summaryrefslogtreecommitdiff
path: root/web/src/lib/ui/DrawButton.svelte
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/lib/ui/DrawButton.svelte')
-rw-r--r--web/src/lib/ui/DrawButton.svelte47
1 files changed, 47 insertions, 0 deletions
diff --git a/web/src/lib/ui/DrawButton.svelte b/web/src/lib/ui/DrawButton.svelte
new file mode 100644
index 0000000..40d9245
--- /dev/null
+++ b/web/src/lib/ui/DrawButton.svelte
@@ -0,0 +1,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>