summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/menus/SelectScenarioMenu.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/SelectScenarioMenu.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/SelectScenarioMenu.svelte')
-rw-r--r--web/src/lib/ui/menus/SelectScenarioMenu.svelte109
1 files changed, 109 insertions, 0 deletions
diff --git a/web/src/lib/ui/menus/SelectScenarioMenu.svelte b/web/src/lib/ui/menus/SelectScenarioMenu.svelte
new file mode 100644
index 0000000..14add41
--- /dev/null
+++ b/web/src/lib/ui/menus/SelectScenarioMenu.svelte
@@ -0,0 +1,109 @@
+<!--
+ Set Scenario (the reference `SelectScenarioMenu`): pick a campaign, then
+ a scenario from it. Selecting sends `setCampaign` (when the campaign
+ changed) followed by `setScenario` — the server applies them in order.
+-->
+<script lang="ts">
+ import type { GameSession } from '$lib/state/session';
+ import { gameData, type CampaignData } from '$lib/data/gameData';
+ 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;
+
+ let campaigns = $state<string[] | null>(null);
+ let campaign = $state('');
+ let data = $state<CampaignData | null>(null);
+ let error = $state<string | null>(null);
+
+ // Load the campaign list and default to the current campaign.
+ $effect(() => {
+ if (!open) return;
+ let alive = true;
+ campaigns = null;
+ error = null;
+ gameData
+ .campaigns()
+ .then((list) => {
+ if (!alive) return;
+ campaigns = list;
+ campaign = $gameState?.currentCampaign && list.includes($gameState.currentCampaign)
+ ? $gameState.currentCampaign
+ : list[0] ?? '';
+ })
+ .catch(() => {
+ if (alive) error = 'failed to load campaigns';
+ });
+ return () => {
+ alive = false;
+ };
+ });
+
+ // Load the selected campaign's scenarios.
+ $effect(() => {
+ const c = campaign;
+ if (!open || !c) return;
+ let alive = true;
+ data = null;
+ gameData
+ .loadCampaign(c)
+ .then((d) => {
+ if (alive) data = d;
+ })
+ .catch(() => {
+ if (alive) error = 'failed to load campaign';
+ });
+ return () => {
+ alive = false;
+ };
+ });
+
+ function pickScenario(scenario: string) {
+ if (!$player) return;
+ if ($gameState && $gameState.currentCampaign !== campaign) {
+ session.command('setCampaign', { campaign });
+ }
+ session.command('setScenario', { scenario, section: false });
+ open = false;
+ }
+</script>
+
+<Menu open={open} title={t('menuSetScenario')}>
+ {#if error}
+ <p style="padding: 12px; opacity: 0.8">{error}</p>
+ {:else if campaigns}
+ <div class="campaignbtns">
+ {#each campaigns as c (c)}
+ <button class:button--active={c === campaign} onclick={() => (campaign = c)}>
+ {c}
+ </button>
+ {/each}
+ </div>
+ {#if data}
+ {#if data.scenarios.length === 0}
+ <p style="padding: 12px; opacity: 0.7">{t('noResultsFound')}</p>
+ {:else}
+ <ul class="menulist">
+ {#each data.scenarios as s (s.name)}
+ <li>
+ <button class="menulist__item" disabled={!$player} onclick={() => pickScenario(s.name)}>
+ {s.name}
+ </button>
+ </li>
+ {/each}
+ </ul>
+ {/if}
+ {:else}
+ <p style="padding: 12px; opacity: 0.7">{t('connecting')}</p>
+ {/if}
+ {/if}
+</Menu>