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/MonsterRow.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/MonsterRow.svelte')
| -rw-r--r-- | web/src/lib/ui/MonsterRow.svelte | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/web/src/lib/ui/MonsterRow.svelte b/web/src/lib/ui/MonsterRow.svelte new file mode 100644 index 0000000..3f3442b --- /dev/null +++ b/web/src/lib/ui/MonsterRow.svelte @@ -0,0 +1,109 @@ +<!-- + A monster row (the reference `MonsterWidget`): the monster art with its + name, the standee boxes (one per surviving instance, with health), the + level, and the turn-state styling. Tapping the art ends its turn + (playTurns); tapping the row or a standee box opens the stat menu. +--> +<script lang="ts"> + import type { GameSession } from '$lib/state/session'; + import type { MonsterItem } from '$lib/protocol/types'; + import { monsterImage } from '$lib/game/art'; + import { standeeFigureId } from '$lib/game/stats'; + import type { FigureRef } from './StatusMenu.svelte'; + + let { + session, + item, + onOpenMenu + }: { + session: GameSession; + item: MonsterItem; + onOpenMenu: (figure: FigureRef) => void; + } = $props(); + + const player = session.player; + const gameState = session.state; + + const roundState = $derived($gameState?.roundState ?? 0); + const turnState = $derived(item.turnState); + const currentTurn = $derived(roundState === 1 && turnState === 1); + const done = $derived(roundState === 1 && turnState === 2); + const gray = $derived(!item.isActive || done); + + const instances = $derived(item.monsterInstances); + const aliveInstances = $derived(instances.filter((s) => s.health > 0)); + const main = $derived(aliveInstances[0] ?? instances[0] ?? null); + + function figureFor(standeeIndex = 0): FigureRef { + const s = instances[standeeIndex] ?? instances[0]; + return { + title: item.id, + figureId: s ? standeeFigureId(s) : item.id, + ownerId: item.id, + kind: 'monster', + rowId: item.id, + isObjective: false + }; + } + + function onArtTap() { + if (roundState !== 1 || !item.isActive || !$player) return; + session.command('turnDone', { id: item.id }); + } +</script> + +<div class="row row--monster" class:row--current={currentTurn} class:row--done={gray}> + <div class="row__bg"></div> + + <div class="row__inner" style="align-items: flex-start"> + <div + class="row__art" + style="width: 96px; height: 96px" + role="button" + tabindex="0" + onclick={() => onOpenMenu(figureFor(0))} + onkeydown={(e) => { + if (e.key === 'Enter' || e.key === ' ') onOpenMenu(figureFor(0)); + }} + > + <img + src={main ? monsterImage(main.gfx) : ''} + alt={item.id} + style="width: 88px; height: 88px" + loading="lazy" + /> + </div> + + <div + style="flex: 1; min-width: 0; padding: 4px 0" + role="button" + tabindex="0" + onclick={() => onArtTap()} + onkeydown={(e) => { + if (e.key === 'Enter' || e.key === ' ') onArtTap(); + }} + > + <div class="row__name" style="font-size: 15px"> + {item.id} + {#if item.isAlly}<span class="chip" style="position: static; margin-left: 6px">ally</span>{/if} + </div> + <div class="row__hp">Level {item.level}</div> + </div> + </div> + + {#if instances.length > 0} + <div class="monster__boxes"> + {#each instances as standee, i} + <button + class="monster__box" + class:monster__box--dead={standee.health <= 0} + onclick={() => onOpenMenu(figureFor(i))} + aria-label={item.id} + > + <img src={monsterImage(standee.gfx)} alt="" loading="lazy" /> + <span class="monster__box-hp">{standee.health}</span> + </button> + {/each} + </div> + {/if} +</div> |
