summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/StatusMenu.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/StatusMenu.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/StatusMenu.svelte')
-rw-r--r--web/src/lib/ui/StatusMenu.svelte106
1 files changed, 106 insertions, 0 deletions
diff --git a/web/src/lib/ui/StatusMenu.svelte b/web/src/lib/ui/StatusMenu.svelte
index eb1090a..b14e2b0 100644
--- a/web/src/lib/ui/StatusMenu.svelte
+++ b/web/src/lib/ui/StatusMenu.svelte
@@ -203,6 +203,49 @@
function presetLinkTarget(): string {
return figure.ownerId ?? figure.figureId;
}
+
+ // --- Character level + name (the reference `SetCharacterLevelMenu`) ------
+
+ /** The character's class model (its per-level health bounds the level range). */
+ const charClass = $derived.by(() => {
+ if (figure.kind !== 'character' || !liveCharacter || !campaignData)
+ return null;
+ return (
+ campaignData.classes.find(
+ (c) =>
+ c.id === liveCharacter.characterClass ||
+ c.name === liveCharacter.characterClass
+ ) ?? null
+ );
+ });
+
+ const maxLevel = $derived(charClass?.health.length ?? 9);
+ const currentLevel = $derived(liveCharacter?.characterState.level ?? 1);
+
+ function setLevel(nr: number) {
+ if (nr === currentLevel) return;
+ cmd('setCharacterLevel', { level: nr, characterId: figure.figureId });
+ }
+
+ // The name field mirrors the server's display, resetting only when the
+ // display itself changes (so a live edit is never clobbered by an
+ // unrelated state update).
+ let nameDraft = $state('');
+ let lastSeenDisplay = $state('');
+ $effect(() => {
+ const display = liveCharacter?.characterState.display ?? '';
+ if (display !== lastSeenDisplay) {
+ lastSeenDisplay = display;
+ nameDraft = display;
+ }
+ });
+
+ function submitName() {
+ const name = nameDraft.trim();
+ if (name && name !== liveCharacter?.characterState.display) {
+ cmd('changeName', { name, characterId: figure.figureId });
+ }
+ }
</script>
<Menu open={open} title={figure.title}>
@@ -230,6 +273,35 @@
</div>
{/if}
+ <!-- Level + name (the reference `SetCharacterLevelMenu`); characters only. -->
+ {#if figure.kind === 'character' && !figure.isObjective && liveCharacter}
+ <div class="statrow statrow--wrap">
+ <span class="statrow__label">{t('web:level')}</span>
+ <div class="levelbtns">
+ {#each Array(maxLevel) as _, i}
+ <button
+ class="pill"
+ class:pill--on={i + 1 === currentLevel}
+ disabled={!canAct || i + 1 === currentLevel}
+ onclick={() => setLevel(i + 1)}
+ >{i + 1}</button>
+ {/each}
+ </div>
+ </div>
+ <div class="statrow">
+ <span class="statrow__label">{t('changeName')}</span>
+ <input
+ class="search"
+ style="margin: 0; width: auto; flex: 1"
+ value={nameDraft}
+ oninput={(e) => (nameDraft = e.currentTarget.value)}
+ onkeydown={(e) => {
+ if (e.key === 'Enter') submitName();
+ }}
+ />
+ </div>
+ {/if}
+
{#if counters}
<div class="statrow">
<span class="statrow__label">{t('cmdAddBless')}</span>
@@ -340,3 +412,37 @@
bind:open={noteOpen}
/>
{/if}
+
+<style>
+ .statrow--wrap {
+ flex-wrap: wrap;
+ }
+ .levelbtns {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 4px;
+ flex: 1;
+ justify-content: flex-end;
+ }
+ .pill {
+ min-width: 26px;
+ padding: 3px 6px;
+ font-size: 13px;
+ border: none;
+ border-radius: 4px;
+ background: rgba(255, 255, 255, 0.12);
+ color: inherit;
+ cursor: pointer;
+ }
+ .pill:hover {
+ background: rgba(255, 255, 255, 0.25);
+ }
+ .pill--on {
+ background: #2196f3;
+ color: #fff;
+ }
+ .pill:disabled {
+ opacity: 0.4;
+ cursor: default;
+ }
+</style>