fix(web client): reactive exit sign
This commit is contained in:
parent
7395d140cc
commit
a82169fbe5
1 changed files with 83 additions and 70 deletions
|
|
@ -312,13 +312,8 @@ pub fn Board(
|
||||||
exit_field_test = |f| matches!(f, 1..=6);
|
exit_field_test = |f| matches!(f, 1..=6);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show a clickable exit sign outside the board when bearing off is possible.
|
// Sequences clone for the reactive exit button (show/hide + class + click).
|
||||||
let has_exit_move = valid_sequences
|
let seqs_exit = valid_sequences.clone();
|
||||||
.iter()
|
|
||||||
.any(|(m1, m2)| m1.get_to() == 0 || m2.get_to() == 0);
|
|
||||||
let show_exit_btn = all_in_exit && is_move_stage && has_exit_move;
|
|
||||||
let seqs_exit_cls = valid_sequences.clone();
|
|
||||||
let seqs_exit_click = valid_sequences.clone();
|
|
||||||
|
|
||||||
// `valid_sequences` is cloned per field (the Vec is small; Send-safe unlike Rc).
|
// `valid_sequences` is cloned per field (the Vec is small; Send-safe unlike Rc).
|
||||||
let fields_from = |nums: &[u8], is_top_row: bool| -> Vec<AnyView> {
|
let fields_from = |nums: &[u8], is_top_row: bool| -> Vec<AnyView> {
|
||||||
|
|
@ -624,7 +619,24 @@ pub fn Board(
|
||||||
</svg>
|
</svg>
|
||||||
// Exit sign: circle+arrow outside the board, next to the last exit field.
|
// Exit sign: circle+arrow outside the board, next to the last exit field.
|
||||||
// White exits to the right (top-right quarter); Black exits to the left (top-left).
|
// White exits to the right (top-right quarter); Black exits to the left (top-left).
|
||||||
{show_exit_btn.then(|| {
|
{move || {
|
||||||
|
// Recompute on every staged_moves change: the exit button must appear
|
||||||
|
// even when the initial board has a checker outside the exit zone,
|
||||||
|
// because the first move can bring all checkers in (e.g. 15→21, 19→exit).
|
||||||
|
let staged = staged_moves.get();
|
||||||
|
let show = is_move_stage && match staged.len() {
|
||||||
|
0 => seqs_exit.iter().any(|(m1, m2)| m1.get_to() == 0 || m2.get_to() == 0),
|
||||||
|
1 => {
|
||||||
|
let (f0, t0) = staged[0];
|
||||||
|
seqs_exit.iter()
|
||||||
|
.filter(|(m1, _)| m1.get_from() as u8 == f0 && m1.get_to() as u8 == t0)
|
||||||
|
.any(|(_, m2)| m2.get_to() == 0)
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
show.then(|| {
|
||||||
|
let seqs_exit_cls = seqs_exit.clone();
|
||||||
|
let seqs_exit_click = seqs_exit.clone();
|
||||||
let (pos_style, line_x1, line_x2, head_pts): (&str, &str, &str, &str) =
|
let (pos_style, line_x1, line_x2, head_pts): (&str, &str, &str, &str) =
|
||||||
if is_white {
|
if is_white {
|
||||||
(
|
(
|
||||||
|
|
@ -687,7 +699,8 @@ pub fn Board(
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
.into_any()
|
.into_any()
|
||||||
})}
|
})
|
||||||
|
}}
|
||||||
</div>
|
</div>
|
||||||
<div class="zone-labels-row">
|
<div class="zone-labels-row">
|
||||||
<div class="zone-label zone-label-quarter">{label_bl}</div>
|
<div class="zone-label zone-label-quarter">{label_bl}</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue