From f6955e34489c79f6d5b764cb6a39b1387366b433 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Sun, 8 Nov 2026 21:56:29 +0100 Subject: Phase 0: project scaffolding - server/: Dart game-server package (shelf + WebSocket) with the hello/welcome handshake, ping/pong, error responses, healthz, static SPA serving with SPA fallback, and smoke tests (5/5) - web/: Svelte 5 + TypeScript SPA with the protocol client, connection-status page, vitest and svelte-check; Vite dev server proxies /ws to the Dart server - game data assets copied from the read-only reference app into server/assets/ (data, images, i18n, fonts, testData) - PLAN.md implementation plan and progress tracker; README rewritten for the web app; AGPLv3 LICENSE inherited from the reference app; .gitignore; scripts/ci.sh (full pipeline) - CLAUDE.md project guidance Verified: scripts/ci.sh passes end-to-end; live smoke confirms the server serves the built SPA at / and answers a WebSocket hello with a welcome message. --- web/src/App.svelte | 25 +++++++++++++++++ web/src/app.css | 16 +++++++++++ web/src/lib/protocol/connection.ts | 57 ++++++++++++++++++++++++++++++++++++++ web/src/main.ts | 9 ++++++ web/src/vite-env.d.ts | 2 ++ 5 files changed, 109 insertions(+) create mode 100644 web/src/App.svelte create mode 100644 web/src/app.css create mode 100644 web/src/lib/protocol/connection.ts create mode 100644 web/src/main.ts create mode 100644 web/src/vite-env.d.ts (limited to 'web/src') diff --git a/web/src/App.svelte b/web/src/App.svelte new file mode 100644 index 0000000..a1a370d --- /dev/null +++ b/web/src/App.svelte @@ -0,0 +1,25 @@ + + +
+

X-Haven

+

Connection: {status}

+ {#if welcome} +

Session: {welcome.session}

+

Role: {welcome.role}

+

State index: {welcome.index}

+ {:else} +

Waiting for server…

+ {/if} +
diff --git a/web/src/app.css b/web/src/app.css new file mode 100644 index 0000000..34530c9 --- /dev/null +++ b/web/src/app.css @@ -0,0 +1,16 @@ +:root { + color-scheme: dark; + --bg: #15181d; + --fg: #e6e8ee; +} + +* { + box-sizing: border-box; +} + +body { + margin: 0; + background: var(--bg); + color: var(--fg); + font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif; +} diff --git a/web/src/lib/protocol/connection.ts b/web/src/lib/protocol/connection.ts new file mode 100644 index 0000000..0826a3c --- /dev/null +++ b/web/src/lib/protocol/connection.ts @@ -0,0 +1,57 @@ +/** + * Client side of the X-Haven wire protocol (PLAN.md section 3.5). + * + * Phase 0 scope: connect to `/ws`, send the `hello` handshake, surface the + * `welcome` message and connection status. Reconnect/resync, commands, claims + * and state updates arrive in later phases. + */ + +export interface Welcome { + t: 'welcome'; + v: number; + session: string; + role: 'player' | 'spectator'; + index: number; + description: string | null; + event: unknown; + state: Record; + seats: Record; +} + +export type ConnectionStatus = 'connecting' | 'open' | 'closed'; + +/** The handshake message sent right after the WebSocket opens. */ +export function buildHello(): Record { + return { t: 'hello', v: 1 }; +} + +export class GameConnection { + private ws: WebSocket | null = null; + + onWelcome: ((welcome: Welcome) => void) | null = null; + onStatus: ((status: ConnectionStatus) => void) | null = null; + + connect(): void { + const proto = window.location.protocol === 'https:' ? 'wss' : 'ws'; + const ws = new WebSocket(`${proto}://${window.location.host}/ws`); + this.ws = ws; + + ws.onopen = () => { + this.onStatus?.('open'); + ws.send(JSON.stringify(buildHello())); + }; + ws.onclose = () => this.onStatus?.('closed'); + ws.onerror = () => this.onStatus?.('closed'); + ws.onmessage = (event) => { + const message = JSON.parse(String(event.data)) as { t: string }; + if (message.t === 'welcome') { + this.onWelcome?.(message as unknown as Welcome); + } + }; + } + + close(): void { + this.ws?.close(); + this.ws = null; + } +} diff --git a/web/src/main.ts b/web/src/main.ts new file mode 100644 index 0000000..061c445 --- /dev/null +++ b/web/src/main.ts @@ -0,0 +1,9 @@ +import { mount } from 'svelte'; +import './app.css'; +import App from './App.svelte'; + +const app = mount(App, { + target: document.getElementById('app')!, +}); + +export default app; diff --git a/web/src/vite-env.d.ts b/web/src/vite-env.d.ts new file mode 100644 index 0000000..4078e74 --- /dev/null +++ b/web/src/vite-env.d.ts @@ -0,0 +1,2 @@ +/// +/// -- cgit v1.3.1