From bef0ecbd8ced899566cba3cdfef4d2fdc58c6540 Mon Sep 17 00:00:00 2001 From: Henri Bourcereau Date: Sat, 28 Mar 2026 16:37:05 +0100 Subject: [PATCH] fix(client_web): black moves indexes display --- client_web/src/components/game_screen.rs | 88 ++++++++++++++---------- store/src/game.rs | 7 +- 2 files changed, 56 insertions(+), 39 deletions(-) diff --git a/client_web/src/components/game_screen.rs b/client_web/src/components/game_screen.rs index 6b81b70..236490f 100644 --- a/client_web/src/components/game_screen.rs +++ b/client_web/src/components/game_screen.rs @@ -36,53 +36,62 @@ fn matched_dice_used(staged: &[(u8, u8)], dice: (u8, u8)) -> (bool, bool) { fn jan_label(jan: &Jan) -> &'static str { match jan { - Jan::FilledQuarter => "Remplissage", - Jan::TrueHitSmallJan => "Battage à vrai (petit jan)", - Jan::TrueHitBigJan => "Battage à vrai (grand jan)", - Jan::TrueHitOpponentCorner => "Battage coin adverse", - Jan::FirstPlayerToExit => "Premier sorti", - Jan::SixTables => "Six tables", - Jan::TwoTables => "Deux tables", - Jan::Mezeas => "Mezeas", - Jan::FalseHitSmallJan => "Battage à faux (petit jan)", - Jan::FalseHitBigJan => "Battage à faux (grand jan)", - Jan::ContreTwoTables => "Contre deux tables", - Jan::ContreMezeas => "Contre mezeas", - Jan::HelplessMan => "Dame impuissante", + Jan::FilledQuarter => "Remplissage", + Jan::TrueHitSmallJan => "Battage à vrai (petit jan)", + Jan::TrueHitBigJan => "Battage à vrai (grand jan)", + Jan::TrueHitOpponentCorner => "Battage coin adverse", + Jan::FirstPlayerToExit => "Premier sorti", + Jan::SixTables => "Six tables", + Jan::TwoTables => "Deux tables", + Jan::Mezeas => "Mezeas", + Jan::FalseHitSmallJan => "Battage à faux (petit jan)", + Jan::FalseHitBigJan => "Battage à faux (grand jan)", + Jan::ContreTwoTables => "Contre deux tables", + Jan::ContreMezeas => "Contre mezeas", + Jan::HelplessMan => "Dame impuissante", } } fn format_move_pair(m1: CheckerMove, m2: CheckerMove) -> String { let fmt = |m: CheckerMove| -> String { let (f, t) = (m.get_from(), m.get_to()); - if f == 0 && t == 0 { "—".to_string() } - else if t == 0 { format!("{f}↑") } // exit - else { format!("{f}→{t}") } + if f == 0 && t == 0 { + "—".to_string() + } else if t == 0 { + // exit + format!("{f}↑") + } else { + format!("{f}→{t}") + } }; - format!("{} + {}", fmt(m1), fmt(m2)) + format!("{} & {}", fmt(m1), fmt(m2)) } fn jan_row(idx: usize, entry: JanEntry, expanded: RwSignal>) -> impl IntoView { - let row_class = if entry.total >= 0 { "jan-row jan-positive" } else { "jan-row jan-negative" }; + let row_class = if entry.total >= 0 { + "jan-row jan-expandable jan-positive" + } else { + "jan-row jan-expandable jan-negative" + }; let label = jan_label(&entry.jan); let double_tag = if entry.is_double { "double" } else { "simple" }; let ways_tag = format!("×{}", entry.ways); - let pts_str = if entry.total >= 0 { format!("+{}", entry.total) } else { format!("{}", entry.total) }; + let pts_str = if entry.total >= 0 { + format!("+{}", entry.total) + } else { + format!("{}", entry.total) + }; - let can_expand = entry.ways > 1; let moves = entry.moves.clone(); view! {
{label} @@ -90,7 +99,7 @@ fn jan_row(idx: usize, entry: JanEntry, expanded: RwSignal>) -> im {ways_tag} {pts_str}
- {can_expand.then(|| { + { let move_lines: Vec<_> = moves.iter() .map(|&(m1, m2)| { let text = format_move_pair(m1, m2); @@ -102,7 +111,7 @@ fn jan_row(idx: usize, entry: JanEntry, expanded: RwSignal>) -> im {move_lines}
} - })} + } } } @@ -113,7 +122,10 @@ pub fn GameScreen(state: GameUiState) -> impl IntoView { let player_id = state.player_id; let is_my_turn = vs.active_mp_player == Some(player_id); let is_move_stage = is_my_turn - && matches!(vs.turn_stage, SerTurnStage::Move | SerTurnStage::HoldOrGoChoice); + && matches!( + vs.turn_stage, + SerTurnStage::Move | SerTurnStage::HoldOrGoChoice + ); // ── Staged move state ────────────────────────────────────────────────────── let selected_origin: RwSignal> = RwSignal::new(None); @@ -141,14 +153,14 @@ pub fn GameScreen(state: GameUiState) -> impl IntoView { // ── Status text ──────────────────────────────────────────────────────────── let status = match &vs.stage { - SerStage::Ended => "Game over".to_string(), + SerStage::Ended => "Game over".to_string(), SerStage::PreGame => "Waiting for opponent…".to_string(), - SerStage::InGame => match (is_my_turn, &vs.turn_stage) { - (true, SerTurnStage::RollDice) => "Your turn — roll the dice".to_string(), + SerStage::InGame => match (is_my_turn, &vs.turn_stage) { + (true, SerTurnStage::RollDice) => "Your turn — roll the dice".to_string(), (true, SerTurnStage::HoldOrGoChoice) => "Hold or Go?".to_string(), - (true, SerTurnStage::Move) => "Select move 1 of 2".to_string(), - (true, _) => "Your turn".to_string(), - (false, _) => "Opponent's turn".to_string(), + (true, SerTurnStage::Move) => "Select move 1 of 2".to_string(), + (true, _) => "Your turn".to_string(), + (false, _) => "Opponent's turn".to_string(), }, }; @@ -157,10 +169,10 @@ pub fn GameScreen(state: GameUiState) -> impl IntoView { // ── Button senders ───────────────────────────────────────────────────────── let cmd_tx_roll = cmd_tx.clone(); - let cmd_tx_go = cmd_tx.clone(); + let cmd_tx_go = cmd_tx.clone(); let cmd_tx_quit = 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; + let show_roll = is_my_turn && vs.turn_stage == SerTurnStage::RollDice; + let show_hold_go = is_my_turn && vs.turn_stage == SerTurnStage::HoldOrGoChoice; view! {
diff --git a/store/src/game.rs b/store/src/game.rs index e4e938c..57f69dd 100644 --- a/store/src/game.rs +++ b/store/src/game.rs @@ -987,7 +987,12 @@ impl GameState { player.color, self.board, dice, player.dice_roll_count ); let points_rules = PointsRules::new(&player.color, &self.board, *dice); - Ok(points_rules.get_result_jans(player.dice_roll_count)) + let (jans, points) = points_rules.get_result_jans(player.dice_roll_count); + Ok(if player.color == Color::White { + (jans, points) + } else { + (jans.mirror(), points) + }) } /// Determines if someone has won the game