# X-Haven (web) There is a companion/assistant app for playing Gloomhaven (and related games such as Frosthaven) called X-haven assistant. The original code is checked out in `FrosthavenAssistant/` — **DO NOT DO ANY MODIFICATIONS** to that repo. The original app is hard to use, especially the network code: it disconnects and loses sync quite often. Instead of having an app on each device that connects to a server, this repository re-architects the whole app as a **server-driven web app**: every player connects to a web server running the app, keeping all the data on the web server, removing the need for keeping data in sync. It is still important that any changes done on the clients are sent to the server — but only as input. For example, the priority (initiative) input should only be visible on each client's browser until all players have entered their priority and the draw action is tapped. The server runs the app and keeps the state. Each player has the web page open in a browser tab. There will also be other clients with the page open just to watch the current state (spectators). The design intent and the full implementation plan (with progress tracking) live in [`PLAN.md`](PLAN.md). ## Repository layout - `server/` — the Dart game server. Owns all game state, serves the built web app, and hosts the game WebSocket at `/ws`. Game data is copied from the reference app into `server/assets/` (`data/`, `images/`, `i18n/`, `fonts/`, `testData/`). `tool/perf_measure.dart` is the Phase 7 performance probe. - `web/` — the Svelte + TypeScript single-page app. Carries no game state; it renders the server's state and submits player input. - `e2e/` — Playwright end-to-end tests (full round, seats, resilience). - `docs/DEPLOYMENT.md` — production notes: Docker, persistence, reverse proxy, measured performance, smoke-test list. - `Dockerfile` — server + built web in one image. - `scripts/ci.sh` — analyze, test, and build both halves (plus the E2E suite). - `FrosthavenAssistant/` — read-only reference implementation (gitignored). ## Requirements - Dart SDK ≥ 3.11 - Node.js ≥ 20 (tested with Node 26) ## Development Terminal 1 — the Dart server (WebSocket + static serving, default port 4567): ```bash cd server dart pub get dart run bin/main.dart # from server/; serves ../web/dist when built ``` Terminal 2 — the web dev server (Vite, port 5173, proxies `/ws` to the server): ```bash cd web npm install npm run dev ``` Open — you should see the connection status and, once the handshake completes, your session/role/state index. ## Quickstart (playing a game) 1. Start the server (see *Production run* below, or the Docker one-liner in [docs/DEPLOYMENT.md](docs/DEPLOYMENT.md)). 2. Open the game URL in a browser tab — each player gets their **own tab** (and ideally their own device); other tabs can just watch as spectators. 3. In your tab open the main menu (top-left) → **Add Character** and pick your class. Your tab becomes a *player* the moment you own a character; a character someone leaves behind shows a **Claim** chip any player can tap. 4. **Set Scenario** (same menu) picks the scenario. 5. Each player taps their character's initiative slot and enters a number — it is **secret**: only your tab sees your entry until the round is drawn. 6. Once every player has entered, any player taps **Draw** (bottom bar). All tabs reveal the initiative and switch to turns; end a figure's turn by tapping its right-hand zone, then **Next Round** when the round is done. Full per-step verification (what to expect in each tab) is in the [smoke-test list](docs/DEPLOYMENT.md#smoke-test-list); the same flow is automated by the Playwright suite in `e2e/`. ## Production run ```bash cd web && npm run build # outputs web/dist cd server && dart run bin/main.dart # serves web/dist + /ws on :4567 ``` Open . The port and static dir can be overridden: `dart run bin/main.dart --port 8080 --static-dir ../web/dist` (the `PORT` environment variable is also honored). Game state persists in `saves/` next to the server; all options are in `server/bin/main.dart`. ### Docker ```bash docker build -t xhaven . docker run --rm -p 4567:4567 -v xhaven-saves:/app/saves xhaven ``` One image (web build + compiled server + game assets); state lives in the `/app/saves` volume. See [docs/DEPLOYMENT.md](docs/DEPLOYMENT.md) for the full list of options, persistence semantics, reverse-proxy/TLS notes, and the measured performance figures. ## Testing ```bash scripts/ci.sh ``` runs `dart analyze` + `dart test` for the server and `svelte-check` + `vitest` + `vite build` for the web app, then the Playwright E2E suite (two players + a spectator play a full round through the real UI; seat claiming; resilience — offline tabs, throttled tabs, server restart mid-game). The E2E steps are skipped when the `PLAYWRIGHT` environment variable is unset (it is set on CI). Individual suites: ```bash cd server && dart test # server (604 tests) cd web && npm run test # client (195 tests) cd e2e && npx playwright test # end-to-end (needs `npm install` + # `npx playwright install chromium`) ``` ## License This project ports code from and ships the game data and art assets of FrosthavenAssistant, which is licensed under the GNU AGPL v3. This project therefore inherits that license — see `LICENSE`.