summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/DrawButton.svelte
blob: 40d9245937d79cc34d43f814724e56f108e82ae0 (plain)
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
<!--
	The bottom-bar draw button (the reference `DrawButtonWidget`): "Draw"
	while choosing initiative, "Next Round" during turns, with the round
	counter beneath.

	Draw gating: only players act (the server rejects spectators). A player
	may tap draw at any point during chooseInitiative — initiative values are
	masked per connection (PLAN.md 3.4), so the client cannot know whether a
	teammate has entered theirs; the server rejects an early draw with the
	"all players must set initiative" error, which surfaces as a toast.
-->
<script lang="ts">
	import type { GameSession } from '$lib/state/session';
	import { t } from '$lib/i18n';

	let { session }: { session: GameSession } = $props();

	const gameState = session.state;
	const player = session.player;
	const status = session.status;

	const roundState = $derived($gameState?.roundState ?? 0);
	const label = $derived(roundState === 0 ? t('draw') : t('nextRound'));
	const locked = $derived(
		!$player || $gameState === null || ($status !== 'open' && $status !== 'reconnecting')
	);

	function onDraw() {
		if (locked) return;
		if (roundState === 0) session.command('draw', {});
		else session.command('nextRound', {});
	}
</script>

<button
	class="drawbtn"
	class:drawbtn--locked={locked}
	disabled={locked}
	onclick={onDraw}
>
	{label}
	{#if $gameState}
		<span class="drawbtn__round">
			{t('web:round')} {$gameState.round}/{$gameState.totalRounds}
		</span>
	{/if}
</button>