1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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>
|