summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/menus/AddSectionMenu.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/AddSectionMenu.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/AddSectionMenu.svelte')
-rw-r--r--web/src/lib/ui/menus/AddSectionMenu.svelte103
1 files changed, 84 insertions, 19 deletions
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>