refactor: remove card.rs / card_to_id; use card_game::Card directly (#83)
card_to_id was a frankenstein 0..=51 id shim. Replace it with card_game::Card: - feedback_anim deal jitter now seeds off a hash of the Card itself - radial_menu RightClickRadialState.cards: Vec<u32> -> Vec<Card> - wasm CardSnapshot.id: u32 -> Card (serialises transparently as a plain JS number, the same opaque key the renderer already used; new test asserts the JSON id field is a number) - wasm DebugInvariantReport deck-completeness check reworked from a [bool;52] index into a HashSet<Card> + Card::new reference deck; the out-of-range check is dropped since a Card is always valid Delete card.rs entirely: the Card/Deck/Rank/Suit re-exports move to the crate root and the 69 `solitaire_core::card::` import paths flatten to `solitaire_core::`. The JS card.id is purely an opaque identity key (Map key / dataset.cardId, no arithmetic, card faces render from rank+suit), so the value change is safe. cargo test --workspace and clippy --workspace --all-targets -- -D warnings green. Closes #83 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,23 +0,0 @@
|
||||
pub use card_game::{Card, Deck, Rank, Suit};
|
||||
|
||||
/// Maps a [`Card`] to a stable `0..=51` numeric identity, independent of the
|
||||
/// upstream `card_game::Card` bit-packing.
|
||||
///
|
||||
/// Encoding: `suit_index * 13 + (rank as u32 - 1)`, where `suit_index` is
|
||||
/// Clubs=0, Diamonds=1, Hearts=2, Spades=3 and `rank` is 1 (Ace) ..= 13 (King).
|
||||
/// The deck id is intentionally ignored so the id depends only on the visible
|
||||
/// face.
|
||||
///
|
||||
/// This is the single source of truth shared by `CardEntity` numeric tracking,
|
||||
/// deterministic per-card animation jitter, and the WASM replay layer — those
|
||||
/// must agree byte-for-byte so replay snapshots are identical across the
|
||||
/// desktop and browser builds.
|
||||
pub fn card_to_id(card: &Card) -> u32 {
|
||||
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)
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
pub mod achievement;
|
||||
pub mod card;
|
||||
pub mod error;
|
||||
pub mod game_state;
|
||||
pub mod klondike_adapter;
|
||||
@@ -12,7 +11,7 @@ pub mod klondike_adapter;
|
||||
// re-exported — they are only used internally (in `klondike_adapter.rs` and
|
||||
// when decoding instructions to piles in `instruction_to_piles`) and do not
|
||||
// appear in any public method signature.
|
||||
pub use card_game::{Card, Session, SolveError};
|
||||
pub use card_game::{Card, Deck, Rank, Session, SolveError, Suit};
|
||||
pub use klondike::{DrawStockConfig, Foundation, Klondike, KlondikeInstruction, KlondikePile, Tableau};
|
||||
|
||||
// Solvability check API (delegates to `card_game::Session::solve`); replaces the
|
||||
|
||||
Reference in New Issue
Block a user