diff --git a/solitaire_engine/src/game_plugin.rs b/solitaire_engine/src/game_plugin.rs index c9c9d1c..9eda9ce 100644 --- a/solitaire_engine/src/game_plugin.rs +++ b/solitaire_engine/src/game_plugin.rs @@ -48,10 +48,46 @@ impl Plugin for GamePlugin { ) .chain() .in_set(GameMutation), - ); + ) + .add_systems(Update, tick_elapsed_time); } } +/// Pure, testable helper. Updates `elapsed_seconds` and drains the +/// fractional accumulator into whole-second ticks. No-op when `is_won`. +pub fn advance_elapsed( + elapsed_seconds: &mut u64, + accumulator: &mut f32, + delta_secs: f32, + is_won: bool, +) { + if is_won { + return; + } + *accumulator += delta_secs; + while *accumulator >= 1.0 { + *elapsed_seconds = elapsed_seconds.saturating_add(1); + *accumulator -= 1.0; + } +} + +/// Increment `GameState.elapsed_seconds` once per real-world second while +/// the game is in progress (not won). Stops counting on win so the final +/// time reflects how long the player took to solve the deal. +fn tick_elapsed_time( + time: Res