summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/menus/AddCharacterMenu.svelte
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-23 00:51:32 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-23 00:51:32 +0100
commit93970f361b831f17d48ff2a345fc78488ac71fba (patch)
treef3844cc343c95dcc19a1444bdb6666e807bc59ef /web/src/lib/ui/menus/AddCharacterMenu.svelte
parentb884441ba0d10bdd3559748507a0991888f66194 (diff)
Phase 7: hardening and shipping (M7)
E2E (Playwright, e2e/): - table fixture: one real compiled server per test (temp saves dir, free port, workers: 1); a Tab helper drives the real UI (menus, rows, initiative, draw, seats) over one WS per fresh browser context - full round: onboarding, secret initiative masked to ?? per connection, draw revealing on every screen, turns, next round, round-2 secrecy - seats: claim/re-claim on owner-leave, reload keeps the session and re-claims, two sessions can't own one character - resilience: a dropped tab resyncs on reconnect (no drift); a SIGKILL'd server restarts with state + seats surviving (incl. the owner's secret initiative and the enabled draw); a throttled tab converges on the same state as the fast tabs; a double-tapped draw runs once, error sent to the sender only - figure edit: set a character level + rename from the status menu Cross-check vs the reference (feature parity): - status menu: level pills (setCharacterLevel) + a name field (changeName), mirroring SetCharacterLevelMenu - ability-card removal: draw-pile-only "send to bottom" (reorderAbilityList -> index 0) + "shuffle undrawn cards" (shuffleDrawnAbilityCard), mirroring RemoveCardMenu - Add Character: already-added classes disabled (Objective/Escort may be added repeatedly), matching _characterAlreadyAdded - every remaining registry command verified reachable from the UI Session persistence (found by the restart test): - the client never learned its session id before the first welcome, so a reconnect minted a new id and orphaned the restored seat; fixed with establishSessionCookie() (a GET /session before the WS upgrade, plus a vite /session proxy) so the x-haven-session cookie survives restarts - the initiative input now prefills from re-synced state (CharacterRow effect, guarded against clobbering a live edit) so a reload/reconnect doesn't blank an entry Performance + deployment: - immutable asset caching (Cache-Control: 1yr, immutable) for the game data / images / in-game translations; no-cache for the SPA index.html so rebuilt apps reach open tabs - server tool/perf_measure.dart: the performance probe (state payload size at full-table scale, WS fan-out bytes per action, traffic per connection) - Dockerfile (server + built web); docs/DEPLOYMENT.md (Docker, persistence, reverse proxy, measured performance, smoke-test list) - README quickstart + production/Docker/testing sections Server: - --saves-dir and --data-dir CLI options (Docker / multi-game hosts), threaded through the stores and data loading Misc: - app.css: height 100% on .row so the turn-done tap zone resolves to a clickable height; fake-socket.ts readyState constants corrected to the real WebSocket values (0 CONNECTING, 1 OPEN) - scripts/ci.sh: the Playwright E2E gate (runs when PLAYWRIGHT is set) - PLAN.md: Phase 7 boxes checked, M7 progress-log entry Verification: svelte-check 0 errors; web 196/196 tests; vite build OK; dart analyze 0 errors / 0 warnings; dart test 604/604; Playwright 9/9; scripts/ci.sh green end-to-end.
Diffstat (limited to 'web/src/lib/ui/menus/AddCharacterMenu.svelte')
-rw-r--r--web/src/lib/ui/menus/AddCharacterMenu.svelte51
1 files changed, 45 insertions, 6 deletions
diff --git a/web/src/lib/ui/menus/AddCharacterMenu.svelte b/web/src/lib/ui/menus/AddCharacterMenu.svelte
index 8383f13..06a24f8 100644
--- a/web/src/lib/ui/menus/AddCharacterMenu.svelte
+++ b/web/src/lib/ui/menus/AddCharacterMenu.svelte
@@ -7,6 +7,7 @@
<script lang="ts">
import type { GameSession } from '$lib/state/session';
import { gameData, type ClassData } from '$lib/data/gameData';
+ import { isObjectiveOrEscort } from '$lib/data/classInfo';
import { classColor, classIcon } from '$lib/game/art';
import { t } from '$lib/i18n';
import Menu from '../Menu.svelte';
@@ -21,7 +22,6 @@
} = $props();
const gameState = session.state;
- const player = session.player;
let campaignData = $state<ClassData[] | null>(null);
let search = $state('');
@@ -57,11 +57,50 @@
(campaignData ?? []).filter((c) => !c.hidden || q.includes(c.name.toLowerCase()))
);
+ // The character items in the current list (their `characterClass` is the
+ // class id — the same key the reference's `_characterAlreadyAdded`
+ // compares on).
+ const existingClasses = $derived.by(() => {
+ const set = new Set<string>();
+ for (const item of $gameState?.currentList ?? []) {
+ if ('characterClass' in item) set.add(item.characterClass);
+ }
+ return set;
+ });
+
+ /**
+ * The reference disables a class once it has been added — except
+ * Objective/Escort, which may be added repeatedly under a numbered
+ * display name.
+ */
+ function alreadyAdded(cls: ClassData): boolean {
+ if (isObjectiveOrEscort(cls.name)) return false;
+ return existingClasses.has(cls.id);
+ }
+
+ /** The reference's display numbering for a repeated objective/escort. */
+ function objectiveDisplay(cls: ClassData): string | null {
+ if (!isObjectiveOrEscort(cls.name)) return null;
+ let count = 1;
+ for (const item of $gameState?.currentList ?? []) {
+ if ('characterClass' in item && item.characterClass === cls.name) count++;
+ }
+ return count > 1 ? `${cls.name} ${count}` : null;
+ }
+
let charsOpen = $state(false);
+ // No player gate: the server lets a spectator add a character, and the
+ // adding session owns it — this is how a fresh session becomes a player
+ // on an empty table (PLAN.md section 3.3).
function pick(cls: ClassData) {
- if (!$player) return;
- session.command('addCharacter', { id: cls.id, edition: cls.edition, level });
+ const display = objectiveDisplay(cls);
+ session.command('addCharacter', {
+ id: cls.id,
+ edition: cls.edition,
+ level,
+ ...(display != null ? { display } : {})
+ });
open = false;
}
</script>
@@ -74,9 +113,9 @@
<div class="statrow">
<span class="statrow__label">{t('web:level')}</span>
- <button class="stepbtn" disabled={!$player || level <= 1} onclick={() => (level -= 1)}>−</button>
+ <button class="stepbtn" disabled={level <= 1} onclick={() => (level -= 1)}>−</button>
<span class="statrow__value">{level}</span>
- <button class="stepbtn" disabled={!$player || level >= 10} onclick={() => (level += 1)}>+</button>
+ <button class="stepbtn" disabled={level >= 10} onclick={() => (level += 1)}>+</button>
</div>
{#if campaignData === null}
@@ -87,7 +126,7 @@
<ul class="menulist">
{#each classes as cls (cls.id)}
<li>
- <button class="menulist__item" disabled={!$player} onclick={() => pick(cls)}>
+ <button class="menulist__item" disabled={alreadyAdded(cls)} onclick={() => pick(cls)}>
<img src={classIcon(cls.name)} alt="" loading="lazy" style="background: {classColor(cls.color)}" />
{cls.name}
</button>