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
|
<!--
Add Note Row (the reference `NoteRowAddMenu`, Phase 3 form): a colour
picker, free text, and an optional link to a figure. Sending
`addNoteRow` appends the row (beneath its linked figure, if any).
-->
<script lang="ts">
import type { GameSession } from '$lib/state/session';
import { isCharacter, isMonster } from '$lib/protocol/types';
import { t } from '$lib/i18n';
import Menu from '../Menu.svelte';
let {
session,
open = $bindable(true)
}: {
session: GameSession;
open?: boolean;
} = $props();
const gameState = session.state;
const player = session.player;
const COLORS = [
0xffb58900,
0xff1565c0,
0xff2e7d32,
0xffc2185b,
0xffffb300,
0xff5e35b1
];
let color = $state(COLORS[0]);
let text = $state('');
let linkedId = $state('');
$effect(() => {
if (!open) return;
color = COLORS[0];
text = '';
linkedId = '';
});
const figures = $derived.by(() =>
($gameState?.currentList ?? [])
.filter((i) => isCharacter(i) || isMonster(i))
.map((i) => ({
id: i.id,
name: isCharacter(i) ? i.characterState.display : i.id
}))
);
function colorCss(c: number): string {
return `#${c.toString(16).padStart(8, '0').slice(2)}`;
}
function add() {
if (!$player) return;
const id =
typeof crypto !== 'undefined' && 'randomUUID' in crypto
? crypto.randomUUID()
: `note-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
session.command('addNoteRow', {
noteRow: {
id,
text: text.trim(),
color,
linkedId,
standeeNr: 0
}
});
open = false;
}
</script>
<Menu open={open} title={t('menuAddNoteRow')}>
<div style="display: flex; gap: 6px; padding: 8px 4px">
{#each COLORS as c (c)}
<button
aria-label="note colour"
style="width: 32px; height: 32px; border-radius: 6px; background: {colorCss(c)}; outline: {c === color ? '3px solid #fff' : 'none'}"
onclick={() => (color = c)}
></button>
{/each}
</div>
<input class="search" placeholder={t('noteRowHint')} bind:value={text} />
<div class="statrow" style="align-items: center">
<span class="statrow__label" style="font-size: 13px">{t('noteRowWholeGroup')}</span>
<select
class="search"
style="margin: 0; width: auto"
value={linkedId}
onchange={(e) => (linkedId = e.currentTarget.value)}
>
<option value="">{t('noteRowAll')}</option>
{#each figures as f (f.id)}
<option value={f.id}>{f.name}</option>
{/each}
</select>
</div>
<div style="display: flex; justify-content: flex-end; padding: 8px 4px">
<button
class="stepbtn"
style="border-radius: 6px"
disabled={!$player || text.trim() === ''}
onclick={add}
>
{t('noteRowAddFromMenu')}
</button>
</div>
</Menu>
|