fix(replay): store the deal via upstream card_game serializers (schema v4)
Test / test (pull_request) Successful in 36m34s
Test / test (pull_request) Successful in 36m34s
Replays previously persisted only seed + moves and re-dealt the board
from the seed at playback time, so any change to the seed->deal mapping
(RNG bumps, upstream upgrades) silently invalidated every existing
replay. Schema v4 instead embeds a SessionRecording - the upstream
card_game Session serde ({config, initial_state, instructions}) - so
playback rebuilds the exact recorded board; seed/draw_mode/mode remain
caption metadata only.
- core: SessionRecording newtype delegating to Session<Klondike> serde;
GameState::recording() / from_recording(); from_instructions_unchecked
fixture helper; serde_json added to dev-deps (tests only)
- data: Replay v4 (recording replaces moves); v1-v3 files rejected by
the existing version gate
- engine: win-recording and sync upload freeze game.recording();
playback rebuilds from the recording; Playing carries the extracted
move list (+ Box<Replay> for clippy large_enum_variant)
- wasm: replay_export() builds the full v4 upload payload so JS never
hand-assembles it (the old game.js path hardcoded schema_version: 2
and corrupted u64 seeds via Math.round); ReplayPlayer::from_json
enforces schema_version == 4 with a descriptive error
- web: game.js/play.html use replay_export; replay.js surfaces player
construction errors in the caption instead of dying silently
- server: mode validation accepts data-carrying GameMode variants
(Difficulty uploads previously 400'd against the String field)
Both replays on prod are May-era v1 rows with empty move lists - every
shared replay was already unplayable; the viewer now says why.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1343,7 +1343,9 @@ mod tests {
|
||||
|
||||
use crate::replay_playback::ReplayPlaybackState;
|
||||
use chrono::NaiveDate;
|
||||
use solitaire_core::{DrawStockConfig, KlondikeInstruction, game_state::GameMode};
|
||||
use solitaire_core::{
|
||||
DrawStockConfig, KlondikeInstruction, SessionRecording, game_state::GameMode,
|
||||
};
|
||||
use solitaire_data::Replay;
|
||||
|
||||
/// Headless app variant that injects a default `ReplayPlaybackState`
|
||||
@@ -1364,7 +1366,11 @@ mod tests {
|
||||
10,
|
||||
100,
|
||||
NaiveDate::from_ymd_opt(2026, 5, 5).expect("valid date"),
|
||||
vec![KlondikeInstruction::RotateStock],
|
||||
SessionRecording::from_instructions_unchecked(
|
||||
1,
|
||||
DrawStockConfig::DrawOne,
|
||||
[KlondikeInstruction::RotateStock],
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1408,12 +1414,8 @@ mod tests {
|
||||
|
||||
// Frame 1: enter Playing. The observer's first sample sees
|
||||
// `last_was_playing = false` and `now_playing = true`.
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() = ReplayPlaybackState::Playing {
|
||||
replay: dummy_replay(),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.0,
|
||||
paused: false,
|
||||
};
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() =
|
||||
ReplayPlaybackState::playing(dummy_replay(), 0, 0.0, false);
|
||||
app.update();
|
||||
assert!(
|
||||
!cinephile_unlocked(&app),
|
||||
@@ -1442,12 +1444,8 @@ mod tests {
|
||||
fn cinephile_does_not_unlock_on_stop_button_abort() {
|
||||
let mut app = cinephile_app();
|
||||
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() = ReplayPlaybackState::Playing {
|
||||
replay: dummy_replay(),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.0,
|
||||
paused: false,
|
||||
};
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() =
|
||||
ReplayPlaybackState::playing(dummy_replay(), 0, 0.0, false);
|
||||
app.update();
|
||||
|
||||
// Direct Playing → Inactive — the path the Stop button takes via
|
||||
@@ -1473,12 +1471,8 @@ mod tests {
|
||||
let mut app = cinephile_app();
|
||||
|
||||
// First completion cycle to unlock.
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() = ReplayPlaybackState::Playing {
|
||||
replay: dummy_replay(),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.0,
|
||||
paused: false,
|
||||
};
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() =
|
||||
ReplayPlaybackState::playing(dummy_replay(), 0, 0.0, false);
|
||||
app.update();
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() = ReplayPlaybackState::Completed;
|
||||
app.update();
|
||||
@@ -1496,12 +1490,8 @@ mod tests {
|
||||
// Second cycle: Inactive → Playing → Completed once more.
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() = ReplayPlaybackState::Inactive;
|
||||
app.update();
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() = ReplayPlaybackState::Playing {
|
||||
replay: dummy_replay(),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.0,
|
||||
paused: false,
|
||||
};
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() =
|
||||
ReplayPlaybackState::playing(dummy_replay(), 0, 0.0, false);
|
||||
app.update();
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() = ReplayPlaybackState::Completed;
|
||||
app.update();
|
||||
@@ -1520,12 +1510,8 @@ mod tests {
|
||||
fn cinephile_fires_once_across_completed_linger() {
|
||||
let mut app = cinephile_app();
|
||||
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() = ReplayPlaybackState::Playing {
|
||||
replay: dummy_replay(),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.0,
|
||||
paused: false,
|
||||
};
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() =
|
||||
ReplayPlaybackState::playing(dummy_replay(), 0, 0.0, false);
|
||||
app.update();
|
||||
*app.world_mut().resource_mut::<ReplayPlaybackState>() = ReplayPlaybackState::Completed;
|
||||
app.update();
|
||||
|
||||
@@ -1062,11 +1062,16 @@ pub fn record_replay_on_win(
|
||||
if recording.moves.is_empty() {
|
||||
continue;
|
||||
}
|
||||
// The session itself is the authoritative recording: its history
|
||||
// holds the dealt board plus the forward instruction list (undos
|
||||
// already popped), and it serialises via the upstream card_game
|
||||
// serializers so playback never re-deals from the seed.
|
||||
let session_recording = game.0.recording();
|
||||
// Recording freezes on win, so the move that triggered the
|
||||
// win condition is the last one in the list. Storing the
|
||||
// index explicitly lets the playback UI read the WIN MOVE
|
||||
// position directly instead of re-deriving it on every render.
|
||||
let win_move_index = recording.moves.len().checked_sub(1);
|
||||
let win_move_index = session_recording.len().checked_sub(1);
|
||||
let replay = Replay::new(
|
||||
game.0.seed,
|
||||
game.0.draw_mode(),
|
||||
@@ -1074,7 +1079,7 @@ pub fn record_replay_on_win(
|
||||
ev.time_seconds,
|
||||
ev.score,
|
||||
Utc::now().date_naive(),
|
||||
recording.moves.clone(),
|
||||
session_recording,
|
||||
)
|
||||
.with_win_move_index(win_move_index);
|
||||
let Some(p) = path.as_ref().and_then(|r| r.0.as_deref()) else {
|
||||
|
||||
@@ -853,17 +853,15 @@ fn replay_recording_freezes_into_replay_on_game_won() {
|
||||
let mut app = test_app(7654);
|
||||
app.insert_resource(ReplayPath(Some(path.clone())));
|
||||
|
||||
// Push two recorded instructions manually so we can verify they
|
||||
// survive the freeze/save round-trip without having to drive a
|
||||
// real win. Both are `RotateStock` — the only instruction
|
||||
// constructible without the runtime-only `klondike` pile-stack
|
||||
// types (which the engine intentionally does not depend on); the
|
||||
// round-trip shape is identical for any instruction variant.
|
||||
{
|
||||
let mut recording = app.world_mut().resource_mut::<RecordingReplay>();
|
||||
recording.moves.push(KlondikeInstruction::RotateStock);
|
||||
recording.moves.push(KlondikeInstruction::RotateStock);
|
||||
}
|
||||
// Drive two real draws so the *session* history (the source the
|
||||
// freeze now serialises from, via `GameState::recording()`) holds
|
||||
// two instructions. `RotateStock` is the only instruction the
|
||||
// engine can drive without the runtime-only `klondike` pile-stack
|
||||
// types; the round-trip shape is identical for any variant.
|
||||
app.world_mut().write_message(DrawRequestEvent);
|
||||
app.update();
|
||||
app.world_mut().write_message(DrawRequestEvent);
|
||||
app.update();
|
||||
|
||||
// Fire the win event the engine emits when the last foundation
|
||||
// completes — `record_replay_on_win` listens for it.
|
||||
@@ -895,9 +893,15 @@ fn replay_recording_freezes_into_replay_on_game_won() {
|
||||
loaded.time_seconds, 250,
|
||||
"time_seconds must come from the win event"
|
||||
);
|
||||
assert_eq!(loaded.moves.len(), 2, "every recorded move must round-trip");
|
||||
assert!(matches!(loaded.moves[0], KlondikeInstruction::RotateStock));
|
||||
assert!(matches!(loaded.moves[1], KlondikeInstruction::RotateStock));
|
||||
let instructions = loaded.recording.instructions();
|
||||
assert_eq!(instructions.len(), 2, "every recorded move must round-trip");
|
||||
assert!(matches!(instructions[0], KlondikeInstruction::RotateStock));
|
||||
assert!(matches!(instructions[1], KlondikeInstruction::RotateStock));
|
||||
assert_eq!(
|
||||
loaded.win_move_index,
|
||||
Some(1),
|
||||
"win move index must point at the last recorded instruction",
|
||||
);
|
||||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
let _ = std::fs::remove_file(&path);
|
||||
|
||||
@@ -122,12 +122,8 @@ pub(crate) fn format_move_body(instruction: &KlondikeInstruction) -> String {
|
||||
/// `▌ MOVE LOG · COMPLETE` in `Completed`.
|
||||
pub(crate) fn format_move_log_header(state: &ReplayPlaybackState) -> String {
|
||||
match state {
|
||||
ReplayPlaybackState::Playing { replay, cursor, .. } => {
|
||||
format!(
|
||||
"\u{258C} MOVE LOG \u{00B7} {}/{}",
|
||||
cursor,
|
||||
replay.moves.len()
|
||||
)
|
||||
ReplayPlaybackState::Playing { moves, cursor, .. } => {
|
||||
format!("\u{258C} MOVE LOG \u{00B7} {}/{}", cursor, moves.len())
|
||||
}
|
||||
ReplayPlaybackState::Completed => "\u{258C} MOVE LOG \u{00B7} COMPLETE".to_string(),
|
||||
ReplayPlaybackState::Inactive => String::new(),
|
||||
@@ -135,7 +131,7 @@ pub(crate) fn format_move_log_header(state: &ReplayPlaybackState) -> String {
|
||||
}
|
||||
|
||||
/// Pure helper — formats the kth-most-recently-applied move's row
|
||||
/// text. `k = 1` is the active row (`replay.moves[cursor - 1]`,
|
||||
/// text. `k = 1` is the active row (`moves[cursor - 1]`,
|
||||
/// displayed as `"{cursor} │ {body}"`). `k = 2` is the row above
|
||||
/// that (`moves[cursor - 2]` displayed as `"{cursor - 1} │ {body}"`),
|
||||
/// and so on.
|
||||
@@ -147,14 +143,14 @@ pub(crate) fn format_move_log_header(state: &ReplayPlaybackState) -> String {
|
||||
/// for k=1 and k=2 only, k=3 returns empty).
|
||||
/// - The move list is shorter than expected (defensive guard).
|
||||
pub(crate) fn format_kth_recent_row(state: &ReplayPlaybackState, k: usize) -> String {
|
||||
let ReplayPlaybackState::Playing { replay, cursor, .. } = state else {
|
||||
let ReplayPlaybackState::Playing { moves, cursor, .. } = state else {
|
||||
return String::new();
|
||||
};
|
||||
if k == 0 || k > *cursor {
|
||||
return String::new();
|
||||
}
|
||||
let zero_idx = *cursor - k;
|
||||
let Some(m) = replay.moves.get(zero_idx) else {
|
||||
let Some(m) = moves.get(zero_idx) else {
|
||||
return String::new();
|
||||
};
|
||||
let display_idx = *cursor - k + 1;
|
||||
@@ -162,7 +158,7 @@ pub(crate) fn format_kth_recent_row(state: &ReplayPlaybackState, k: usize) -> St
|
||||
}
|
||||
|
||||
/// Pure helper — formats the kth-NEXT move's row text. `k = 1`
|
||||
/// is the move that will apply next (`replay.moves[cursor]`,
|
||||
/// is the move that will apply next (`moves[cursor]`,
|
||||
/// displayed as `cursor + 1`); `k = 2` is the move after that,
|
||||
/// and so on.
|
||||
///
|
||||
@@ -174,14 +170,14 @@ pub(crate) fn format_kth_recent_row(state: &ReplayPlaybackState, k: usize) -> St
|
||||
/// replay — late in the move list, the trailing next rows
|
||||
/// stay empty).
|
||||
pub(crate) fn format_kth_next_row(state: &ReplayPlaybackState, k: usize) -> String {
|
||||
let ReplayPlaybackState::Playing { replay, cursor, .. } = state else {
|
||||
let ReplayPlaybackState::Playing { moves, cursor, .. } = state else {
|
||||
return String::new();
|
||||
};
|
||||
if k == 0 {
|
||||
return String::new();
|
||||
}
|
||||
let zero_idx = *cursor + k - 1;
|
||||
let Some(m) = replay.moves.get(zero_idx) else {
|
||||
let Some(m) = moves.get(zero_idx) else {
|
||||
return String::new();
|
||||
};
|
||||
let display_idx = *cursor + k;
|
||||
|
||||
@@ -383,7 +383,7 @@ pub struct ReplayOverlayMoveLogPrevRow {
|
||||
/// Marker on a "next move" row below the active row. `offset`
|
||||
/// is the 1-based distance forward from the active row:
|
||||
/// `offset = 1` is the move that will apply next
|
||||
/// (`replay.moves[cursor]`, displayed as `cursor + 1`),
|
||||
/// (`moves[cursor]`, displayed as `cursor + 1`),
|
||||
/// `offset = 2` is the one after that, and so on. Up to
|
||||
/// [`MOVE_LOG_NEXT_ROWS`] rows render below the active row.
|
||||
///
|
||||
@@ -1258,11 +1258,11 @@ fn keybind_footer_hint_text() -> &'static str {
|
||||
/// `win_move_index >= total` (defensive — shouldn't happen) doesn't
|
||||
/// position the marker outside the track.
|
||||
fn win_move_marker_pct(state: &ReplayPlaybackState) -> Option<f32> {
|
||||
let ReplayPlaybackState::Playing { replay, .. } = state else {
|
||||
let ReplayPlaybackState::Playing { replay, moves, .. } = state else {
|
||||
return None;
|
||||
};
|
||||
let idx = replay.win_move_index?;
|
||||
let total = replay.moves.len();
|
||||
let total = moves.len();
|
||||
if total == 0 {
|
||||
return None;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::*;
|
||||
use chrono::NaiveDate;
|
||||
use solitaire_core::{DrawStockConfig, game_state::GameMode};
|
||||
use solitaire_core::{Foundation, KlondikeInstruction, KlondikePile, Tableau};
|
||||
use solitaire_core::{Foundation, KlondikeInstruction, KlondikePile, SessionRecording, Tableau};
|
||||
use solitaire_core::{Rank, Suit};
|
||||
use solitaire_data::Replay;
|
||||
|
||||
@@ -17,9 +17,11 @@ fn synthetic_replay(move_count: usize) -> Replay {
|
||||
120,
|
||||
1_000,
|
||||
NaiveDate::from_ymd_opt(2026, 5, 2).expect("valid date"),
|
||||
(0..move_count)
|
||||
.map(|_| KlondikeInstruction::RotateStock)
|
||||
.collect(),
|
||||
SessionRecording::from_instructions_unchecked(
|
||||
42,
|
||||
DrawStockConfig::DrawOne,
|
||||
(0..move_count).map(|_| KlondikeInstruction::RotateStock),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -93,12 +95,7 @@ fn overlay_spawns_when_playback_starts() {
|
||||
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
|
||||
@@ -117,12 +114,7 @@ fn overlay_progress_text_reflects_cursor() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 5,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 5, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
|
||||
@@ -138,12 +130,7 @@ fn overlay_stop_button_click_clears_playback() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(overlay_root_count(&mut app), 1);
|
||||
@@ -195,12 +182,7 @@ fn floating_chip_spawns_and_despawns_with_overlay() {
|
||||
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(5),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(5), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -232,12 +214,7 @@ fn overlay_despawns_when_playback_returns_to_inactive() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(3),
|
||||
cursor: 1,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(3), 1, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(overlay_root_count(&mut app), 1);
|
||||
@@ -260,12 +237,7 @@ fn overlay_text_changes_on_completed() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(7),
|
||||
cursor: 7,
|
||||
secs_to_next: 0.0,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(7), 7, 0.0, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(banner_text(&mut app), "\u{258C} replay");
|
||||
@@ -314,30 +286,30 @@ fn scrub_pct_covers_state_corners() {
|
||||
assert_eq!(scrub_pct(&ReplayPlaybackState::Inactive), 0.0);
|
||||
assert_eq!(scrub_pct(&ReplayPlaybackState::Completed), 100.0);
|
||||
assert_eq!(
|
||||
scrub_pct(&ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
}),
|
||||
scrub_pct(&ReplayPlaybackState::playing(
|
||||
synthetic_replay(10),
|
||||
0,
|
||||
0.5,
|
||||
false,
|
||||
)),
|
||||
0.0,
|
||||
);
|
||||
assert_eq!(
|
||||
scrub_pct(&ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 5,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
}),
|
||||
scrub_pct(&ReplayPlaybackState::playing(
|
||||
synthetic_replay(10),
|
||||
5,
|
||||
0.5,
|
||||
false,
|
||||
)),
|
||||
50.0,
|
||||
);
|
||||
assert_eq!(
|
||||
scrub_pct(&ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 10,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
}),
|
||||
scrub_pct(&ReplayPlaybackState::playing(
|
||||
synthetic_replay(10),
|
||||
10,
|
||||
0.5,
|
||||
false,
|
||||
)),
|
||||
100.0,
|
||||
);
|
||||
}
|
||||
@@ -367,12 +339,12 @@ fn format_game_caption_covers_state_corners() {
|
||||
// Mar = 31, Apr = 30, May 2 = 122). Synthetic_replay always
|
||||
// uses this date so the assertion is stable.
|
||||
assert_eq!(
|
||||
format_game_caption(&ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 5,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
}),
|
||||
format_game_caption(&ReplayPlaybackState::playing(
|
||||
synthetic_replay(10),
|
||||
5,
|
||||
0.5,
|
||||
false,
|
||||
)),
|
||||
Some("GAME #2026-122".to_string()),
|
||||
);
|
||||
|
||||
@@ -381,12 +353,7 @@ fn format_game_caption_covers_state_corners() {
|
||||
let mut early_january = synthetic_replay(10);
|
||||
early_january.recorded_at = NaiveDate::from_ymd_opt(2026, 1, 5).expect("valid date");
|
||||
assert_eq!(
|
||||
format_game_caption(&ReplayPlaybackState::Playing {
|
||||
replay: early_january,
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
}),
|
||||
format_game_caption(&ReplayPlaybackState::playing(early_january, 0, 0.5, false,)),
|
||||
Some("GAME #2026-005".to_string()),
|
||||
);
|
||||
}
|
||||
@@ -399,12 +366,7 @@ fn overlay_game_caption_shows_replay_date() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(game_caption_text(&mut app), "GAME #2026-122");
|
||||
@@ -431,12 +393,7 @@ fn overlay_scrub_fill_tracks_cursor() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(8),
|
||||
cursor: 2,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(8), 2, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -447,12 +404,7 @@ fn overlay_scrub_fill_tracks_cursor() {
|
||||
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(8),
|
||||
cursor: 6,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(8), 6, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -497,12 +449,7 @@ fn win_move_marker_pct_is_none_for_completed() {
|
||||
fn win_move_marker_pct_is_none_when_replay_lacks_field() {
|
||||
// Synthetic replay constructor leaves win_move_index as None
|
||||
// (legacy / pre-`ab857bb` path).
|
||||
let state = ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
};
|
||||
let state = ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false);
|
||||
assert_eq!(win_move_marker_pct(&state), None);
|
||||
}
|
||||
|
||||
@@ -511,12 +458,12 @@ fn win_move_marker_pct_is_some_at_correct_position() {
|
||||
// 10 moves, win at index 9 → marker sits at 90 % of the track.
|
||||
// Matches the recording semantic: cursor reaches the marker
|
||||
// exactly when the about-to-apply move IS the win move.
|
||||
let state = ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10).with_win_move_index(Some(9)),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
};
|
||||
let state = ReplayPlaybackState::playing(
|
||||
synthetic_replay(10).with_win_move_index(Some(9)),
|
||||
0,
|
||||
0.5,
|
||||
false,
|
||||
);
|
||||
assert_eq!(win_move_marker_pct(&state), Some(90.0));
|
||||
}
|
||||
|
||||
@@ -524,12 +471,12 @@ fn win_move_marker_pct_is_some_at_correct_position() {
|
||||
fn win_move_marker_pct_clamps_to_track_bounds() {
|
||||
// Defensive: if a malformed replay carried `win_move_index >=
|
||||
// total`, the marker must still sit on the track, not past it.
|
||||
let state = ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(5).with_win_move_index(Some(99)),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
};
|
||||
let state = ReplayPlaybackState::playing(
|
||||
synthetic_replay(5).with_win_move_index(Some(99)),
|
||||
0,
|
||||
0.5,
|
||||
false,
|
||||
);
|
||||
assert_eq!(win_move_marker_pct(&state), Some(100.0));
|
||||
}
|
||||
|
||||
@@ -538,12 +485,12 @@ fn marker_spawned_when_replay_has_win_move_index() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(8).with_win_move_index(Some(7)),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(
|
||||
synthetic_replay(8).with_win_move_index(Some(7)),
|
||||
0,
|
||||
0.5,
|
||||
false,
|
||||
),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -559,12 +506,7 @@ fn marker_not_spawned_when_replay_lacks_win_move_index() {
|
||||
// Default constructor → win_move_index: None (legacy replay).
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(8),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(8), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -579,12 +521,12 @@ fn marker_despawns_when_replay_state_returns_to_inactive() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(8).with_win_move_index(Some(7)),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(
|
||||
synthetic_replay(8).with_win_move_index(Some(7)),
|
||||
0,
|
||||
0.5,
|
||||
false,
|
||||
),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(win_marker_count(&mut app), 1);
|
||||
@@ -608,12 +550,12 @@ fn win_move_marker_carries_hc_background_marker() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(8).with_win_move_index(Some(7)),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(
|
||||
synthetic_replay(8).with_win_move_index(Some(7)),
|
||||
0,
|
||||
0.5,
|
||||
false,
|
||||
),
|
||||
);
|
||||
app.update();
|
||||
|
||||
@@ -669,12 +611,7 @@ fn scrub_notches_spawn_with_overlay() {
|
||||
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -693,12 +630,7 @@ fn scrub_notches_carry_high_contrast_background_marker() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
|
||||
@@ -723,12 +655,7 @@ fn scrub_track_carries_high_contrast_background_marker() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
|
||||
@@ -759,12 +686,7 @@ fn scrub_notches_despawn_with_overlay() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(scrub_notch_count(&mut app), 5);
|
||||
@@ -821,12 +743,7 @@ fn scrub_notch_labels_spawn_with_overlay() {
|
||||
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -844,12 +761,7 @@ fn scrub_notch_labels_carry_helper_strings() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
|
||||
@@ -870,12 +782,7 @@ fn scrub_notch_labels_despawn_with_overlay() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(scrub_notch_label_count(&mut app), 5);
|
||||
@@ -947,12 +854,7 @@ fn keybind_footer_spawns_with_overlay() {
|
||||
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -970,12 +872,7 @@ fn keybind_footer_paints_helper_strings() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
|
||||
@@ -999,12 +896,7 @@ fn keybind_footer_carries_high_contrast_border_marker() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
|
||||
@@ -1025,12 +917,7 @@ fn keybind_footer_despawns_with_overlay() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(keybind_footer_count(&mut app), 1);
|
||||
@@ -1054,12 +941,7 @@ fn scrub_notches_spawn_even_without_win_marker() {
|
||||
// Default constructor → win_move_index: None.
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(8),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(8), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -1144,12 +1026,7 @@ fn format_move_body_handles_stock_cycle() {
|
||||
/// `Inactive` → empty.
|
||||
#[test]
|
||||
fn format_move_log_header_covers_state_branches() {
|
||||
let playing = ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 3,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
};
|
||||
let playing = ReplayPlaybackState::playing(synthetic_replay(10), 3, 0.5, false);
|
||||
assert_eq!(
|
||||
format_move_log_header(&playing),
|
||||
"\u{258C} MOVE LOG \u{00B7} 3/10"
|
||||
@@ -1167,24 +1044,14 @@ fn format_move_log_header_covers_state_branches() {
|
||||
/// `replay.moves[N - 1]` and the row reads `"N | ..."`.
|
||||
#[test]
|
||||
fn format_active_move_row_handles_cursor_zero_and_positive() {
|
||||
let cursor_zero = ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
};
|
||||
let cursor_zero = ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false);
|
||||
assert_eq!(
|
||||
format_active_move_row(&cursor_zero),
|
||||
"",
|
||||
"cursor=0 means no move applied yet; row stays empty",
|
||||
);
|
||||
|
||||
let cursor_three = ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 3,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
};
|
||||
let cursor_three = ReplayPlaybackState::playing(synthetic_replay(10), 3, 0.5, false);
|
||||
// synthetic_replay produces all StockClicks, so the body
|
||||
// is "stock cycle". The displayed index is 3 (cursor),
|
||||
// matching the most-recently-applied move at moves[2].
|
||||
@@ -1208,12 +1075,7 @@ fn move_log_panel_spawns_with_overlay() {
|
||||
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -1232,12 +1094,7 @@ fn move_log_panel_header_paints_helper_string() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(8),
|
||||
cursor: 2,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(8), 2, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -1254,12 +1111,7 @@ fn move_log_active_row_repaints_on_cursor_advance() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -1271,12 +1123,7 @@ fn move_log_active_row_repaints_on_cursor_advance() {
|
||||
// Advance cursor to 2 (most-recently-applied move is moves[1]).
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 2,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 2, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -1292,12 +1139,7 @@ fn move_log_active_row_repaints_on_cursor_advance() {
|
||||
/// early in a replay don't paint stale text.
|
||||
#[test]
|
||||
fn format_kth_recent_row_handles_in_range_and_out_of_range() {
|
||||
let state_at_three = ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 3,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
};
|
||||
let state_at_three = ReplayPlaybackState::playing(synthetic_replay(10), 3, 0.5, false);
|
||||
// k=1 → active (most recent applied). cursor=3 → display=3.
|
||||
assert_eq!(
|
||||
format_kth_recent_row(&state_at_three, 1),
|
||||
@@ -1348,12 +1190,7 @@ fn move_log_prev_rows_spawn_with_panel() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 3,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 3, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -1371,12 +1208,7 @@ fn move_log_prev_rows_paint_helper_strings_at_spawn() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 5,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 5, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
|
||||
@@ -1401,12 +1233,7 @@ fn move_log_prev_rows_repaint_on_cursor_advance() {
|
||||
// Start at cursor=2: offset 1 → k=2 → display=1, offset 2 → k=3 → empty (k > cursor).
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 2,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 2, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -1422,12 +1249,7 @@ fn move_log_prev_rows_repaint_on_cursor_advance() {
|
||||
// Advance to cursor=5 — both offsets now have history.
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 5,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 5, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -1465,12 +1287,7 @@ fn move_log_next_row_text_at_offset(app: &mut App, offset: u8) -> String {
|
||||
/// alongside in-range correctness.
|
||||
#[test]
|
||||
fn format_kth_next_row_handles_in_range_and_out_of_range() {
|
||||
let state_at_three = ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 3,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
};
|
||||
let state_at_three = ReplayPlaybackState::playing(synthetic_replay(10), 3, 0.5, false);
|
||||
// k=1 → moves[3], display=4
|
||||
assert_eq!(
|
||||
format_kth_next_row(&state_at_three, 1),
|
||||
@@ -1498,12 +1315,7 @@ fn move_log_next_rows_spawn_with_panel() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 3,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 3, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -1520,12 +1332,7 @@ fn move_log_next_rows_paint_helper_strings_at_spawn() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 5,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 5, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
|
||||
@@ -1549,12 +1356,7 @@ fn move_log_next_rows_underfill_at_replay_end() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 9,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 9, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -1578,12 +1380,7 @@ fn active_row_wrapper_carries_accent_primary_background() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 3,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 3, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
|
||||
@@ -1621,12 +1418,7 @@ fn active_row_text_uses_high_contrast_color_for_highlight() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 3,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 3, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
|
||||
@@ -1647,24 +1439,14 @@ fn active_row_text_uses_high_contrast_color_for_highlight() {
|
||||
/// dropping it has to also update this test.
|
||||
#[test]
|
||||
fn active_row_format_includes_focus_prefix() {
|
||||
let state = ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 5,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
};
|
||||
let state = ReplayPlaybackState::playing(synthetic_replay(10), 5, 0.5, false);
|
||||
let row = format_active_move_row(&state);
|
||||
assert!(
|
||||
row.starts_with('\u{25B6}'),
|
||||
"active-row format must start with ▶ focus marker; got {row:?}",
|
||||
);
|
||||
// Cursor=0 still returns empty, never just the prefix.
|
||||
let cursor_zero = ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
};
|
||||
let cursor_zero = ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false);
|
||||
assert_eq!(
|
||||
format_active_move_row(&cursor_zero),
|
||||
"",
|
||||
@@ -1679,12 +1461,7 @@ fn move_log_panel_despawns_with_overlay() {
|
||||
let mut app = headless_app();
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(10),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(10), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(move_log_panel_count(&mut app), 1);
|
||||
@@ -1728,21 +1505,11 @@ fn unique_button<M: Component>(app: &mut App) -> Entity {
|
||||
}
|
||||
|
||||
fn pressed_paused_state(replay_len: usize, cursor: usize) -> ReplayPlaybackState {
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(replay_len),
|
||||
cursor,
|
||||
secs_to_next: 0.5,
|
||||
paused: true,
|
||||
}
|
||||
ReplayPlaybackState::playing(synthetic_replay(replay_len), cursor, 0.5, true)
|
||||
}
|
||||
|
||||
fn running_state(replay_len: usize, cursor: usize) -> ReplayPlaybackState {
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(replay_len),
|
||||
cursor,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
}
|
||||
ReplayPlaybackState::playing(synthetic_replay(replay_len), cursor, 0.5, false)
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -2191,12 +1958,7 @@ fn dim_layer_spawns_and_despawns_with_overlay() {
|
||||
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(5),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(5), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -2255,12 +2017,7 @@ fn mini_tableau_panel_spawns_and_despawns_with_overlay() {
|
||||
|
||||
set_state(
|
||||
&mut app,
|
||||
ReplayPlaybackState::Playing {
|
||||
replay: synthetic_replay(5),
|
||||
cursor: 0,
|
||||
secs_to_next: 0.5,
|
||||
paused: false,
|
||||
},
|
||||
ReplayPlaybackState::playing(synthetic_replay(5), 0, 0.5, false),
|
||||
);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
|
||||
@@ -83,11 +83,11 @@ pub(crate) fn update_floating_progress_chip(
|
||||
// any). `cursor` is the index of the *next* move to apply, so
|
||||
// the most-recently-applied move sits at `cursor - 1`.
|
||||
let dest_pile = match state.as_ref() {
|
||||
ReplayPlaybackState::Playing { replay, cursor, .. } if *cursor > 0 => {
|
||||
ReplayPlaybackState::Playing { moves, cursor, .. } if *cursor > 0 => {
|
||||
// The destination pile is recoverable directly from the
|
||||
// instruction — no live state needed. `RotateStock` has no
|
||||
// destination (the chip hides over the stock pile).
|
||||
match &replay.moves[cursor - 1] {
|
||||
match &moves[cursor - 1] {
|
||||
KlondikeInstruction::DstFoundation(dst) => {
|
||||
Some(KlondikePile::Foundation(dst.foundation))
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
//! In-engine replay playback core.
|
||||
//!
|
||||
//! When the player clicks "Watch replay" on the Stats overlay, the live
|
||||
//! game state is reset to the deal seeded from the replay's `seed` /
|
||||
//! `mode` / `draw_mode`, and the engine ticks through `replay.moves` at a
|
||||
//! steady cadence — firing the canonical [`MoveRequestEvent`] /
|
||||
//! [`DrawRequestEvent`] for each one. The existing animation pipeline
|
||||
//! plays back identically to a live game.
|
||||
//! game state is reset to the recorded deal — rebuilt directly from
|
||||
//! `replay.recording` via `GameState::from_recording`, never by
|
||||
//! re-dealing the seed — and the engine ticks through the recording's
|
||||
//! instruction list at a steady cadence, firing the canonical
|
||||
//! [`MoveRequestEvent`] / [`DrawRequestEvent`] for each one. The
|
||||
//! existing animation pipeline plays back identically to a live game.
|
||||
//!
|
||||
//! ## Public surface
|
||||
//!
|
||||
@@ -95,7 +96,7 @@ pub const REPLAY_COMPLETION_LINGER_SECS: f32 = 5.0;
|
||||
/// 3. The tick system [`tick_replay_playback`] advances `cursor` once
|
||||
/// per [`REPLAY_MOVE_INTERVAL_SECS`] and fires the canonical event
|
||||
/// for each [`KlondikeInstruction`].
|
||||
/// 4. When `cursor == replay.moves.len()`, the state transitions to
|
||||
/// 4. When `cursor == moves.len()`, the state transitions to
|
||||
/// [`Completed`](Self::Completed). It lingers for
|
||||
/// [`REPLAY_COMPLETION_LINGER_SECS`] (driven by
|
||||
/// [`auto_clear_completed_replay`]) before returning to
|
||||
@@ -109,14 +110,20 @@ pub enum ReplayPlaybackState {
|
||||
#[default]
|
||||
Inactive,
|
||||
/// A replay is currently being played back. The overlay reads
|
||||
/// `replay.moves.len()` for the denominator of the progress
|
||||
/// `moves.len()` for the denominator of the progress
|
||||
/// indicator and `cursor` for the numerator.
|
||||
Playing {
|
||||
/// The replay being played back. Owned so the state is the
|
||||
/// only place playback metadata lives — no separate resource
|
||||
/// needed.
|
||||
replay: Replay,
|
||||
/// Index of the next move to apply, in `[0, replay.moves.len()]`.
|
||||
/// needed. Boxed: the v4 recording embeds the dealt board and
|
||||
/// would otherwise dwarf the other variants
|
||||
/// (`clippy::large_enum_variant`).
|
||||
replay: Box<Replay>,
|
||||
/// Instruction list extracted once from `replay.recording` at
|
||||
/// [`start_replay_playback`] time, so the per-frame tick indexes
|
||||
/// a plain slice instead of re-walking the recording.
|
||||
moves: Vec<KlondikeInstruction>,
|
||||
/// Index of the next move to apply, in `[0, moves.len()]`.
|
||||
cursor: usize,
|
||||
/// Seconds remaining until the next move is dispatched.
|
||||
secs_to_next: f32,
|
||||
@@ -138,6 +145,19 @@ pub enum ReplayPlaybackState {
|
||||
}
|
||||
|
||||
impl ReplayPlaybackState {
|
||||
/// Construct a [`Self::Playing`] state, extracting the instruction
|
||||
/// list from `replay.recording` once up front.
|
||||
pub fn playing(replay: Replay, cursor: usize, secs_to_next: f32, paused: bool) -> Self {
|
||||
let moves = replay.recording.instructions();
|
||||
Self::Playing {
|
||||
replay: Box::new(replay),
|
||||
moves,
|
||||
cursor,
|
||||
secs_to_next,
|
||||
paused,
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns `true` when a replay is currently being played back.
|
||||
pub fn is_playing(&self) -> bool {
|
||||
matches!(self, Self::Playing { .. })
|
||||
@@ -156,7 +176,7 @@ impl ReplayPlaybackState {
|
||||
/// the total is no longer available in `Completed`.
|
||||
pub fn progress(&self) -> Option<(usize, usize)> {
|
||||
match self {
|
||||
Self::Playing { replay, cursor, .. } => Some((*cursor, replay.moves.len())),
|
||||
Self::Playing { moves, cursor, .. } => Some((*cursor, moves.len())),
|
||||
Self::Inactive | Self::Completed => None,
|
||||
}
|
||||
}
|
||||
@@ -191,7 +211,11 @@ pub fn start_replay_playback(
|
||||
) {
|
||||
use solitaire_core::game_state::GameState;
|
||||
|
||||
let fresh = GameState::new_with_mode(replay.seed, replay.draw_mode, replay.mode);
|
||||
// The recording carries the dealt board and the session config
|
||||
// (including draw mode), so the fresh game is bit-identical to the
|
||||
// recorded deal regardless of how the current build maps seeds to
|
||||
// deals — `replay.seed` is presentation metadata only.
|
||||
let (fresh, moves) = GameState::from_recording(&replay.recording, replay.seed, replay.mode);
|
||||
commands.insert_resource(GameStateResource(fresh));
|
||||
|
||||
// Initial `secs_to_next` uses the constant rather than reading
|
||||
@@ -201,7 +225,8 @@ pub fn start_replay_playback(
|
||||
// unusually short setting; subsequent ticks read the live setting
|
||||
// every frame via [`tick_replay_playback`].
|
||||
**state = ReplayPlaybackState::Playing {
|
||||
replay,
|
||||
replay: Box::new(replay),
|
||||
moves,
|
||||
cursor: 0,
|
||||
secs_to_next: REPLAY_MOVE_INTERVAL_SECS,
|
||||
paused: false,
|
||||
@@ -256,7 +281,7 @@ pub fn step_replay_playback(
|
||||
draws_writer: &mut MessageWriter<DrawRequestEvent>,
|
||||
) -> bool {
|
||||
let ReplayPlaybackState::Playing {
|
||||
replay,
|
||||
moves,
|
||||
cursor,
|
||||
paused: true,
|
||||
..
|
||||
@@ -264,10 +289,10 @@ pub fn step_replay_playback(
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
if *cursor >= replay.moves.len() {
|
||||
if *cursor >= moves.len() {
|
||||
return false;
|
||||
}
|
||||
let instruction = replay.moves[*cursor];
|
||||
let instruction = moves[*cursor];
|
||||
dispatch_instruction(instruction, *cursor, game, moves_writer, draws_writer);
|
||||
*cursor += 1;
|
||||
true
|
||||
@@ -362,7 +387,7 @@ pub fn step_backwards_replay_playback(
|
||||
/// Drains `secs_to_next` by `time.delta_secs()`. When the countdown
|
||||
/// expires, fires the canonical event for the move at `cursor`,
|
||||
/// increments `cursor`, and resets `secs_to_next`. When `cursor`
|
||||
/// reaches `replay.moves.len()`, transitions to
|
||||
/// reaches `moves.len()`, transitions to
|
||||
/// [`ReplayPlaybackState::Completed`].
|
||||
///
|
||||
/// The advance loop is a `while`, not an `if`, so coarse time steps
|
||||
@@ -384,10 +409,11 @@ fn tick_replay_playback(
|
||||
let mut transition_to_completed = false;
|
||||
|
||||
if let ReplayPlaybackState::Playing {
|
||||
replay,
|
||||
moves,
|
||||
cursor,
|
||||
secs_to_next,
|
||||
paused,
|
||||
..
|
||||
} = state.as_mut()
|
||||
{
|
||||
// While paused, the cursor and the timer freeze together —
|
||||
@@ -397,8 +423,8 @@ fn tick_replay_playback(
|
||||
// path.
|
||||
if !*paused {
|
||||
*secs_to_next -= dt;
|
||||
while *secs_to_next <= 0.0 && *cursor < replay.moves.len() {
|
||||
let instruction = replay.moves[*cursor];
|
||||
while *secs_to_next <= 0.0 && *cursor < moves.len() {
|
||||
let instruction = moves[*cursor];
|
||||
dispatch_instruction(
|
||||
instruction,
|
||||
*cursor,
|
||||
@@ -410,7 +436,7 @@ fn tick_replay_playback(
|
||||
*secs_to_next += interval;
|
||||
}
|
||||
|
||||
if *cursor >= replay.moves.len() {
|
||||
if *cursor >= moves.len() {
|
||||
transition_to_completed = true;
|
||||
}
|
||||
}
|
||||
@@ -562,8 +588,7 @@ mod tests {
|
||||
use crate::game_plugin::GamePlugin;
|
||||
use bevy::time::TimeUpdateStrategy;
|
||||
use chrono::NaiveDate;
|
||||
use solitaire_core::KlondikeInstruction;
|
||||
use solitaire_core::{DrawStockConfig, game_state::GameMode};
|
||||
use solitaire_core::{DrawStockConfig, SessionRecording, game_state::GameMode};
|
||||
use std::time::Duration;
|
||||
|
||||
/// Builds a headless `App` with `MinimalPlugins`, `GamePlugin`, and
|
||||
@@ -612,11 +637,11 @@ mod tests {
|
||||
60,
|
||||
500,
|
||||
NaiveDate::from_ymd_opt(2026, 5, 5).expect("valid date"),
|
||||
vec![
|
||||
KlondikeInstruction::RotateStock,
|
||||
KlondikeInstruction::RotateStock,
|
||||
KlondikeInstruction::RotateStock,
|
||||
],
|
||||
SessionRecording::from_instructions_unchecked(
|
||||
12345,
|
||||
DrawStockConfig::DrawOne,
|
||||
[KlondikeInstruction::RotateStock; 3],
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -673,11 +698,14 @@ mod tests {
|
||||
let state = app.world().resource::<ReplayPlaybackState>();
|
||||
match state {
|
||||
ReplayPlaybackState::Playing {
|
||||
cursor, replay: r, ..
|
||||
cursor,
|
||||
replay: r,
|
||||
moves,
|
||||
..
|
||||
} => {
|
||||
assert_eq!(*cursor, 0);
|
||||
assert_eq!(r.seed, replay.seed);
|
||||
assert_eq!(r.moves.len(), 3);
|
||||
assert_eq!(moves.len(), 3);
|
||||
}
|
||||
other => panic!("expected Playing, got {other:?}"),
|
||||
}
|
||||
@@ -778,7 +806,11 @@ mod tests {
|
||||
10,
|
||||
100,
|
||||
NaiveDate::from_ymd_opt(2026, 5, 5).expect("valid date"),
|
||||
vec![KlondikeInstruction::RotateStock],
|
||||
SessionRecording::from_instructions_unchecked(
|
||||
42,
|
||||
DrawStockConfig::DrawOne,
|
||||
[KlondikeInstruction::RotateStock],
|
||||
),
|
||||
);
|
||||
start_playback(&mut app, one_move);
|
||||
app.update();
|
||||
@@ -887,7 +919,11 @@ mod tests {
|
||||
10,
|
||||
100,
|
||||
NaiveDate::from_ymd_opt(2026, 5, 5).expect("valid date"),
|
||||
vec![KlondikeInstruction::RotateStock; 10],
|
||||
SessionRecording::from_instructions_unchecked(
|
||||
7,
|
||||
DrawStockConfig::DrawOne,
|
||||
[KlondikeInstruction::RotateStock; 10],
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -1939,7 +1939,11 @@ mod tests {
|
||||
time_seconds,
|
||||
0,
|
||||
date,
|
||||
vec![],
|
||||
solitaire_core::SessionRecording::from_instructions_unchecked(
|
||||
1,
|
||||
solitaire_core::DrawStockConfig::DrawOne,
|
||||
[],
|
||||
),
|
||||
);
|
||||
r.share_url = share_url;
|
||||
r
|
||||
|
||||
@@ -335,7 +335,11 @@ fn push_replay_on_win(
|
||||
ev.time_seconds,
|
||||
ev.score,
|
||||
Utc::now().date_naive(),
|
||||
recording.moves.clone(),
|
||||
// The live session is the authoritative recording; it
|
||||
// serialises via the upstream card_game serializers so web
|
||||
// playback rebuilds the exact deal instead of re-dealing
|
||||
// the seed.
|
||||
game.0.recording(),
|
||||
);
|
||||
let provider = provider.0.clone();
|
||||
let rt = rt.0.clone();
|
||||
@@ -621,7 +625,11 @@ mod tests {
|
||||
60,
|
||||
500,
|
||||
chrono::NaiveDate::from_ymd_opt(2026, 5, 6).expect("valid date"),
|
||||
vec![],
|
||||
solitaire_core::SessionRecording::from_instructions_unchecked(
|
||||
7,
|
||||
DrawStockConfig::DrawOne,
|
||||
[],
|
||||
),
|
||||
);
|
||||
let history = ReplayHistory {
|
||||
schema_version: solitaire_data::REPLAY_HISTORY_SCHEMA_VERSION,
|
||||
|
||||
Reference in New Issue
Block a user