summaryrefslogtreecommitdiff
path: root/web/src/lib/game/stats.ts
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/game/stats.ts
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/game/stats.ts')
-rw-r--r--web/src/lib/game/stats.ts81
1 files changed, 81 insertions, 0 deletions
diff --git a/web/src/lib/game/stats.ts b/web/src/lib/game/stats.ts
new file mode 100644
index 0000000..d842159
--- /dev/null
+++ b/web/src/lib/game/stats.ts
@@ -0,0 +1,81 @@
+/**
+ * Reads current stat values for the status menu from the live state.
+ *
+ * Health / max / xp / chill / conditions live on the figure; bless, curse,
+ * empower and enfeeble live as modifier-deck cards — the server keeps their
+ * counter in sync with the matching cards in the character's draw pile, so
+ * counting the cards here mirrors the server's own computation.
+ */
+
+import type {
+ CharacterItem,
+ MonsterInstance
+} from '$lib/protocol/types';
+
+export interface ModifierCard {
+ gfx: string;
+}
+
+export interface ModifierDeckJson {
+ drawPile: ModifierCard[];
+ discardPile: ModifierCard[];
+ removedPile?: ModifierCard[];
+ [ key: string ]: unknown;
+}
+
+/**
+ * The wire `figureId` for a standee (a monster instance or a summon): the
+ * reference app builds it as `name + gfx + standeeNr`.
+ */
+export function standeeFigureId(standee: MonsterInstance): string {
+ return standee.name + standee.gfx + standee.standeeNr.toString();
+}
+
+/** Count modifier cards matching [predicate] in the draw pile. */
+function countCards(
+ deck: ModifierDeckJson | undefined,
+ predicate: (gfx: string) => boolean
+): number {
+ if (!deck?.drawPile) return 0;
+ return deck.drawPile.filter((c) => c && predicate(c.gfx)).length;
+}
+
+/**
+ * The stat counters for a character, keyed by the modifier-deck removable
+ * name (which is also the `gfx` wire arg for empower/enfeeble).
+ */
+export function characterStatCounters(
+ character: CharacterItem
+): {
+ bless: number;
+ curse: number;
+ empower: number;
+ enfeeble: number;
+} {
+ const deck = character.characterState.modifierDeck as
+ | ModifierDeckJson
+ | undefined;
+ return {
+ bless: countCards(deck, (g) => g === 'bless'),
+ curse: countCards(deck, (g) => g === 'curse'),
+ empower: countCards(deck, (g) => g.includes('empower')),
+ enfeeble: countCards(deck, (g) => g.includes('enfeeble'))
+ };
+}
+
+/** The stat counters for a standee (its owner's modifier deck). */
+export function standeeStatCounters(
+ deck: ModifierDeckJson | undefined
+): {
+ bless: number;
+ curse: number;
+ empower: number;
+ enfeeble: number;
+} {
+ return {
+ bless: countCards(deck, (g) => g === 'bless'),
+ curse: countCards(deck, (g) => g === 'curse'),
+ empower: countCards(deck, (g) => g.includes('empower')),
+ enfeeble: countCards(deck, (g) => g.includes('enfeeble'))
+ };
+}