From f10ced9384105fcda37a833c3d969c375cb2a881 Mon Sep 17 00:00:00 2001 From: pleb Date: Sat, 11 Apr 2026 16:27:38 -0700 Subject: [PATCH] Minor reorganization of files --- AGENTS.md | 10 +++++----- README.md | 6 +++--- deno.json | 6 +++--- index.js | 2 +- index.ts => src/client/index.ts | 0 types.ts => src/client/types.ts | 0 serve.ts => src/server/serve.ts | 5 +++-- 7 files changed, 15 insertions(+), 14 deletions(-) rename index.ts => src/client/index.ts (100%) rename types.ts => src/client/types.ts (100%) rename serve.ts => src/server/serve.ts (92%) diff --git a/AGENTS.md b/AGENTS.md index 83c3c65..962e859 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ # AGENTS.md -OBS/browser overlay that reads Beat Saber Plus Song Overlay events over WebSocket (`ws://localhost:2947/socket`). Serve the folder with **`deno task serve`** (see [`serve.ts`](serve.ts)) so the request-queue JSON loads from the same origin; configure the BS+ database path via `CHAT_REQUEST_DATABASE` or `chat-request-database.path`. +OBS/browser overlay that reads Beat Saber Plus Song Overlay events over WebSocket (`ws://localhost:2947/socket`). Serve the folder with **`deno task serve`** (see [`src/server/serve.ts`](src/server/serve.ts)) so the request-queue JSON loads from the same origin; configure the BS+ database path via `CHAT_REQUEST_DATABASE` or `chat-request-database.path`. ## Preference: HTTP only, no `file://` @@ -9,11 +9,11 @@ Do **not** add or maintain code paths for opening the overlay as **`file://`**. ## Files of interest - [`index.html`](index.html) — Page shell: markup for map info, time bar, score, settings dialog; pulls `index.css` and bundled `index.js` module. -- [`index.ts`](index.ts) — Main overlay source in TypeScript; connects to BS+ WebSocket, parses events (`gameState`, `mapInfo`, `pause`, `resume`, `score`), updates DOM, and manages settings/hash state. -- [`types.ts`](types.ts) — Shared TypeScript types for BS+ payloads/events and chat request JSON. -- [`index.js`](index.js) — Bundled browser output generated from `index.ts` via `deno task build`. +- [`src/client/index.ts`](src/client/index.ts) — Main overlay source in TypeScript; connects to BS+ WebSocket, parses events (`gameState`, `mapInfo`, `pause`, `resume`, `score`), updates DOM, and manages settings/hash state. +- [`src/client/types.ts`](src/client/types.ts) — Shared TypeScript types for BS+ payloads/events and chat request JSON. +- [`index.js`](index.js) — Bundled browser output generated from `src/client/index.ts` via `deno task build`. - [`index.css`](index.css) — Layout, theming, visibility toggles driven by body classes and CSS variables from settings. -- [`serve.ts`](serve.ts) — Deno static server + optional mapping of `ChatRequest.json` / `database.json` to the real BS+ `Database.json` path. +- [`src/server/serve.ts`](src/server/serve.ts) — Deno static server + optional mapping of `ChatRequest.json` / `database.json` to the real BS+ `Database.json` path. - [`deno.json`](deno.json) — Deno tasks and TypeScript compiler options (`build`, `serve`, `dev`). - [`images/`](images/) — Cover fallback (`unknown.svg`), characteristic icons under `images/characteristic/` (filenames match BS+ characteristic strings). - [`README.md`](README.md) — User-facing usage (Deno, OBS URL, BS+ module). diff --git a/README.md b/README.md index a6070f2..9a4bd37 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Requires [BeatSaberPlus](https://github.com/hardcpp/BeatSaberPlus) Install [Deno](https://docs.deno.com/runtime/getting_started/installation/) and serve the overlay over HTTP (see below). -The browser overlay source is now TypeScript (`index.ts`) and is bundled to `index.js` with `deno task build` (run automatically by `deno task serve`). +The browser overlay source is now TypeScript (`src/client/index.ts`) and is bundled to `index.js` with `deno task build` (run automatically by `deno task serve`). The server must know where Beat Saber Plus stores **`ChatRequest/Database.json`**. It then serves that file as `ChatRequest.json` and `database.json` (same data) over HTTP—no symlink. @@ -34,6 +34,6 @@ Clone the repo and run `deno task serve` as above. ### Development tasks -- `deno task build` - bundle/check `index.ts` for browser output (`index.js`) +- `deno task build` - bundle/check `src/client/index.ts` for browser output (`index.js`) - `deno task serve` - build, then serve `index.html` and JSON files -- `deno task dev` - watch and rebuild `index.js` when `index.ts` changes +- `deno task dev` - watch and rebuild `index.js` when client TS changes diff --git a/deno.json b/deno.json index 696221e..11cd6ba 100644 --- a/deno.json +++ b/deno.json @@ -4,8 +4,8 @@ "lib": ["dom", "dom.iterable", "deno.ns", "esnext"] }, "tasks": { - "build": "deno bundle --platform=browser --check index.ts -o index.js", - "serve": "deno task build && deno run --allow-net --allow-read --allow-env serve.ts", - "dev": "deno bundle --platform=browser --watch --check index.ts -o index.js" + "build": "deno bundle --platform=browser --check src/client/index.ts -o index.js", + "serve": "deno task build && deno run --allow-net --allow-read --allow-env src/server/serve.ts", + "dev": "deno bundle --platform=browser --watch --check src/client/index.ts -o index.js" } } diff --git a/index.js b/index.js index 10ddb7c..9a7d9d0 100644 --- a/index.js +++ b/index.js @@ -1,4 +1,4 @@ -// index.ts +// src/client/index.ts function must(id) { const element = document.getElementById(id); if (!element) throw new Error(`Missing element: ${id}`); diff --git a/index.ts b/src/client/index.ts similarity index 100% rename from index.ts rename to src/client/index.ts diff --git a/types.ts b/src/client/types.ts similarity index 100% rename from types.ts rename to src/client/types.ts diff --git a/serve.ts b/src/server/serve.ts similarity index 92% rename from serve.ts rename to src/server/serve.ts index 05d5f5d..0da88be 100644 --- a/serve.ts +++ b/src/server/serve.ts @@ -1,7 +1,8 @@ import { join } from "jsr:@std/path"; import { serveDir } from "jsr:@std/http/file-server"; -const root = import.meta.dirname ?? "."; +const scriptDir = import.meta.dirname ?? "."; +const root = join(scriptDir, "..", ".."); const port = Number(Deno.env.get("PORT") ?? "8080"); function trimPathLine(line: string): string { @@ -13,7 +14,7 @@ function trimPathLine(line: string): string { return s.trim(); } -/** Optional one-line file next to this script: absolute path to `ChatRequest/Database.json`. */ +/** Optional one-line file in repo root: absolute path to `ChatRequest/Database.json`. */ function readOptionalPathFile(): string | undefined { try { const pathFile = join(root, "chat-request-database.path");