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:
@@ -534,7 +534,7 @@ fn update_stats_on_win(
|
||||
let prev_streak = stats.0.win_streak_current;
|
||||
stats
|
||||
.0
|
||||
.update_on_win(ev.score, ev.time_seconds, &game.0.draw_mode);
|
||||
.update_on_win(ev.score, ev.time_seconds, &game.0.draw_mode());
|
||||
// Per-mode best score / fastest win — additive on top of the
|
||||
// lifetime totals tracked by `update_on_win`. TimeAttack is a
|
||||
// no-op inside the helper because it has its own session-level
|
||||
@@ -588,7 +588,7 @@ fn update_stats_on_new_game(
|
||||
mut toast: MessageWriter<InfoToastEvent>,
|
||||
) {
|
||||
for _ in events.read() {
|
||||
if game.0.move_count > 0 && !game.0.is_won {
|
||||
if game.0.move_count() > 0 && !game.0.is_won() {
|
||||
let streak = stats.0.win_streak_current;
|
||||
stats.0.record_abandoned();
|
||||
persist(&path, &stats.0, "abandoned game");
|
||||
@@ -614,7 +614,7 @@ fn handle_forfeit(
|
||||
mut auto_complete: Option<ResMut<AutoCompleteState>>,
|
||||
) {
|
||||
for _ in events.read() {
|
||||
if game.0.move_count > 0 && !game.0.is_won {
|
||||
if game.0.move_count() > 0 && !game.0.is_won() {
|
||||
let streak = stats.0.win_streak_current;
|
||||
stats.0.record_abandoned();
|
||||
persist(&path, &stats.0, "forfeit");
|
||||
@@ -1327,7 +1327,7 @@ mod tests {
|
||||
app.world_mut()
|
||||
.resource_mut::<crate::resources::GameStateResource>()
|
||||
.0
|
||||
.draw_mode = solitaire_core::DrawMode::DrawThree;
|
||||
.set_test_draw_mode(solitaire_core::DrawMode::DrawThree);
|
||||
|
||||
app.world_mut().write_message(GameWonEvent {
|
||||
score: 500,
|
||||
@@ -1373,7 +1373,7 @@ mod tests {
|
||||
app.world_mut()
|
||||
.resource_mut::<crate::resources::GameStateResource>()
|
||||
.0
|
||||
.move_count = 3;
|
||||
.set_test_move_count(3);
|
||||
|
||||
app.world_mut().write_message(NewGameRequestEvent {
|
||||
seed: Some(999),
|
||||
@@ -1699,7 +1699,7 @@ mod tests {
|
||||
app.world_mut()
|
||||
.resource_mut::<crate::resources::GameStateResource>()
|
||||
.0
|
||||
.move_count = 1;
|
||||
.set_test_move_count(1);
|
||||
|
||||
app.world_mut().write_message(ForfeitEvent);
|
||||
app.update();
|
||||
@@ -1725,7 +1725,7 @@ mod tests {
|
||||
app.world_mut()
|
||||
.resource_mut::<crate::resources::GameStateResource>()
|
||||
.0
|
||||
.move_count = 1;
|
||||
.set_test_move_count(1);
|
||||
|
||||
app.world_mut().write_message(ForfeitEvent);
|
||||
app.update();
|
||||
|
||||
Reference in New Issue
Block a user