refactor: consolidate card_to_id into solitaire_core
Build and Deploy / build-and-push (push) Failing after 1m21s
Web E2E / web-e2e (push) Failing after 3m27s

Three byte-identical copies of the stable 0..=51 card-id helper
(suit_index*13 + rank-1) lived in feedback_anim_plugin, radial_menu, and
solitaire_wasm. The WASM copy's own comment notes it MUST match the engine
for cross-platform replay parity — exactly the kind of invariant a single
source of truth should enforce.

Add `solitaire_core::card::card_to_id(&Card) -> u32` and have all three
call sites import it. No behaviour change (same formula).

cargo test --workspace and cargo clippy --workspace --all-targets -- -D warnings pass.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
funman300
2026-06-10 10:14:20 -07:00
parent cac77a54a6
commit 0d3f037672
4 changed files with 29 additions and 38 deletions
+3 -13
View File
@@ -188,19 +188,9 @@ pub fn deal_stagger_jitter(card_id: u32) -> f32 {
(jitter_norm - 0.5) * 0.2 // ±0.1 == ±10 %
}
/// Converts a `Card` to a `u32` seed suitable for deterministic per-card
/// jitter. Uses suit index × 13 + (rank value 1) to produce a stable 051
/// integer that survives changes to the internal `Card` representation.
fn card_to_id(card: &Card) -> u32 {
use solitaire_core::card::Suit;
let suit_index = match card.suit() {
Suit::Clubs => 0,
Suit::Diamonds => 1,
Suit::Hearts => 2,
Suit::Spades => 3,
};
suit_index * 13 + (card.rank() as u32 - 1)
}
// Per-card jitter keys off the shared stable card id so it matches the
// numeric identity used elsewhere (and on the WASM replay side).
use solitaire_core::card::card_to_id;
// ---------------------------------------------------------------------------
// Plugin
+1 -13
View File
@@ -359,19 +359,7 @@ fn pile_cards(game: &GameState, pile: &KlondikePile) -> Vec<(Card, bool)> {
}
}
/// Maps a `card_game::Card` to a stable `u32` identity used by `CardEntity`
/// and systems that still track cards by numeric ID.
/// Encoding: `suit_index * 13 + (rank as u8 - 1)`, range 0..=51.
fn card_to_id(card: &Card) -> u32 {
use solitaire_core::card::Suit;
let suit_index: u32 = match card.suit() {
Suit::Clubs => 0,
Suit::Diamonds => 1,
Suit::Hearts => 2,
Suit::Spades => 3,
};
suit_index * 13 + (card.rank() as u32 - 1)
}
use solitaire_core::card::card_to_id;
const fn foundations() -> [Foundation; 4] {
[