From 4f50f2008f4d7c2a635f7f26861fcfc7f7504423 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Sun, 15 Nov 2026 13:45:21 +0100 Subject: Phase 3: web UI core loop (M3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Browser game UI on top of the Phase 2 protocol: server-driven, input-only clients with per-connection secret visibility. Web (Svelte 5): - Layout: TopBar (element buttons with use/imbue long-press, title, menu), MainList (character/monster/note rows), BottomBar (draw/next-round + level widget with T/H/X/C values). - CharacterRow with the secret initiative input: own value editable, server-masked values render as ??, revealed on draw. - Per-figure StatusMenu: health/max/xp/bless/curse/empower/enfeeble steppers, condition grid, turn-done — all server commands, player-gated. - Menu dialogs: select scenario, add section, add/remove character, set level/difficulty/solo/auto-level, add/remove monster, note row, action log with rollback, settings (style theme + language). - Player vs spectator UI gated on the live seat table; reconnecting banner, error toasts, connection status plumbing. - i18n: English ported, locale store with localStorage persistence. - Design tokens + the three style themes (frosthaven/gloomhaven/original). - Unit tests: level values, game logic (elements/conditions/art/stats), i18n, the reactive player store, the data client (sections keyed by scenario number), plus the existing connection/protocol/state tests. Server: - Serve the engine's data JSON at /data/ and artwork at /images/ so the client menus and rows read the same assets the engine loads. --- web/test/fake-socket.ts | 70 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 web/test/fake-socket.ts (limited to 'web/test/fake-socket.ts') diff --git a/web/test/fake-socket.ts b/web/test/fake-socket.ts new file mode 100644 index 0000000..290f9a8 --- /dev/null +++ b/web/test/fake-socket.ts @@ -0,0 +1,70 @@ +/** + * A scriptable fake WebSocket for the connection tests. It records outbound + * frames and lets tests drive `open` / `message` / `close` from either side. + */ +import type { Transport } from '$lib/protocol/connection'; + +export class FakeSocket implements Transport { + onopen: ((ev?: unknown) => void) | null = null; + onclose: ((ev?: unknown) => void) | null = null; + onerror: ((ev?: unknown) => void) | null = null; + onmessage: ((ev: { data: unknown }) => void) | null = null; + readyState = 1; // CONNECTING + + readonly sent: string[] = []; + closed = false; + + send(data: string): void { + if (this.readyState !== 0) throw new Error('not open'); + this.sent.push(data); + } + + close(): void { + if (this.closed) return; + this.closed = true; + this.readyState = 3; + this.onclose?.(); + } + + // test drivers -------------------------------------------------------- + + open(): void { + this.readyState = 0; + this.onopen?.(); + } + + /** Deliver a raw server frame. */ + serverSend(obj: object | string): void { + const data = typeof obj === 'string' ? obj : JSON.stringify(obj); + this.onmessage?.({ data }); + } + + /** The socket drops (server-side close). */ + serverClose(): void { + if (this.closed) return; + this.closed = true; + this.readyState = 3; + this.onclose?.(); + } + + lastJson(): Record | null { + if (this.sent.length === 0) return null; + return JSON.parse(this.sent[this.sent.length - 1]); + } +} + +/** Creates and tracks a sequence of fake sockets handed to a connection. */ +export class SocketSequence { + readonly sockets: FakeSocket[] = []; + + // Arrow field so `this` survives being passed as a bare transport factory. + factory = (_url: string): Transport => { + const socket = new FakeSocket(); + this.sockets.push(socket); + return socket; + }; + + get current(): FakeSocket { + return this.sockets[this.sockets.length - 1]; + } +} -- cgit v1.3.1