summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/MonsterRow.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/lib/ui/MonsterRow.svelte')
-rw-r--r--web/src/lib/ui/MonsterRow.svelte109
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>