summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/menus/AddNoteRowMenu.svelte
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-15 13:45:21 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-15 13:45:21 +0100
commit4f50f2008f4d7c2a635f7f26861fcfc7f7504423 (patch)
tree94e6286e7e22e0467a61b99c18b9ab582fbbe656 /web/src/lib/ui/menus/AddNoteRowMenu.svelte
parent3ebbdf6ffa16f751c82e3bd2e74294f4fe843155 (diff)
Phase 3: web UI core loop (M3)
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.
Diffstat (limited to 'web/src/lib/ui/menus/AddNoteRowMenu.svelte')
-rw-r--r--web/src/lib/ui/menus/AddNoteRowMenu.svelte113
1 files changed, 113 insertions, 0 deletions
diff --git a/web/src/lib/ui/menus/AddNoteRowMenu.svelte b/web/src/lib/ui/menus/AddNoteRowMenu.svelte
new file mode 100644
index 0000000..5bb14a0
--- /dev/null
+++ b/web/src/lib/ui/menus/AddNoteRowMenu.svelte
@@ -0,0 +1,113 @@
+<!--
+ Add Note Row (the reference `NoteRowAddMenu`, Phase 3 form): a colour
+ picker, free text, and an optional link to a figure. Sending
+ `addNoteRow` appends the row (beneath its linked figure, if any).
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import { isCharacter, isMonster } from '$lib/protocol/types';
+ import { t } from '$lib/i18n';
+ import Menu from '../Menu.svelte';
+
+ let {
+ session,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ open?: boolean;
+ } = $props();
+
+ const gameState = session.state;
+ const player = session.player;
+
+ const COLORS = [
+ 0xffb58900,
+ 0xff1565c0,
+ 0xff2e7d32,
+ 0xffc2185b,
+ 0xffffb300,
+ 0xff5e35b1
+ ];
+
+ let color = $state(COLORS[0]);
+ let text = $state('');
+ let linkedId = $state('');
+
+ $effect(() => {
+ if (!open) return;
+ color = COLORS[0];
+ text = '';
+ linkedId = '';
+ });
+
+ const figures = $derived.by(() =>
+ ($gameState?.currentList ?? [])
+ .filter((i) => isCharacter(i) || isMonster(i))
+ .map((i) => ({
+ id: i.id,
+ name: isCharacter(i) ? i.characterState.display : i.id
+ }))
+ );
+
+ function colorCss(c: number): string {
+ return `#${c.toString(16).padStart(8, '0').slice(2)}`;
+ }
+
+ function add() {
+ if (!$player) return;
+ const id =
+ typeof crypto !== 'undefined' && 'randomUUID' in crypto
+ ? crypto.randomUUID()
+ : `note-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
+ session.command('addNoteRow', {
+ noteRow: {
+ id,
+ text: text.trim(),
+ color,
+ linkedId,
+ standeeNr: 0
+ }
+ });
+ open = false;
+ }
+</script>
+
+<Menu open={open} title={t('menuAddNoteRow')}>
+ <div style="display: flex; gap: 6px; padding: 8px 4px">
+ {#each COLORS as c (c)}
+ <button
+ aria-label="note colour"
+ style="width: 32px; height: 32px; border-radius: 6px; background: {colorCss(c)}; outline: {c === color ? '3px solid #fff' : 'none'}"
+ onclick={() => (color = c)}
+ ></button>
+ {/each}
+ </div>
+
+ <input class="search" placeholder={t('noteRowHint')} bind:value={text} />
+
+ <div class="statrow" style="align-items: center">
+ <span class="statrow__label" style="font-size: 13px">{t('noteRowWholeGroup')}</span>
+ <select
+ class="search"
+ style="margin: 0; width: auto"
+ value={linkedId}
+ onchange={(e) => (linkedId = e.currentTarget.value)}
+ >
+ <option value="">{t('noteRowAll')}</option>
+ {#each figures as f (f.id)}
+ <option value={f.id}>{f.name}</option>
+ {/each}
+ </select>
+ </div>
+
+ <div style="display: flex; justify-content: flex-end; padding: 8px 4px">
+ <button
+ class="stepbtn"
+ style="border-radius: 6px"
+ disabled={!$player || text.trim() === ''}
+ onclick={add}
+ >
+ {t('noteRowAddFromMenu')}
+ </button>
+ </div>
+</Menu>