From 77233b24c01732cb7dd3cad01ef596fc5cedabb0 Mon Sep 17 00:00:00 2001 From: Henri Bourcereau Date: Sun, 5 Apr 2026 11:13:48 +0200 Subject: [PATCH] feat(client_web): auto-roll dice on player turn --- client_web/src/components/game_screen.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/client_web/src/components/game_screen.rs b/client_web/src/components/game_screen.rs index 8a43399..686a9d1 100644 --- a/client_web/src/components/game_screen.rs +++ b/client_web/src/components/game_screen.rs @@ -103,16 +103,26 @@ pub fn GameScreen(state: GameUiState) -> impl IntoView { } }); + // ── Auto-roll effect ───────────────────────────────────────────────────── + // GameScreen is fully re-mounted on every ViewState update (state is a + // plain prop, not a signal), so this effect fires exactly once per + // RollDice phase entry and will not double-send. + let show_roll = is_my_turn && vs.turn_stage == SerTurnStage::RollDice; + if show_roll { + let cmd_tx_auto = cmd_tx.clone(); + Effect::new(move |_| { + cmd_tx_auto.unbounded_send(NetCommand::Action(PlayerAction::Roll)).ok(); + }); + } + let dice = vs.dice; let show_dice = dice != (0, 0); // ── Button senders ───────────────────────────────────────────────────────── - let cmd_tx_roll = cmd_tx.clone(); let cmd_tx_go = cmd_tx.clone(); let cmd_tx_quit = cmd_tx.clone(); let cmd_tx_end_quit = cmd_tx.clone(); let cmd_tx_end_replay = cmd_tx.clone(); - let show_roll = is_my_turn && vs.turn_stage == SerTurnStage::RollDice; let show_hold_go = is_my_turn && vs.turn_stage == SerTurnStage::HoldOrGoChoice; // ── Valid move sequences for this turn ───────────────────────────────────── @@ -232,11 +242,6 @@ pub fn GameScreen(state: GameUiState) -> impl IntoView { // Action buttons
- {show_roll.then(|| view! { - - })} {show_hold_go.then(|| view! {