summaryrefslogtreecommitdiff
path: root/web/src/lib/ui
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
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')
-rw-r--r--web/src/lib/ui/CharacterRow.svelte112
-rw-r--r--web/src/lib/ui/MainList.svelte107
-rw-r--r--web/src/lib/ui/MainMenu.svelte29
-rw-r--r--web/src/lib/ui/MonsterRow.svelte27
-rw-r--r--web/src/lib/ui/NoteRow.svelte187
-rw-r--r--web/src/lib/ui/StatusMenu.svelte115
-rw-r--r--web/src/lib/ui/menus/AddNoteRowMenu.svelte113
-rw-r--r--web/src/lib/ui/menus/AddSectionMenu.svelte103
-rw-r--r--web/src/lib/ui/menus/AddSummonMenu.svelte261
-rw-r--r--web/src/lib/ui/menus/FigureNoteMenu.svelte83
-rw-r--r--web/src/lib/ui/menus/NoteRowMenu.svelte270
-rw-r--r--web/src/lib/ui/menus/SettingsMenu.svelte63
-rw-r--r--web/src/lib/ui/menus/SpecialUnlocksMenu.svelte83
13 files changed, 1357 insertions, 196 deletions
diff --git a/web/src/lib/ui/CharacterRow.svelte b/web/src/lib/ui/CharacterRow.svelte
index f4fdd76..043c225 100644
--- a/web/src/lib/ui/CharacterRow.svelte
+++ b/web/src/lib/ui/CharacterRow.svelte
@@ -15,20 +15,24 @@
-->
<script lang="ts">
import type { GameSession } from '$lib/state/session';
- import type { CharacterItem } from '$lib/protocol/types';
+ import type { CharacterItem, MonsterInstance } from '$lib/protocol/types';
import { classInfo, isObjectiveOrEscort, type ClassData } from '$lib/data/classInfo';
- import { classColor, classIcon } from '$lib/game/art';
+ import { classColor, classIcon, summonImage } from '$lib/game/art';
import { conditionChipClass, conditionLabel } from '$lib/game/conditions';
+ import { standeeFigureId } from '$lib/game/stats';
import type { FigureRef } from './StatusMenu.svelte';
let {
session,
item,
- onOpenMenu
+ onOpenMenu,
+ onAddSummon
}: {
session: GameSession;
item: CharacterItem;
onOpenMenu: (figure: FigureRef) => void;
+ /** Open the add-summon menu for this character. */
+ onAddSummon: () => void;
} = $props();
const seats = session.seats;
@@ -106,8 +110,42 @@
rowId: item.id,
isObjective
});
+
+ /** A figure ref for one of the character's summon standees. */
+ function summonFigureFor(s: MonsterInstance): FigureRef {
+ return {
+ title: s.name || cs.display,
+ figureId: standeeFigureId(s),
+ ownerId: item.id,
+ kind: 'summon',
+ rowId: item.id,
+ isObjective: false
+ };
+ }
</script>
+{#if !isObjective}
+ <div class="summons">
+ {#each cs.summonList as s (standeeFigureId(s))}
+ <button
+ class="summon__box"
+ class:summon__box--dead={s.health <= 0}
+ onclick={() => onOpenMenu(summonFigureFor(s))}
+ aria-label={s.name || 'summon'}
+ >
+ <img src={summonImage(s.gfx)} alt="" loading="lazy" />
+ {#if s.standeeNr > 0}
+ <span class="summon__box-nr">{s.standeeNr}</span>
+ {/if}
+ <span class="summon__box-hp">{s.health}</span>
+ </button>
+ {/each}
+ <button class="summon__add" onclick={onAddSummon} aria-label="Add Summon">
+ ⚔+
+ </button>
+ </div>
+{/if}
+
<div
class="row row--character"
class:row--current={currentTurn}
@@ -172,9 +210,6 @@
<span class="row__xp">XP {cs.xp}</span>
{/if}
<span class="row__level">{cs.level}</span>
- {#if cs.summonList.length > 0}
- <span class="row__summon">⚔ {cs.summonList.length}</span>
- {/if}
<!-- Right-hand tap zone: initiative focus / turn done (reference). -->
<div
@@ -193,3 +228,68 @@
{#if unclaimed}
<button class="chip chip--claim" onclick={() => session.claim(item.id)}>Claim</button>
{/if}
+
+<style>
+ /* The summon standees sit above the row, like the reference. */
+ .summons {
+ display: flex;
+ align-items: stretch;
+ gap: 4px;
+ width: calc(100% - 6px);
+ margin: 2px 3px 0;
+ }
+ .summon__box {
+ position: relative;
+ width: 34px;
+ height: 44px;
+ padding: 0;
+ border: 1px solid #2196f3;
+ border-radius: 4px;
+ background: rgba(0, 0, 0, 0.45);
+ overflow: hidden;
+ cursor: pointer;
+ }
+ .summon__box:focus-visible {
+ outline: 2px solid #7ec8ff;
+ }
+ .summon__box img {
+ width: 100%;
+ height: 100%;
+ object-fit: cover;
+ }
+ .summon__box--dead {
+ filter: grayscale(1);
+ opacity: 0.6;
+ }
+ .summon__box-hp {
+ position: absolute;
+ right: 2px;
+ bottom: 1px;
+ font-size: 11px;
+ font-weight: 700;
+ color: #fff;
+ text-shadow: 0 0 2px #000;
+ }
+ .summon__box-nr {
+ position: absolute;
+ left: 2px;
+ top: 1px;
+ font-size: 10px;
+ font-weight: 700;
+ color: #fff;
+ text-shadow: 0 0 2px #000;
+ }
+ .summon__add {
+ width: 34px;
+ height: 44px;
+ border: 1px dashed rgba(255, 255, 255, 0.4);
+ border-radius: 4px;
+ background: rgba(0, 0, 0, 0.3);
+ color: inherit;
+ font-size: 12px;
+ cursor: pointer;
+ }
+ .summon__add:hover {
+ background: rgba(255, 255, 255, 0.12);
+ }
+</style>
diff --git a/web/src/lib/ui/MainList.svelte b/web/src/lib/ui/MainList.svelte
index f594778..87f83b9 100644
--- a/web/src/lib/ui/MainList.svelte
+++ b/web/src/lib/ui/MainList.svelte
@@ -1,13 +1,13 @@
<!--
The main list (the reference `MainList`/`GameList`): one row per entry of
the server's `currentList`. The reference lays wide screens out as two
- reorderable columns; the web Phase 3 uses a single centred, scrollable
- column (reordering arrives later, if at all).
+ long-press reorderable columns; the web uses a single centred column with
+ drag-to-reorder (the reference `ReorderableWrap` → `reorderList`).
-->
<script lang="ts">
import type { GameSession } from '$lib/state/session';
import { isCharacter, isMonster, isNoteRow } from '$lib/protocol/types';
- import type { MonsterItem } from '$lib/protocol/types';
+ import type { CharacterItem, MonsterItem, NoteRowItem } from '$lib/protocol/types';
import type { CampaignData } from '$lib/data/gameData';
import type { FigureRef } from './StatusMenu.svelte';
import CharacterRow from './CharacterRow.svelte';
@@ -17,37 +17,94 @@
let {
session,
onOpenMenu,
+ onEditNote,
+ onAddSummon,
campaignData,
onOpenAbility,
onZoomAbility
}: {
session: GameSession;
onOpenMenu: (figure: FigureRef) => void;
+ onEditNote: (item: NoteRowItem) => void;
+ onAddSummon: (item: CharacterItem) => void;
campaignData: CampaignData | null;
onOpenAbility: (item: MonsterItem) => void;
onZoomAbility: (item: MonsterItem) => void;
} = $props();
const gameState = session.state;
+ const player = session.player;
+
+ // --- reordering (HTML5 drag & drop, the reference long-press drag) -------
+
+ let dragIndex = $state<number | null>(null);
+ let dropIndex = $state<number | null>(null);
+
+ function onDragStart(e: DragEvent, i: number) {
+ if (!$player) return;
+ dragIndex = i;
+ if (e.dataTransfer) {
+ e.dataTransfer.effectAllowed = 'move';
+ e.dataTransfer.setData('text/plain', String(i));
+ }
+ }
+ function onDragOver(e: DragEvent, i: number) {
+ if (dragIndex == null) return;
+ e.preventDefault();
+ if (e.dataTransfer) e.dataTransfer.dropEffect = 'move';
+ dropIndex = i;
+ }
+ function onDrop() {
+ if (dragIndex != null && dropIndex != null && dragIndex !== dropIndex) {
+ session.command('reorderList', {
+ newIndex: dropIndex,
+ oldIndex: dragIndex
+ });
+ }
+ dragIndex = null;
+ dropIndex = null;
+ }
+ function onDragEnd() {
+ dragIndex = null;
+ dropIndex = null;
+ }
</script>
<div class="list">
{#if $gameState}
- {#each $gameState.currentList as item (item.id)}
- {#if isCharacter(item)}
- <CharacterRow {session} {item} {onOpenMenu} />
- {:else if isMonster(item)}
- <MonsterRow
- {session}
- {item}
- {onOpenMenu}
- {campaignData}
- {onOpenAbility}
- {onZoomAbility}
- />
- {:else if isNoteRow(item)}
- <NoteRow {session} {item} />
- {/if}
+ {#each $gameState.currentList as item, i (item.id)}
+ <div
+ class="list__slot"
+ class:list__slot--drop={dropIndex === i && dragIndex != null && dragIndex !== i}
+ draggable={!!$player}
+ ondragstart={(e) => onDragStart(e, i)}
+ ondragover={(e) => onDragOver(e, i)}
+ ondrop={onDrop}
+ ondragend={onDragEnd}
+ ondragleave={() => {
+ if (dropIndex === i) dropIndex = null;
+ }}
+ >
+ {#if isCharacter(item)}
+ <CharacterRow
+ {session}
+ {item}
+ {onOpenMenu}
+ onAddSummon={() => onAddSummon(item)}
+ />
+ {:else if isMonster(item)}
+ <MonsterRow
+ {session}
+ {item}
+ {onOpenMenu}
+ {campaignData}
+ {onOpenAbility}
+ {onZoomAbility}
+ />
+ {:else if isNoteRow(item)}
+ <NoteRow {session} {item} onEdit={onEditNote} />
+ {/if}
+ </div>
{/each}
{#if $gameState.currentList.length === 0}
<p style="padding: 40px 12px; text-align: center; opacity: 0.7">
@@ -57,3 +114,17 @@
{/if}
{/if}
</div>
+
+<style>
+ .list__slot {
+ width: 100%;
+ }
+ .list__slot--drop {
+ outline: 2px solid #7ec8ff;
+ outline-offset: -2px;
+ border-radius: 6px;
+ }
+ .list__slot:focus-visible {
+ outline: 2px solid #7ec8ff;
+ }
+</style>
diff --git a/web/src/lib/ui/MainMenu.svelte b/web/src/lib/ui/MainMenu.svelte
index f0aca7a..59386a2 100644
--- a/web/src/lib/ui/MainMenu.svelte
+++ b/web/src/lib/ui/MainMenu.svelte
@@ -6,6 +6,7 @@
-->
<script lang="ts">
import type { GameSession } from '$lib/state/session';
+ import { shouldShowAlliesDeck } from '$lib/game/rules';
import { t } from '$lib/i18n';
export type MenuName =
@@ -32,11 +33,29 @@
const gameState = session.state;
const index = session.index;
+ const player = session.player;
function pick(menu: MenuName) {
open = false;
onOpenMenu(menu);
}
+
+ // The ally deck (the reference `MainMenuViewModel.showShowAllyDeck` /
+ // `showHideAllyDeck`; the web always shows the AMD deck, so that gate
+ // is dropped).
+ const showShowAllyDeck = $derived.by(() => {
+ const gs = $gameState;
+ return gs != null && !gs.showAllyDeck && !shouldShowAlliesDeck(gs);
+ });
+ const showHideAllyDeck = $derived.by(() => {
+ const gs = $gameState;
+ return gs != null && gs.showAllyDeck;
+ });
+
+ function toggleAllyDeck(show: boolean) {
+ if (!$player) return;
+ session.command(show ? 'showAllyDeck' : 'hideAllyDeck');
+ }
</script>
{#if open}
@@ -81,6 +100,16 @@
<button class="drawer__item" onclick={() => pick('addMon')}>{t('menuAddMonsters')}</button>
<button class="drawer__item" onclick={() => pick('removeMon')}>{t('menuRemoveMonsters')}</button>
<button class="drawer__item" onclick={() => pick('noteRow')}>{t('menuAddNoteRow')}</button>
+ {#if showShowAllyDeck}
+ <button class="drawer__item" disabled={!$player} onclick={() => toggleAllyDeck(true)}>
+ {t('menuShowAllyDeck')}
+ </button>
+ {/if}
+ {#if showHideAllyDeck}
+ <button class="drawer__item" disabled={!$player} onclick={() => toggleAllyDeck(false)}>
+ {t('menuHideAllyDeck')}
+ </button>
+ {/if}
<hr class="drawer__divider" />
diff --git a/web/src/lib/ui/MonsterRow.svelte b/web/src/lib/ui/MonsterRow.svelte
index e2a4383..ffab021 100644
--- a/web/src/lib/ui/MonsterRow.svelte
+++ b/web/src/lib/ui/MonsterRow.svelte
@@ -8,7 +8,7 @@
import type { GameSession } from '$lib/state/session';
import type { MonsterItem } from '$lib/protocol/types';
import type { CampaignData } from '$lib/data/gameData';
- import { monsterImage } from '$lib/game/art';
+ import { monsterImage, summonImage } from '$lib/game/art';
import { standeeFigureId } from '$lib/game/stats';
import { isFrosthavenStyleForMonster } from '$lib/game/rules';
import { styleTheme } from '$lib/settings';
@@ -80,6 +80,24 @@
if (gs == null || model == null) return false;
return isFrosthavenStyleForMonster(model.edition, gs, $styleTheme);
});
+
+ // --- standee images (the reference `MonsterBoxBody`) --------------------
+
+ /**
+ * Summon standees show their summon art; a normal standee marked as
+ * "summoned this round" gets the green summon overlay instead.
+ */
+ function standeeImage(standee: (typeof instances)[number]): string {
+ if (standee.type === 3) return summonImage(standee.gfx);
+ if (standee.roundSummoned !== -1) return summonImage('green');
+ return monsterImage(standee.gfx);
+ }
+
+ // Grayscaled while its owner's turn is current (the reference
+ // `isSummonedThisTurn`: marked this round AND the owner's turn).
+ function standeeGrayed(standee: (typeof instances)[number]): boolean {
+ return standee.roundSummoned === ($gameState?.round ?? 0) && currentTurn;
+ }
</script>
<div class="row row--monster" class:row--current={currentTurn} class:row--done={gray}>
@@ -127,10 +145,15 @@
<button
class="monster__box"
class:monster__box--dead={standee.health <= 0}
+ class:monster__box--summon={standee.type === 3}
+ class:monster__box--grayed={standeeGrayed(standee)}
onclick={() => onOpenMenu(figureFor(i))}
aria-label={item.id}
>
- <img src={monsterImage(standee.gfx)} alt="" loading="lazy" />
+ <img src={standeeImage(standee)} alt="" loading="lazy" />
+ {#if standee.standeeNr > 0}
+ <span class="monster__box-nr">{standee.standeeNr}</span>
+ {/if}
<span class="monster__box-hp">{standee.health}</span>
</button>
{/each}
diff --git a/web/src/lib/ui/NoteRow.svelte b/web/src/lib/ui/NoteRow.svelte
index 34af63e..f237c13 100644
--- a/web/src/lib/ui/NoteRow.svelte
+++ b/web/src/lib/ui/NoteRow.svelte
@@ -1,57 +1,174 @@
<!--
- A note row (the reference `NoteRowWidget`, Phase 3 placeholder): a
- free-form coloured row. Tapping it edits the text inline and commits
- through `setNoteRowText`.
+ A note row (the reference `NoteRowWidget`): a coloured row in the main
+ list. When linked it takes a gradient derived from its target row's
+ colour (the character's class colour, or a red/blue base for
+ enemy/ally monsters) with an indent and connector; monster notes are
+ prefixed with the standee number (or "All"). Unlinked notes use their
+ own colour and a note icon. Tapping opens the editor.
-->
<script lang="ts">
import type { GameSession } from '$lib/state/session';
- import type { NoteRowItem } from '$lib/protocol/types';
+ import { isCharacter, isMonster, type NoteRowItem } from '$lib/protocol/types';
+ import { classColor } from '$lib/game/art';
+ import { classInfo } from '$lib/data/classInfo';
+ import { t } from '$lib/i18n';
let {
session,
- item
+ item,
+ onEdit
}: {
session: GameSession;
item: NoteRowItem;
+ onEdit: (item: NoteRowItem) => void;
} = $props();
- const player = session.player;
+ const gameState = session.state;
- let editing = $state(false);
- let draft = $state(item.text);
+ // Base tones for monster targets, which have no per-figure colour.
+ const ENEMY_BASE = 0x8e2a2a;
+ const ALLY_BASE = 0x2a4a8e;
- function colorCss(color: number): string {
- return `#${color.toString(16).padStart(8, '0').slice(2)}`;
- }
+ /** The target row, or null when unlinked / target absent. */
+ const target = $derived.by(() => {
+ const gs = $gameState;
+ if (item.linkedId === '' || gs == null) return null;
+ return gs.currentList.find((i) => i.id === item.linkedId) ?? null;
+ });
+ const linked = $derived(target != null);
+ const targetIsMonster = $derived(target != null && isMonster(target));
+
+ // The linked character's class colour (the reference reads it from the
+ // character model; the web resolves it from the campaign data).
+ let targetColor = $state<string | null>(null);
+ $effect(() => {
+ const tgt = target;
+ targetColor = null;
+ if (tgt != null && isCharacter(tgt)) {
+ let alive = true;
+ classInfo(tgt.edition, tgt.characterClass)
+ .then((c) => {
+ if (alive) targetColor = c ? c.color : null;
+ })
+ .catch(() => {});
+ return () => {
+ alive = false;
+ };
+ }
+ });
- function startEdit() {
- if (!$player) return;
- draft = item.text;
- editing = true;
+ /** ARGB int from a class ARGB hex string, or null. */
+ function hexToArgb(hex: string | null): number | null {
+ if (hex == null || !/^[0-9a-f]{8}$/i.test(hex)) return null;
+ return parseInt(hex, 16);
}
- function commit() {
- editing = false;
- if (draft !== item.text) {
- session.command('setNoteRowText', { text: draft, noteId: item.id });
+ /** The base colour a note derives from (target colour or its own). */
+ const base = $derived.by((): number => {
+ if (target != null) {
+ if (isCharacter(target)) {
+ const c = hexToArgb(targetColor);
+ if (c != null) return c;
+ } else if (isMonster(target)) {
+ return target.isAlly ? ALLY_BASE : ENEMY_BASE;
+ }
}
+ return item.color;
+ });
+
+ /** `Color.lerp(base, white, amount)` — mix toward white. */
+ function lighten(argb: number, amount: number): string {
+ const r = argb >> 16 & 0xff;
+ const g = argb >> 8 & 0xff;
+ const b = argb & 0xff;
+ const m = (c: number) => Math.round(c + (255 - c) * amount);
+ return `rgb(${m(r)}, ${m(g)}, ${m(b)})`;
}
+ // Inverted gradient (darker at top) echoes the figure rows' framed look.
+ const gradTop = $derived(lighten(base, 0.3));
+ const gradBottom = $derived(lighten(base, 0.6));
+ const borderCss = $derived(colorCss(base, 0.8));
+
+ function colorCss(argb: number, alpha = 1): string {
+ const r = argb >> 16 & 0xff;
+ const g = argb >> 8 & 0xff;
+ const b = argb & 0xff;
+ return alpha >= 1 ? `rgb(${r}, ${g}, ${b})` : `rgba(${r}, ${g}, ${b}, ${alpha})`;
+ }
+
+ // Contrast against the darker (top) part of the gradient.
+ const darkTop = $derived.by(() => {
+ const r = base >> 16 & 0xff;
+ const g = base >> 8 & 0xff;
+ const b = base & 0xff;
+ return 0.299 * r + 0.587 * g + 0.114 * b < 128;
+ });
+ const fg = $derived(darkTop ? '#fff' : 'rgba(0, 0, 0, 0.87)');
+ const fgFaint = $derived(darkTop ? 'rgba(255, 255, 255, 0.6)' : 'rgba(0, 0, 0, 0.54)');
+
+ const empty = $derived(item.text.trim() === '');
</script>
-<div class="row row--note" style:background-color={colorCss(item.color)}>
- <div class="note__text">
- {#if editing}
- <input
- class="search"
- style="margin: 0; width: 100%"
- bind:value={draft}
- onblur={commit}
- onkeydown={(e) => {
- if (e.key === 'Enter') commit();
- }}
- />
- {:else}
- <button class="note__edit" onclick={startEdit}>{item.text || '…'}</button>
- {/if}
- </div>
+<div
+ class="note__row"
+ role="button"
+ tabindex={0}
+ aria-label={t('noteRowTitle')}
+ onclick={() => onEdit(item)}
+ onkeydown={(e) => {
+ if (e.key === 'Enter' || e.key === ' ') onEdit(item);
+ }}
+ style="margin-left: {linked ? 27 : 3}px; margin-right: 3px;
+ background: linear-gradient(180deg, {gradTop} 0%, {gradBottom} 100%);
+ border: 1.3px solid {borderCss};
+ color: {fg}"
+>
+ <span class="note__icon">{linked ? '›' : '✎'}</span>
+ {#if linked && targetIsMonster && target}
+ <span class="note__standee" style="color: {fg}">
+ {item.standeeNr > 0 ? item.standeeNr + ':' : t('noteRowAll') + ':'}
+ </span>
+ {/if}
+ <span class="note__text" style="color: {empty ? fgFaint : fg}">
+ {empty ? t('noteRowHint') : item.text}
+ </span>
</div>
+
+<style>
+ .note__row {
+ display: flex;
+ align-items: center;
+ gap: 6px;
+ height: 40px;
+ margin-bottom: 1px;
+ padding: 0 8px;
+ border-radius: 6px;
+ box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
+ cursor: pointer;
+ min-width: 0;
+ box-sizing: border-box;
+ }
+ .note__row:focus-visible {
+ outline: 2px solid #7ec8ff;
+ }
+ .note__icon {
+ flex: 0 0 auto;
+ font-size: 14px;
+ opacity: 0.75;
+ }
+ .note__standee {
+ flex: 0 0 auto;
+ font-size: 12px;
+ font-weight: 700;
+ }
+ .note__text {
+ flex: 1;
+ min-width: 0;
+ font-size: 12px;
+ overflow: hidden;
+ display: -webkit-box;
+ -webkit-line-clamp: 2;
+ -webkit-box-orient: vertical;
+ text-overflow: ellipsis;
+ }
+</style>
diff --git a/web/src/lib/ui/StatusMenu.svelte b/web/src/lib/ui/StatusMenu.svelte
index 46f6325..e968883 100644
--- a/web/src/lib/ui/StatusMenu.svelte
+++ b/web/src/lib/ui/StatusMenu.svelte
@@ -21,7 +21,9 @@
import { isObjectiveOrEscort } from '$lib/data/classInfo';
import { CONDITIONS } from '$lib/game/conditions';
import { t } from '$lib/i18n';
+ import type { CampaignData } from '$lib/data/gameData';
import Menu from './Menu.svelte';
+ import FigureNoteMenu from './menus/FigureNoteMenu.svelte';
export interface FigureRef {
title: string;
@@ -38,10 +40,16 @@
let {
session,
figure,
+ campaignData,
+ onAddNoteRow,
open = $bindable(true)
}: {
session: GameSession;
figure: FigureRef;
+ /** Campaign data (monster model lookup for the Ice Wraith gate). */
+ campaignData?: CampaignData | null;
+ /** Open the note-row editor with a preset link target. */
+ onAddNoteRow: (presetLinkId: string) => void;
open?: boolean;
} = $props();
@@ -131,6 +139,62 @@
if (conditions.includes(index)) cmd('removeCondition', args);
else cmd('addCondition', args);
}
+
+ // --- Phase 5 extras ------------------------------------------------------
+
+ /** The owning monster's model (Ice Wraith gate), for monster figures. */
+ const monsterModel = $derived.by(() => {
+ if (figure.kind !== 'monster' || !campaignData) return null;
+ const owner = liveOwner;
+ if (owner == null || !('monsterInstances' in owner)) return null;
+ return (
+ campaignData.monsters.find(
+ (m) => m.name === owner.type || m.display === owner.type
+ ) ?? null
+ );
+ });
+
+ const isIceWraith = $derived(monsterModel?.deck === 'Ice Wraith');
+ const isElite = $derived(liveStandee?.type === 1);
+
+ function switchForm() {
+ // The command takes the *current* elite state and toggles it.
+ cmd('iceWraithChangeForm', {
+ isElite,
+ ownerId: figure.ownerId ?? '',
+ figureId: figure.figureId
+ });
+ }
+
+ // The summon mark (the reference `StatusMenuSummonButton`).
+ const summonMarked = $derived(liveStandee?.roundSummoned !== -1);
+
+ function toggleSummon() {
+ cmd('setAsSummon', {
+ summoned: !summonMarked,
+ figureId: figure.figureId,
+ ownerId: figure.ownerId ?? ''
+ });
+ }
+
+ // The figure's quick note (characters and monsters; not summons).
+ const noteFigure = $derived.by(() => {
+ if (figure.kind === 'character') return liveCharacter;
+ if (figure.kind === 'monster')
+ return liveOwner && 'note' in liveOwner ? liveOwner : null;
+ return null;
+ });
+
+ let noteOpen = $state(false);
+
+ function openNote() {
+ noteOpen = true;
+ }
+
+ /** The link target preset when adding a note row from here. */
+ function presetLinkTarget(): string {
+ return figure.ownerId ?? figure.figureId;
+ }
</script>
<Menu open={open} title={figure.title}>
@@ -197,6 +261,48 @@
{/each}
</div>
+ <div class="dialog__body" style="padding-top: 8px">
+ {#if isIceWraith}
+ <button
+ class="stepbtn"
+ style="width: 100%; height: 36px"
+ disabled={!canAct}
+ onclick={switchForm}
+ >
+ Switch Form
+ </button>
+ {/if}
+ {#if figure.kind === 'monster' && liveStandee}
+ <button
+ class="stepbtn"
+ class:stepbtn--on={summonMarked}
+ style="width: 100%; height: 36px"
+ disabled={!canAct}
+ onclick={toggleSummon}
+ >
+ {summonMarked ? t('cmdRemoveSummonMark') : t('cmdMarkAsSummon')}
+ </button>
+ {/if}
+ {#if noteFigure}
+ <button
+ class="stepbtn"
+ style="width: 100%; height: 36px"
+ disabled={!canAct}
+ onclick={openNote}
+ >
+ {noteFigure.note || t('characterNoteQuickAdd')}
+ </button>
+ {/if}
+ <button
+ class="stepbtn"
+ style="width: 100%; height: 36px"
+ disabled={!canAct}
+ onclick={() => onAddNoteRow(presetLinkTarget())}
+ >
+ {t('noteRowAddFromMenu')}
+ </button>
+ </div>
+
{#if roundState === 1}
<div class="dialog__body" style="padding-top: 8px">
<button
@@ -213,3 +319,12 @@
</div>
{/if}
</Menu>
+
+{#if noteOpen && noteFigure}
+ <FigureNoteMenu
+ {session}
+ figureId={figure.kind === 'character' ? figure.figureId : (figure.ownerId ?? figure.figureId)}
+ initial={noteFigure.note}
+ bind:open={noteOpen}
+ />
+{/if}
diff --git a/web/src/lib/ui/menus/AddNoteRowMenu.svelte b/web/src/lib/ui/menus/AddNoteRowMenu.svelte
deleted file mode 100644
index 5bb14a0..0000000
--- a/web/src/lib/ui/menus/AddNoteRowMenu.svelte
+++ /dev/null
@@ -1,113 +0,0 @@
-<!--
- 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>
diff --git a/web/src/lib/ui/menus/AddSectionMenu.svelte b/web/src/lib/ui/menus/AddSectionMenu.svelte
index 991b6a5..8fdef55 100644
--- a/web/src/lib/ui/menus/AddSectionMenu.svelte
+++ b/web/src/lib/ui/menus/AddSectionMenu.svelte
@@ -2,6 +2,15 @@
Add Section (the reference `AddSectionMenu`): lists the addable sections
of the current scenario (its rooms after the start room, minus spawns)
and adds one via `setScenario { scenario, section: true }`.
+
+ Reference behaviors ported here:
+ - case-insensitive search filter over the section names;
+ - ordering by the section number (`findNrFromScenarioName`) with a
+ string-compare fallback;
+ - sections already in the scenario are greyed out and tapping them is a
+ no-op;
+ - the search label is "Add Random Dungeon Card" when the scenario is
+ "#Random Dungeon".
-->
<script lang="ts">
import type { GameSession } from '$lib/state/session';
@@ -21,11 +30,25 @@
const player = session.player;
let sections = $state<string[] | null>(null);
+ let search = $state('');
+
+ /** Port of the reference `GameMethods.findNrFromScenarioName`: drop the
+ * first character, read until a space or `.`, and parse an int. Null when
+ * the remainder is not a number. */
+ function sectionNr(name: string): number | null {
+ const rest = name.slice(1);
+ const end = rest.search(/[ .]/);
+ const nr = end === -1 ? rest : rest.slice(0, end);
+ if (nr === '') return null;
+ const n = Number(nr);
+ return Number.isInteger(n) ? n : null;
+ }
$effect(() => {
if (!open) return;
const s = $gameState?.scenario ?? '';
const c = $gameState?.currentCampaign ?? '';
+ search = '';
if (!s || !c) {
sections = [];
return;
@@ -45,35 +68,77 @@
};
});
+ const shown = $derived.by(() => {
+ const all = sections ?? [];
+ const q = search.trim().toLowerCase();
+ const filtered = q
+ ? all.filter((n) => n.toLowerCase().includes(q))
+ : all;
+ return [...filtered].sort((a, b) => {
+ const aNr = sectionNr(a);
+ const bNr = sectionNr(b);
+ if (aNr != null && bNr != null) return aNr - bNr;
+ return a < b ? -1 : a > b ? 1 : 0;
+ });
+ });
+
+ const added = $derived($gameState?.scenarioSectionsAdded ?? []);
+
+ function isAdded(section: string): boolean {
+ return added.includes(section);
+ }
+
function pick(section: string) {
- if (!$player) return;
+ if (!$player || isAdded(section)) return;
// For sections the wire `scenario` field carries the *section name*;
// the server matches it against the current scenario's sections.
session.command('setScenario', { scenario: section, section: true });
open = false;
}
+
+ /** The reference relabels the search field on the random dungeon. */
+ const searchLabel = $derived(
+ $gameState?.scenario === '#Random Dungeon'
+ ? t('menuAddRandomDungeonCard')
+ : t('menuAddSection')
+ );
</script>
<Menu open={open} title={t('menuAddSection')}>
{#if !$gameState?.scenario}
- <p style="padding: 12px; opacity: 0.7">{t('web:noScenario')}</p>
- {:else if sections === null}
- <p style="padding: 12px; opacity: 0.7">{t('connecting')}</p>
- {:else if sections.length === 0}
- <p style="padding: 12px; opacity: 0.7">{t('noResultsFound')}</p>
+ <p class="empty">{t('web:noScenario')}</p>
{:else}
- <ul class="menulist">
- {#each sections as section (section)}
- <li>
- <button
- class="menulist__item"
- disabled={!$player}
- onclick={() => pick(section)}
- >
- {section}
- </button>
- </li>
- {/each}
- </ul>
+ <input class="search" placeholder={searchLabel} bind:value={search} />
+ {#if sections === null}
+ <p class="empty">{t('connecting')}</p>
+ {:else if shown.length === 0}
+ <p class="empty">{t('noResultsFound')}</p>
+ {:else}
+ <ul class="menulist">
+ {#each shown as section (section)}
+ <li>
+ <button
+ class="menulist__item"
+ class:menulist__item--added={isAdded(section)}
+ disabled={!$player || isAdded(section)}
+ onclick={() => pick(section)}
+ >
+ {section}
+ </button>
+ </li>
+ {/each}
+ </ul>
+ {/if}
{/if}
</Menu>
+
+<style>
+ .empty {
+ padding: 12px;
+ opacity: 0.7;
+ }
+ /* The reference greys added sections (Colors.blueGrey on a light theme). */
+ .menulist__item--added {
+ color: #90a4ae;
+ }
+</style>
diff --git a/web/src/lib/ui/menus/AddSummonMenu.svelte b/web/src/lib/ui/menus/AddSummonMenu.svelte
new file mode 100644
index 0000000..a60cb42
--- /dev/null
+++ b/web/src/lib/ui/menus/AddSummonMenu.svelte
@@ -0,0 +1,261 @@
+<!--
+ Add Summon (the reference `AddSummonMenu`): choose a standee colour and
+ number, then pick from the character's class summons (filtered by level
+ and standee cap) or the generic item summons. Adding sends `addStandee`
+ with `type: 3` (summon) and `addAsSummon: true`.
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import type { CharacterItem } from '$lib/protocol/types';
+ import { gameData, type SummonModel } from '$lib/data/gameData';
+ import { summonImage } from '$lib/game/art';
+ import Menu from '../Menu.svelte';
+
+ const COLORS = ['blue', 'green', 'yellow', 'orange', 'white', 'purple', 'pink', 'red'];
+ const MIN_STANDEES_FOR_NR = 2;
+ const NUMBERS = [1, 2, 3, 4, 5, 6, 7, 8];
+
+ let {
+ session,
+ character,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ character: CharacterItem;
+ open?: boolean;
+ } = $props();
+
+ const player = session.player;
+ const gameState = session.state;
+
+ let chosenGfx = $state('blue');
+ let chosenNr = $state(1);
+
+ // The class's summonable figures (the reference filters by level and the
+ // number of standees already out; item summons are always listed).
+ let classSummons = $state<SummonModel[] | null>(null);
+ let itemSummons = $state<SummonModel[] | null>(null);
+
+ $effect(() => {
+ if (!open) return;
+ let alive = true;
+ classSummons = null;
+ itemSummons = null;
+ gameData
+ .loadCampaign(character.edition)
+ .then((c) => {
+ const cls = c.classes.find(
+ (x) => x.name === character.characterClass || x.id === character.characterClass
+ );
+ if (!alive || !cls) return;
+ const level = character.characterState.level;
+ classSummons = cls.summons
+ .filter((s) => s.level <= level)
+ .filter((s) => {
+ const out = character.characterState.summonList.filter(
+ (x) => x.name === s.name
+ ).length;
+ return out < s.standees;
+ });
+ })
+ .catch(() => {});
+ gameData
+ .summons()
+ .then((list) => {
+ if (alive) itemSummons = list;
+ })
+ .catch(() => {});
+ return () => {
+ alive = false;
+ };
+ });
+
+ /** The entries to list (class summons first, then item summons). */
+ const entries = $derived.by(() => {
+ const out: SummonModel[] = [];
+ if (classSummons) out.push(...classSummons);
+ if (itemSummons) out.push(...itemSummons);
+ return out;
+ });
+
+ function entryGfx(model: SummonModel): string {
+ return model.gfx || chosenGfx;
+ }
+
+ /** The standee number shown for a model (hidden for fixed-art, single-standee). */
+ function entryNr(model: SummonModel): number {
+ if (model.gfx && model.standees < MIN_STANDEES_FOR_NR) return 0;
+ return chosenNr;
+ }
+
+ function add(model: SummonModel) {
+ if (!$player) return;
+ const gfx = entryGfx(model);
+ const nr = entryNr(model);
+ session.command('addStandee', {
+ nr,
+ summon: {
+ standeeNr: nr,
+ name: model.name,
+ health: model.health,
+ move: model.move,
+ attack: model.attack,
+ range: model.range,
+ gfx
+ },
+ ownerId: character.id,
+ type: 3,
+ addAsSummon: true
+ });
+ open = false;
+ }
+</script>
+
+<Menu {open} title="Add Summon">
+ <div class="swatches" role="radiogroup" aria-label="standee colour">
+ {#each COLORS as c (c)}
+ <button
+ class="swatch"
+ class:swatch--selected={c === chosenGfx}
+ disabled={!$player}
+ aria-label={c}
+ onclick={() => (chosenGfx = c)}
+ >
+ <img src={summonImage(c)} alt="" />
+ </button>
+ {/each}
+ </div>
+
+ <div class="numbers" role="radiogroup" aria-label="standee number">
+ {#each NUMBERS as n (n)}
+ <button
+ class="numbtn"
+ class:numbtn--selected={n === chosenNr}
+ disabled={!$player}
+ onclick={() => (chosenNr = n)}
+ >
+ {n}
+ </button>
+ {/each}
+ </div>
+
+ {#if $gameState}
+ <ul class="summonlist">
+ {#each entries as model (model.name + model.gfx)}
+ <li>
+ <button
+ class="summonlist__item"
+ disabled={!$player}
+ onclick={() => add(model)}
+ >
+ <span class="summonlist__art">
+ <img src={summonImage(entryGfx(model))} alt="" />
+ {#if entryNr(model) > 0}
+ <span class="summonlist__nr">{entryNr(model)}</span>
+ {/if}
+ </span>
+ <span class="summonlist__name">{model.name}</span>
+ </button>
+ </li>
+ {/each}
+ </ul>
+ {/if}
+</Menu>
+
+<style>
+ .swatches {
+ display: flex;
+ flex-wrap: wrap;
+ gap: 6px;
+ margin-bottom: 10px;
+ justify-content: center;
+ }
+ .swatch {
+ width: 40px;
+ height: 40px;
+ padding: 3px;
+ border-radius: 4px;
+ border: 1px solid rgba(255, 255, 255, 0.25);
+ background: rgba(0, 0, 0, 0.3);
+ cursor: pointer;
+ }
+ .swatch--selected {
+ border: 2px solid #7ec8ff;
+ }
+ .swatch img {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+ }
+ .numbers {
+ display: grid;
+ grid-template-columns: repeat(4, 1fr);
+ gap: 6px;
+ margin-bottom: 12px;
+ }
+ .numbtn {
+ height: 32px;
+ font-size: 13px;
+ border: 1px solid rgba(255, 255, 255, 0.25);
+ border-radius: 4px;
+ background: rgba(0, 0, 0, 0.3);
+ color: inherit;
+ cursor: pointer;
+ }
+ .numbtn--selected {
+ border: 2px solid #7ec8ff;
+ font-weight: 700;
+ }
+ .summonlist {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ max-height: 40vh;
+ overflow-y: auto;
+ }
+ .summonlist__item {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ width: 100%;
+ padding: 6px 8px;
+ border: none;
+ border-radius: 4px;
+ background: none;
+ color: inherit;
+ font-size: 13px;
+ text-align: left;
+ cursor: pointer;
+ }
+ .summonlist__item:hover {
+ background: rgba(255, 255, 255, 0.1);
+ }
+ .summonlist__art {
+ position: relative;
+ width: 32px;
+ height: 32px;
+ flex: 0 0 auto;
+ }
+ .summonlist__art img {
+ width: 100%;
+ height: 100%;
+ object-fit: contain;
+ }
+ .summonlist__nr {
+ position: absolute;
+ inset: 0;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ font-size: 14px;
+ font-weight: 700;
+ color: #fff;
+ text-shadow: 0 0 3px #000, 0 1px 2px #000;
+ }
+ .summonlist__name {
+ min-width: 0;
+ overflow: hidden;
+ text-overflow: ellipsis;
+ white-space: nowrap;
+ }
+</style>
diff --git a/web/src/lib/ui/menus/FigureNoteMenu.svelte b/web/src/lib/ui/menus/FigureNoteMenu.svelte
new file mode 100644
index 0000000..0f79578
--- /dev/null
+++ b/web/src/lib/ui/menus/FigureNoteMenu.svelte
@@ -0,0 +1,83 @@
+<!--
+ A figure's quick note (the reference `SetFigureNoteMenu`): the free-form
+ note shown inline on a figure's row (character or monster). The note is
+ committed (via `setFigureNote`) when the field loses focus or the dialog
+ is dismissed, and only when the text actually changed, so an unedited
+ open/close doesn't pollute the undo history.
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import Menu from '../Menu.svelte';
+
+ let {
+ session,
+ figureId,
+ initial,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ figureId: string;
+ initial: string;
+ open?: boolean;
+ } = $props();
+
+ const player = session.player;
+
+ let text = $state(initial);
+ let lastCommitted = $state(initial);
+
+ function commit() {
+ const trimmed = text.trim();
+ if (trimmed !== lastCommitted) {
+ lastCommitted = trimmed;
+ if ($player)
+ session.command('setFigureNote', { note: trimmed, figureId });
+ }
+ }
+
+ function close() {
+ commit();
+ open = false;
+ }
+</script>
+
+<Menu {open}>
+ <textarea
+ class="search search--area"
+ rows={3}
+ maxlength={140}
+ placeholder="…"
+ bind:value={text}
+ readonly={!$player}
+ onblur={commit}
+ ></textarea>
+ {#if $player}
+ <div class="actions">
+ <button class="pill" onclick={close}>Save</button>
+ </div>
+ {/if}
+</Menu>
+
+<style>
+ textarea.search--area {
+ resize: vertical;
+ min-height: 64px;
+ }
+ .actions {
+ display: flex;
+ justify-content: flex-end;
+ margin-top: 10px;
+ }
+ .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);
+ }
+</style>
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>
diff --git a/web/src/lib/ui/menus/SettingsMenu.svelte b/web/src/lib/ui/menus/SettingsMenu.svelte
index ef5a91a..4a6699a 100644
--- a/web/src/lib/ui/menus/SettingsMenu.svelte
+++ b/web/src/lib/ui/menus/SettingsMenu.svelte
@@ -1,20 +1,35 @@
<!--
- Settings (Phase 3 subset of the reference `SettingsMenu`): the visual
- style theme and the UI language. Both are client-only preferences.
+ Settings (the reference `SettingsMenu`): the visual style theme and the
+ UI language (client-only preferences), plus the special-unlock controls
+ (the reference `settingsClearUnlocked` / `settingsUnlockSpecials`
+ entries, which are game commands).
-->
<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
import { availableLocales, locale, type Locale } from '$lib/i18n';
import { styleTheme, type StyleTheme } from '$lib/settings';
import { t } from '$lib/i18n';
import Menu from '../Menu.svelte';
+ import SpecialUnlocksMenu from './SpecialUnlocksMenu.svelte';
- let { open = $bindable(true) }: { open?: boolean } = $props();
+ let {
+ session,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ open?: boolean;
+ } = $props();
+
+ const player = session.player;
+ const gameState = session.state;
const THEMES: { id: StyleTheme; label: string }[] = [
{ id: 'frosthaven', label: 'Frosthaven' },
{ id: 'gloomhaven', label: 'Gloomhaven' },
{ id: 'original', label: 'Original' }
];
+
+ let unlocksOpen = $state(false);
</script>
<Menu open={open} title={t('menuSettings')}>
@@ -47,4 +62,46 @@
{/each}
</select>
</div>
+
+ <div class="settingsrow settingsrow--btn">
+ <button
+ class="pill"
+ disabled={!$player || !($gameState?.unlockedClasses.length ?? 0)}
+ onclick={() => session.command('clearUnlockedClasses')}
+ >
+ {t('settingsClearUnlocked')}
+ </button>
+ </div>
+ <div class="settingsrow settingsrow--btn">
+ <button class="pill" onclick={() => (unlocksOpen = true)}>
+ {t('settingsUnlockSpecials')}
+ </button>
+ </div>
</Menu>
+
+{#if unlocksOpen}
+ <SpecialUnlocksMenu {session} bind:open={unlocksOpen} />
+{/if}
+
+<style>
+ .settingsrow--btn {
+ justify-content: flex-start;
+ }
+ .pill {
+ padding: 6px 12px;
+ font-size: 13px;
+ border: none;
+ border-radius: 4px;
+ background: rgba(255, 255, 255, 0.12);
+ color: inherit;
+ cursor: pointer;
+ text-align: left;
+ }
+ .pill:hover:not(:disabled) {
+ background: rgba(255, 255, 255, 0.25);
+ }
+ .pill:disabled {
+ opacity: 0.3;
+ cursor: default;
+ }
+</style>
diff --git a/web/src/lib/ui/menus/SpecialUnlocksMenu.svelte b/web/src/lib/ui/menus/SpecialUnlocksMenu.svelte
new file mode 100644
index 0000000..e565c33
--- /dev/null
+++ b/web/src/lib/ui/menus/SpecialUnlocksMenu.svelte
@@ -0,0 +1,83 @@
+<!--
+ Special Unlocks (the reference `SpecialUnlocksMenu`): toggles the special
+ characters available in the add-character menu (`unlockSpecial`). Locked
+ entries show as "???"; the icon is always visible.
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import { t } from '$lib/i18n';
+ import Menu from '../Menu.svelte';
+
+ /** The unlockable specials (the reference hard-codes this list). */
+ const UNLOCKS: { id: string; icon: string }[] = [
+ { id: 'Demons', icon: '/images/demons.png' },
+ { id: 'Merchant-Guild', icon: '/images/merchant-guild.png' },
+ { id: 'Military', icon: '/images/military.png' },
+ { id: 'Bladeswarm', icon: '/images/class-icons/Bladeswarm.png' }
+ ];
+
+ let {
+ session,
+ open = $bindable(true)
+ }: {
+ session: GameSession;
+ open?: boolean;
+ } = $props();
+
+ const gameState = session.state;
+ const player = session.player;
+
+ const unlocked = $derived($gameState?.unlockedClasses ?? []);
+
+ function isEnabled(id: string): boolean {
+ return unlocked.includes(id);
+ }
+
+ function toggle(id: string) {
+ if (!$player) return;
+ session.command('unlockSpecial', { id });
+ }
+</script>
+
+<Menu {open} title={t('specialUnlocks')}>
+ <ul class="unlocklist">
+ {#each UNLOCKS as u (u.id)}
+ <li>
+ <label class="unlocklist__item" class:unlocklist__item--disabled={!$player}>
+ <input
+ type="checkbox"
+ checked={isEnabled(u.id)}
+ disabled={!$player}
+ onchange={() => toggle(u.id)}
+ />
+ <img class="unlocklist__icon" src={u.icon} alt="" />
+ <span>{isEnabled(u.id) ? u.id : '???'}</span>
+ </label>
+ </li>
+ {/each}
+ </ul>
+</Menu>
+
+<style>
+ .unlocklist {
+ list-style: none;
+ margin: 0;
+ padding: 0;
+ }
+ .unlocklist__item {
+ display: flex;
+ align-items: center;
+ gap: 10px;
+ padding: 8px 4px;
+ font-size: 14px;
+ cursor: pointer;
+ }
+ .unlocklist__item--disabled {
+ cursor: default;
+ }
+ .unlocklist__icon {
+ width: 40px;
+ height: 40px;
+ object-fit: contain;
+ }
+</style>