diff options
| author | Joel Klinghed <the_jk@spawned.biz> | 2026-11-15 13:45:21 +0100 |
|---|---|---|
| committer | Joel Klinghed <the_jk@spawned.biz> | 2026-11-15 13:45:21 +0100 |
| commit | 4f50f2008f4d7c2a635f7f26861fcfc7f7504423 (patch) | |
| tree | 94e6286e7e22e0467a61b99c18b9ab582fbbe656 /web/src/lib/ui/ElementButton.svelte | |
| parent | 3ebbdf6ffa16f751c82e3bd2e74294f4fe843155 (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/ElementButton.svelte')
| -rw-r--r-- | web/src/lib/ui/ElementButton.svelte | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/web/src/lib/ui/ElementButton.svelte b/web/src/lib/ui/ElementButton.svelte new file mode 100644 index 0000000..46fd397 --- /dev/null +++ b/web/src/lib/ui/ElementButton.svelte @@ -0,0 +1,88 @@ +<!-- + One of the six elemental ability buttons in the top bar. The coloured + fill rises with the element's state (inert → half → full), exactly like + the reference `ElementButton`: + - tap: uses the element when it is active, imbues (full) when inert + - long press: imbues the half ("advanced") amount +--> +<script lang="ts"> + import type { GameSession } from '$lib/state/session'; + import { elementState } from '$lib/game/elements'; + + let { + session, + index, + name, + color, + icon, + label + }: { + session: GameSession; + /** The `Elements` index (state map key). */ + index: number; + /** The `Elements` wire name. */ + name: string; + color: string; + icon: string; + label: string; + } = $props(); + + const gameState = session.state; + const status = session.status; + const player = session.player; + + let pressTimer: ReturnType<typeof setTimeout> | null = null; + let longPressed = false; + + const elState = $derived($gameState ? elementState($gameState.elementState, index) : 2); + const interactive = $derived( + $gameState !== null && + ($status === 'open' || $status === 'reconnecting') && + $player + ); + + function onPressDown() { + if (!interactive) return; + longPressed = false; + pressTimer = setTimeout(() => { + longPressed = true; + session.command('imbueElement', { element: name, half: true }); + }, 500); + } + + function onPressUp() { + if (pressTimer) { + clearTimeout(pressTimer); + pressTimer = null; + } + if (interactive && !longPressed) { + // Tap: use when active, imbue when inert. + if (elState === 0 || elState === 1) { + session.command('useElement', { element: name }); + } else { + session.command('imbueElement', { element: name, half: false }); + } + } + } + + function onCancel() { + if (pressTimer) { + clearTimeout(pressTimer); + pressTimer = null; + } + } +</script> + +<button + class="elbtn" + aria-label={label} + style="--el-color: {color}" + disabled={!interactive} + onpointerdown={onPressDown} + onpointerup={onPressUp} + onpointerleave={onCancel} + oncontextmenu={(e) => e.preventDefault()} +> + <span class="elbtn__fill {elState === 0 ? 'full' : elState === 1 ? 'half' : ''}"></span> + <img class="elbtn__icon" src={icon} alt="" loading="lazy" /> +</button> |
