summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/menus/NoteRowMenu.svelte
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2026-11-17 23:12:38 +0100
committerJoel Klinghed <the_jk@spawned.biz>2026-11-17 23:12:38 +0100
commitd64cf3514e5ff1ddb1c7f3ddac9a769db3e7dde0 (patch)
tree781ec9f63220f3c15b309658e9b32ad7d9c70b3a /web/src/lib/ui/menus/NoteRowMenu.svelte
parent94e2850fb73005f3fb30af8489905e5cdfb6fac5 (diff)
Phase 5: campaign meta, notes, special rules (M5)
Web: - Note rows: create/edit menu (text, 12-swatch palette, player/monster link with per-standee selection, delete) with the reference's create-vs-edit commit semantics; row rendering with target-derived gradient colour, link indent + connector, standee N:/All: prefixes, tap-to-edit; whole-list drag-to-reorder (reorderList); quick per-figure note (setFigureNote) from the status menu - Special monsters: Ice Wraith "Switch Form" (deck == "Ice Wraith" gate), summon mark toggle (round-green/summon standee artwork, standee-nr badges, per-owner grayscale), character summon boxes + AddSummonMenu (class summons gated by level and standee cap, item summons from summons.json) - Ally deck show/hide in the main menu (shouldShowAlliesDeck gate); settings "clear unlocked" + Special Unlocks menu - AddSectionMenu parity: search filter, findNrFromScenarioName numeric ordering, added sections greyed + no-op, #Random Dungeon label - gameData.ts: SummonModel, ClassData.summons, summons() fetch Server: - unlock_special_command_test (last command without a test; ally-deck hide and remove-sanctuary were already covered) PLAN.md: Phase 5 boxes checked, M5 progress-log entry
Diffstat (limited to 'web/src/lib/ui/menus/NoteRowMenu.svelte')
-rw-r--r--web/src/lib/ui/menus/NoteRowMenu.svelte270
1 files changed, 270 insertions, 0 deletions
diff --git a/web/src/lib/ui/menus/NoteRowMenu.svelte b/web/src/lib/ui/menus/NoteRowMenu.svelte
new file mode 100644
index 0000000..78f25f9
--- /dev/null
+++ b/web/src/lib/ui/menus/NoteRowMenu.svelte
@@ -0,0 +1,270 @@
+<!--
+ The note-row editor (the reference `NoteRowMenu`): used both to create a
+ new note (note == null) and to edit an existing one. In create mode all
+ edits accumulate locally and are committed by the Add button; in edit
+ mode colour/link changes commit immediately and the text commits on close
+ (only when it actually changed, so an unedited open/close doesn't pollute
+ the undo history).
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import {
+ isCharacter,
+ isMonster,
+ type CharacterItem,
+ type MonsterItem,
+ type NoteRowItem
+ } from '$lib/protocol/types';
+ import { t } from '$lib/i18n';
+ import Menu from '../Menu.svelte';
+
+ /** The reference `_kPalette` (12 swatches, ARGB). */
+ const PALETTE = [
+ 0xff4e5d6c,
+ 0xff6d4c41,
+ 0xff37474f,
+ 0xff5d4037,
+ 0xff455a64,
+ 0xff6a1b9a,
+ 0xffad1457,
+ 0xffc62828,
+ 0xffe65100,
+ 0xff2e7d32,
+ 0xff1565c0,
+ 0xff00838f
+ ];
+
+ let {
+ session,
+ note = null,
+ presetLinkId = '',
+ presetStandeeNr = 0,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ /** The existing note to edit; null to create a new one. */
+ note?: NoteRowItem | null;
+ /** Create mode only: pre-select a link target (status-menu entry). */
+ presetLinkId?: string;
+ presetStandeeNr?: number;
+ open?: boolean;
+ } = $props();
+
+ const player = session.player;
+ const gameState = session.state;
+
+ const isEdit = $derived(note != null);
+ const canAct = $derived(!!$player && $gameState != null);
+
+ let text = $state(note?.text ?? '');
+ let color = $state(note?.color ?? 0xff4e5d6c);
+ let linkedId = $state(note?.linkedId ?? presetLinkId);
+ let standeeNr = $state(note?.standeeNr ?? presetStandeeNr);
+ let lastCommitted = $state(text);
+
+ function colorCss(c: number): string {
+ return `#${c.toString(16).padStart(8, '0').slice(2)}`;
+ }
+
+ function cmd(name: string, args: Record<string, unknown>) {
+ if ($player) session.command(name, args);
+ }
+
+ /** Every link target (characters and monsters) in list order. */
+ const figures = $derived.by(() => {
+ const out: { id: string; kind: 'player' | 'monster'; display: string }[] = [];
+ for (const item of $gameState?.currentList ?? []) {
+ if (isCharacter(item)) {
+ const c = item as CharacterItem;
+ out.push({ id: c.id, kind: 'player', display: c.characterState.display || c.id });
+ } else if (isMonster(item)) {
+ out.push({ id: item.id, kind: 'monster', display: item.id });
+ }
+ }
+ return out;
+ });
+
+ /** The linked monster (for the standee selector), if any. */
+ const linkedMonster = $derived.by((): MonsterItem | null => {
+ const gs = $gameState;
+ if (linkedId === '' || gs == null) return null;
+ return (
+ gs.currentList.find((i): i is MonsterItem => isMonster(i) && i.id === linkedId) ??
+ null
+ );
+ });
+
+ function pickColor(c: number) {
+ color = c;
+ if (note) cmd('setNoteRowColor', { color: c, noteId: note.id });
+ }
+
+ function setLink(id: string, nr: number) {
+ linkedId = id;
+ standeeNr = id === '' ? 0 : nr;
+ if (note)
+ cmd('setNoteRowLink', {
+ noteId: note.id,
+ linkedId,
+ standeeNr
+ });
+ }
+
+ function commitText() {
+ if (!note) return;
+ const trimmed = text.trim();
+ if (trimmed !== lastCommitted) {
+ lastCommitted = trimmed;
+ cmd('setNoteRowText', { text: trimmed, noteId: note.id });
+ }
+ }
+
+ function add() {
+ cmd('addNoteRow', {
+ noteRow: {
+ id: 'note_' + crypto.randomUUID(),
+ text: text.trim(),
+ color,
+ linkedId,
+ standeeNr
+ }
+ });
+ open = false;
+ }
+
+ function remove() {
+ if (note) cmd('removeNoteRow', { noteId: note.id });
+ open = false;
+ }
+
+ function close() {
+ commitText();
+ open = false;
+ }
+</script>
+
+<Menu {open} title={t('noteRowTitle')}>
+ <textarea
+ class="search search--area"
+ rows={3}
+ maxlength={300}
+ placeholder={t('noteRowHint')}
+ bind:value={text}
+ readonly={!canAct}
+ onblur={commitText}
+ ></textarea>
+
+ {#if canAct}
+ <div class="fieldlabel">{t('noteRowColourLabel')}</div>
+ <div class="palette" role="radiogroup" aria-label={t('noteRowColourLabel')}>
+ {#each PALETTE as c (c)}
+ <button
+ class="swatch"
+ class:swatch--selected={c === color}
+ style:background={colorCss(c)}
+ aria-label={colorCss(c)}
+ onclick={() => pickColor(c)}
+ ></button>
+ {/each}
+ </div>
+
+ <div class="fieldlabel">{t('noteRowConnectLabel')}</div>
+ <select
+ class="search"
+ style="margin: 0"
+ value={linkedId}
+ onchange={(e) => setLink(e.currentTarget.value, 0)}
+ >
+ <option value="">{t('noteRowConnectNone')}</option>
+ {#each figures as f (f.id)}
+ <option value={f.id}>
+ {f.kind === 'player' ? t('noteRowConnectPlayer') : t('noteRowConnectMonster')}:
+ {f.display}
+ </option>
+ {/each}
+ </select>
+
+ {#if linkedMonster}
+ <select
+ class="search"
+ style="margin: 0"
+ value={linkedMonster.monsterInstances.some((s) => s.standeeNr === standeeNr)
+ ? standeeNr
+ : 0}
+ onchange={(e) => setLink(linkedId, Number(e.currentTarget.value))}
+ >
+ <option value={0}>{t('noteRowWholeGroup')}</option>
+ {#each linkedMonster.monsterInstances as s (s.standeeNr)}
+ <option value={s.standeeNr}>{t('noteRowStandeeNr', { nr: s.standeeNr })}</option>
+ {/each}
+ </select>
+ {/if}
+
+ <div class="actions">
+ {#if isEdit && note}
+ <button class="pill pill--danger" onclick={remove}>{t('noteRowDelete')}</button>
+ {:else}
+ <span></span>
+ {/if}
+ {#if isEdit}
+ <button class="pill" onclick={close}>{t('close')}</button>
+ {:else}
+ <button class="pill pill--primary" onclick={add}>{t('noteRowAddFromMenu')}</button>
+ {/if}
+ </div>
+ {/if}
+</Menu>
+
+<style>
+ textarea.search--area {
+ resize: vertical;
+ min-height: 64px;
+ margin-bottom: 10px;
+ }
+ .fieldlabel {
+ font-size: 13px;
+ margin: 10px 0 4px;
+ opacity: 0.85;
+ }
+ .palette {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 6px;
+ }
+ .swatch {
+ width: 26px;
+ height: 26px;
+ border-radius: 50%;
+ border: 1px solid rgba(0, 0, 0, 0.4);
+ cursor: pointer;
+ padding: 0;
+ }
+ .swatch--selected {
+ border: 3px solid #fff;
+ }
+ .actions {
+ display: flex;
+ justify-content: space-between;
+ gap: 8px;
+ margin-top: 14px;
+ }
+ .pill {
+ padding: 6px 14px;
+ 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--primary {
+ background: rgba(255, 255, 255, 0.3);
+ font-weight: 600;
+ }
+ .pill--danger {
+ color: #ff5252;
+ }
+</style>