refactor: remove leftover redundancies after card_game migration
Post-migration audit found the card_game/klondike migration essentially complete; these are the four small redundancies that remained: - core: delete dead GameState::compute_time_bonus (zero callers; engine uses the klondike_adapter free fn directly) - data: drop dead public re-exports load_latest_replay_from / save_latest_replay_to (no callers outside replay.rs); keep latest_replay_path (engine legacy migration still uses it) - data+engine: lift win-XP scoring into a shared XpBreakdown so the win-summary modal breakdown and xp_for_win share one source of truth instead of duplicating the speed/no-undo constants - engine: replace feedback_anim_plugin's private foundation_from_slot copy with the canonical klondike_adapter::foundation_from_slot cargo test --workspace + clippy -D warnings green. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -25,12 +25,34 @@ pub fn daily_seed_for(date: NaiveDate) -> u64 {
|
||||
y * 10_000 + m * 100 + d
|
||||
}
|
||||
|
||||
/// XP awarded for winning a game.
|
||||
/// Component breakdown of the XP awarded for a win.
|
||||
///
|
||||
/// This is the single source of truth for win-XP scoring: [`xp_for_win`] sums
|
||||
/// it for the total, and UI that displays the individual lines (the win-summary
|
||||
/// modal) reads the parts from here so the breakdown can never drift from the
|
||||
/// total.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct XpBreakdown {
|
||||
/// Flat base XP granted for any win.
|
||||
pub base: u64,
|
||||
/// Scaled fast-win bonus (10..=50 for sub-2-minute wins, else 0).
|
||||
pub speed_bonus: u64,
|
||||
/// Bonus for winning without using undo (25, else 0).
|
||||
pub no_undo_bonus: u64,
|
||||
}
|
||||
|
||||
impl XpBreakdown {
|
||||
/// Total XP awarded: `base + speed_bonus + no_undo_bonus`.
|
||||
pub fn total(self) -> u64 {
|
||||
self.base + self.speed_bonus + self.no_undo_bonus
|
||||
}
|
||||
}
|
||||
|
||||
/// Component breakdown of the XP awarded for a win.
|
||||
///
|
||||
/// Base 50 + scaled fast-win bonus (10..=50 for sub-2-minute wins) + 25 if
|
||||
/// the player did not use undo.
|
||||
pub fn xp_for_win(time_seconds: u64, used_undo: bool) -> u64 {
|
||||
let base: u64 = 50;
|
||||
pub fn xp_breakdown(time_seconds: u64, used_undo: bool) -> XpBreakdown {
|
||||
let speed_bonus: u64 = if time_seconds >= 120 {
|
||||
0
|
||||
} else {
|
||||
@@ -39,8 +61,16 @@ pub fn xp_for_win(time_seconds: u64, used_undo: bool) -> u64 {
|
||||
let scaled = 50_u64.saturating_sub(time_seconds.saturating_mul(40) / 120);
|
||||
scaled.max(10)
|
||||
};
|
||||
let no_undo_bonus: u64 = if used_undo { 0 } else { 25 };
|
||||
base + speed_bonus + no_undo_bonus
|
||||
XpBreakdown {
|
||||
base: 50,
|
||||
speed_bonus,
|
||||
no_undo_bonus: if used_undo { 0 } else { 25 },
|
||||
}
|
||||
}
|
||||
|
||||
/// XP awarded for winning a game. See [`xp_breakdown`] for the components.
|
||||
pub fn xp_for_win(time_seconds: u64, used_undo: bool) -> u64 {
|
||||
xp_breakdown(time_seconds, used_undo).total()
|
||||
}
|
||||
|
||||
/// Platform-specific default path for `progress.json`.
|
||||
|
||||
Reference in New Issue
Block a user