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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
<!--
Add Summon (the reference `AddSummonMenu`): choose a standee colour and
number, then pick from the character's class summons (filtered by level
and standee cap) or the generic item summons. Adding sends `addStandee`
with `type: 3` (summon) and `addAsSummon: true`.
-->
<script lang="ts">
import type { GameSession } from '$lib/state/session';
import type { CharacterItem } from '$lib/protocol/types';
import { gameData, type SummonModel } from '$lib/data/gameData';
import { summonImage } from '$lib/game/art';
import Menu from '../Menu.svelte';
const COLORS = ['blue', 'green', 'yellow', 'orange', 'white', 'purple', 'pink', 'red'];
const MIN_STANDEES_FOR_NR = 2;
const NUMBERS = [1, 2, 3, 4, 5, 6, 7, 8];
let {
session,
character,
open = $bindable(true)
}: {
session: GameSession;
character: CharacterItem;
open?: boolean;
} = $props();
const player = session.player;
const gameState = session.state;
let chosenGfx = $state('blue');
let chosenNr = $state(1);
// The class's summonable figures (the reference filters by level and the
// number of standees already out; item summons are always listed).
let classSummons = $state<SummonModel[] | null>(null);
let itemSummons = $state<SummonModel[] | null>(null);
$effect(() => {
if (!open) return;
let alive = true;
classSummons = null;
itemSummons = null;
gameData
.loadCampaign(character.edition)
.then((c) => {
const cls = c.classes.find(
(x) => x.name === character.characterClass || x.id === character.characterClass
);
if (!alive || !cls) return;
const level = character.characterState.level;
classSummons = cls.summons
.filter((s) => s.level <= level)
.filter((s) => {
const out = character.characterState.summonList.filter(
(x) => x.name === s.name
).length;
return out < s.standees;
});
})
.catch(() => {});
gameData
.summons()
.then((list) => {
if (alive) itemSummons = list;
})
.catch(() => {});
return () => {
alive = false;
};
});
/** The entries to list (class summons first, then item summons). */
const entries = $derived.by(() => {
const out: SummonModel[] = [];
if (classSummons) out.push(...classSummons);
if (itemSummons) out.push(...itemSummons);
return out;
});
function entryGfx(model: SummonModel): string {
return model.gfx || chosenGfx;
}
/** The standee number shown for a model (hidden for fixed-art, single-standee). */
function entryNr(model: SummonModel): number {
if (model.gfx && model.standees < MIN_STANDEES_FOR_NR) return 0;
return chosenNr;
}
function add(model: SummonModel) {
if (!$player) return;
const gfx = entryGfx(model);
const nr = entryNr(model);
session.command('addStandee', {
nr,
summon: {
standeeNr: nr,
name: model.name,
health: model.health,
move: model.move,
attack: model.attack,
range: model.range,
gfx
},
ownerId: character.id,
type: 3,
addAsSummon: true
});
open = false;
}
</script>
<Menu {open} title="Add Summon">
<div class="swatches" role="radiogroup" aria-label="standee colour">
{#each COLORS as c (c)}
<button
class="swatch"
class:swatch--selected={c === chosenGfx}
disabled={!$player}
aria-label={c}
onclick={() => (chosenGfx = c)}
>
<img src={summonImage(c)} alt="" />
</button>
{/each}
</div>
<div class="numbers" role="radiogroup" aria-label="standee number">
{#each NUMBERS as n (n)}
<button
class="numbtn"
class:numbtn--selected={n === chosenNr}
disabled={!$player}
onclick={() => (chosenNr = n)}
>
{n}
</button>
{/each}
</div>
{#if $gameState}
<ul class="summonlist">
{#each entries as model (model.name + model.gfx)}
<li>
<button
class="summonlist__item"
disabled={!$player}
onclick={() => add(model)}
>
<span class="summonlist__art">
<img src={summonImage(entryGfx(model))} alt="" />
{#if entryNr(model) > 0}
<span class="summonlist__nr">{entryNr(model)}</span>
{/if}
</span>
<span class="summonlist__name">{model.name}</span>
</button>
</li>
{/each}
</ul>
{/if}
</Menu>
<style>
.swatches {
display: flex;
flex-wrap: wrap;
gap: 6px;
margin-bottom: 10px;
justify-content: center;
}
.swatch {
width: 40px;
height: 40px;
padding: 3px;
border-radius: 4px;
border: 1px solid rgba(255, 255, 255, 0.25);
background: rgba(0, 0, 0, 0.3);
cursor: pointer;
}
.swatch--selected {
border: 2px solid #7ec8ff;
}
.swatch img {
width: 100%;
height: 100%;
object-fit: contain;
}
.numbers {
display: grid;
grid-template-columns: repeat(4, 1fr);
gap: 6px;
margin-bottom: 12px;
}
.numbtn {
height: 32px;
font-size: 13px;
border: 1px solid rgba(255, 255, 255, 0.25);
border-radius: 4px;
background: rgba(0, 0, 0, 0.3);
color: inherit;
cursor: pointer;
}
.numbtn--selected {
border: 2px solid #7ec8ff;
font-weight: 700;
}
.summonlist {
list-style: none;
margin: 0;
padding: 0;
max-height: 40vh;
overflow-y: auto;
}
.summonlist__item {
display: flex;
align-items: center;
gap: 10px;
width: 100%;
padding: 6px 8px;
border: none;
border-radius: 4px;
background: none;
color: inherit;
font-size: 13px;
text-align: left;
cursor: pointer;
}
.summonlist__item:hover {
background: rgba(255, 255, 255, 0.1);
}
.summonlist__art {
position: relative;
width: 32px;
height: 32px;
flex: 0 0 auto;
}
.summonlist__art img {
width: 100%;
height: 100%;
object-fit: contain;
}
.summonlist__nr {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
font-size: 14px;
font-weight: 700;
color: #fff;
text-shadow: 0 0 3px #000, 0 1px 2px #000;
}
.summonlist__name {
min-width: 0;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
</style>
|