fix(client_web): black moves indexes display

This commit is contained in:
Henri Bourcereau 2026-03-28 16:37:05 +01:00
parent 31ee129262
commit bef0ecbd8c
2 changed files with 56 additions and 39 deletions

View file

@ -55,42 +55,51 @@ fn jan_label(jan: &Jan) -> &'static str {
fn format_move_pair(m1: CheckerMove, m2: CheckerMove) -> String { fn format_move_pair(m1: CheckerMove, m2: CheckerMove) -> String {
let fmt = |m: CheckerMove| -> String { let fmt = |m: CheckerMove| -> String {
let (f, t) = (m.get_from(), m.get_to()); let (f, t) = (m.get_from(), m.get_to());
if f == 0 && t == 0 { "".to_string() } if f == 0 && t == 0 {
else if t == 0 { format!("{f}") } // exit "".to_string()
else { format!("{f}{t}") } } 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<Option<usize>>) -> impl IntoView { fn jan_row(idx: usize, entry: JanEntry, expanded: RwSignal<Option<usize>>) -> 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 label = jan_label(&entry.jan);
let double_tag = if entry.is_double { "double" } else { "simple" }; let double_tag = if entry.is_double { "double" } else { "simple" };
let ways_tag = format!("×{}", entry.ways); 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(); let moves = entry.moves.clone();
view! { view! {
<div> <div>
<div <div
class=row_class class=row_class
class:jan-expandable=can_expand
on:click=move |_| { on:click=move |_| {
if can_expand {
expanded.update(|s| { expanded.update(|s| {
*s = if *s == Some(idx) { None } else { Some(idx) }; *s = if *s == Some(idx) { None } else { Some(idx) };
}); });
} }
}
> >
<span class="jan-label">{label}</span> <span class="jan-label">{label}</span>
<span class="jan-tag">{double_tag}</span> <span class="jan-tag">{double_tag}</span>
<span class="jan-tag">{ways_tag}</span> <span class="jan-tag">{ways_tag}</span>
<span class="jan-pts">{pts_str}</span> <span class="jan-pts">{pts_str}</span>
</div> </div>
{can_expand.then(|| { {
let move_lines: Vec<_> = moves.iter() let move_lines: Vec<_> = moves.iter()
.map(|&(m1, m2)| { .map(|&(m1, m2)| {
let text = format_move_pair(m1, m2); let text = format_move_pair(m1, m2);
@ -102,7 +111,7 @@ fn jan_row(idx: usize, entry: JanEntry, expanded: RwSignal<Option<usize>>) -> im
{move_lines} {move_lines}
</div> </div>
} }
})} }
</div> </div>
} }
} }
@ -113,7 +122,10 @@ pub fn GameScreen(state: GameUiState) -> impl IntoView {
let player_id = state.player_id; let player_id = state.player_id;
let is_my_turn = vs.active_mp_player == Some(player_id); let is_my_turn = vs.active_mp_player == Some(player_id);
let is_move_stage = is_my_turn 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 ────────────────────────────────────────────────────── // ── Staged move state ──────────────────────────────────────────────────────
let selected_origin: RwSignal<Option<u8>> = RwSignal::new(None); let selected_origin: RwSignal<Option<u8>> = RwSignal::new(None);

View file

@ -987,7 +987,12 @@ impl GameState {
player.color, self.board, dice, player.dice_roll_count player.color, self.board, dice, player.dice_roll_count
); );
let points_rules = PointsRules::new(&player.color, &self.board, *dice); 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 /// Determines if someone has won the game