refactor(core): derive draw_mode/is_won/move_count/is_auto_completable from session
Remove the draw_mode, move_count, is_won, and is_auto_completable fields from GameState; they are now &self methods deriving from the underlying card_game session (draw_mode from session config, move_count from history length, is_won/is_auto_completable from check_win/check_auto_complete). Tests previously fabricated these via direct field writes, which is no longer possible. Add gated test-support overrides on TestPileState (won/auto_completable/move_count) plus setters set_test_won, set_test_auto_completable, set_test_move_count, and set_test_draw_mode (re-deals the seed). All compiled out in production builds. Fix the field->method ripple across solitaire_data, solitaire_wasm, and solitaire_engine. Add a test-support dev-dependency to solitaire_data for the won-game storage test. cargo test --workspace and cargo clippy --workspace -- -D warnings pass. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1154,7 +1154,7 @@ fn handle_hint_button(
|
||||
return;
|
||||
}
|
||||
let Some(ref g) = game else { return };
|
||||
if g.0.is_won {
|
||||
if g.0.is_won() {
|
||||
info_toast.write(InfoToastEvent(HINT_WON_MSG.to_string()));
|
||||
return;
|
||||
}
|
||||
@@ -2106,10 +2106,10 @@ fn update_won_previously(
|
||||
let Ok(mut text) = q.single_mut() else {
|
||||
return;
|
||||
};
|
||||
let won_before = !game.0.is_won
|
||||
let won_before = !game.0.is_won()
|
||||
&& history.as_ref().is_some_and(|h| {
|
||||
h.0.replays.iter().any(|r| {
|
||||
r.seed == game.0.seed && r.draw_mode == game.0.draw_mode && r.mode == game.0.mode
|
||||
r.seed == game.0.seed && r.draw_mode == game.0.draw_mode() && r.mode == game.0.mode
|
||||
})
|
||||
});
|
||||
let next = if won_before {
|
||||
@@ -2279,11 +2279,11 @@ fn update_hud(
|
||||
};
|
||||
}
|
||||
if let Ok(mut t) = moves_q.single_mut() {
|
||||
**t = format!("Moves: {}", g.move_count);
|
||||
**t = format!("Moves: {}", g.move_count());
|
||||
}
|
||||
if let Ok(mut t) = mode_q.single_mut() {
|
||||
**t = match g.mode {
|
||||
GameMode::Classic => match g.draw_mode {
|
||||
GameMode::Classic => match g.draw_mode() {
|
||||
DrawMode::DrawOne => String::new(),
|
||||
DrawMode::DrawThree => "Draw 3".to_string(),
|
||||
},
|
||||
@@ -2296,7 +2296,7 @@ fn update_hud(
|
||||
|
||||
// --- Daily challenge constraint (with time-low colour warning) ---
|
||||
if let Ok((mut t, mut color)) = challenge_q.single_mut() {
|
||||
if g.is_won {
|
||||
if g.is_won() {
|
||||
**t = String::new();
|
||||
} else if let Some(dc) = daily.as_deref() {
|
||||
**t = challenge_hud_text(dc);
|
||||
@@ -2334,7 +2334,7 @@ fn update_hud(
|
||||
|
||||
// --- Draw-cycle indicator (Draw-Three mode only) ---
|
||||
if let Ok(mut t) = draw_cycle_q.single_mut() {
|
||||
**t = if g.is_won || g.draw_mode != DrawMode::DrawThree {
|
||||
**t = if g.is_won() || g.draw_mode() != DrawMode::DrawThree {
|
||||
// Hide when not in Draw-Three or after the game is won.
|
||||
String::new()
|
||||
} else {
|
||||
@@ -2774,7 +2774,7 @@ mod tests {
|
||||
app.world_mut()
|
||||
.resource_mut::<GameStateResource>()
|
||||
.0
|
||||
.move_count = 42;
|
||||
.set_test_move_count(42);
|
||||
app.update();
|
||||
assert_eq!(read_hud_text::<HudMoves>(&mut app), "Moves: 42");
|
||||
}
|
||||
@@ -2962,7 +2962,7 @@ mod tests {
|
||||
max_time_secs: Some(300),
|
||||
});
|
||||
// Mark the game as won — HudChallenge should be empty.
|
||||
app.world_mut().resource_mut::<GameStateResource>().0.is_won = true;
|
||||
app.world_mut().resource_mut::<GameStateResource>().0.set_test_won(true);
|
||||
app.update();
|
||||
assert_eq!(read_hud_text::<HudChallenge>(&mut app), "");
|
||||
}
|
||||
@@ -3012,7 +3012,7 @@ mod tests {
|
||||
app.world_mut()
|
||||
.resource_mut::<GameStateResource>()
|
||||
.0
|
||||
.move_count += 1;
|
||||
.set_test_move_count(1);
|
||||
app.update();
|
||||
assert_eq!(read_hud_text::<HudAutoComplete>(&mut app), "AUTO");
|
||||
}
|
||||
@@ -3024,7 +3024,7 @@ mod tests {
|
||||
app.world_mut()
|
||||
.resource_mut::<GameStateResource>()
|
||||
.0
|
||||
.move_count += 1;
|
||||
.set_test_move_count(1);
|
||||
app.update();
|
||||
assert_eq!(read_hud_text::<HudAutoComplete>(&mut app), "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user