pub struct CardDb {
pub cards: Vec<CardStatic>,
/* private fields */
}Expand description
Loaded card database with cached per-id lookups and compiled abilities.
Fields§
§cards: Vec<CardStatic>Canonical list of static card definitions.
Implementations§
Source§impl CardDb
impl CardDb
Sourcepub fn from_wsdb_bytes(bytes: &[u8]) -> Result<Self>
pub fn from_wsdb_bytes(bytes: &[u8]) -> Result<Self>
Parse a WSDB v2 file from bytes.
Sourcepub fn from_postcard_payload(payload: &[u8]) -> Result<Self>
pub fn from_postcard_payload(payload: &[u8]) -> Result<Self>
Parse the postcard payload (without WSDB header) into a CardDb.
Sourcepub fn schema_version() -> u32
pub fn schema_version() -> u32
Return the current WSDB schema version supported by this build.
Sourcepub fn to_bytes_with_header(&self) -> Result<Vec<u8>>
pub fn to_bytes_with_header(&self) -> Result<Vec<u8>>
Serialize this database to a WSDB v2 byte buffer (including header).
Source§impl CardDb
impl CardDb
Sourcepub fn new(cards: Vec<CardStatic>) -> Result<Self>
pub fn new(cards: Vec<CardStatic>) -> Result<Self>
Build a new database from raw card definitions.
Validates ids, canonicalizes templates, and builds per-id caches.
Sourcepub fn get(&self, id: CardId) -> Option<&CardStatic>
pub fn get(&self, id: CardId) -> Option<&CardStatic>
Look up a card by id. Returns None for invalid or zero ids.
Sourcepub fn max_card_id(&self) -> CardId
pub fn max_card_id(&self) -> CardId
Maximum card id present in the index.
Sourcepub fn is_valid_id(&self, id: CardId) -> bool
pub fn is_valid_id(&self, id: CardId) -> bool
Whether an id exists in this database.
Sourcepub fn power_by_id(&self, id: CardId) -> i32
pub fn power_by_id(&self, id: CardId) -> i32
Cached power value for a card id, or 0 if invalid.
Sourcepub fn soul_by_id(&self, id: CardId) -> u8
pub fn soul_by_id(&self, id: CardId) -> u8
Cached soul value for a card id, or 0 if invalid.
Sourcepub fn level_by_id(&self, id: CardId) -> u8
pub fn level_by_id(&self, id: CardId) -> u8
Cached level value for a card id, or 0 if invalid.
Sourcepub fn cost_by_id(&self, id: CardId) -> u8
pub fn cost_by_id(&self, id: CardId) -> u8
Cached cost value for a card id, or 0 if invalid.
Sourcepub fn color_by_id(&self, id: CardId) -> CardColor
pub fn color_by_id(&self, id: CardId) -> CardColor
Cached color value for a card id, defaulting to red.
Sourcepub fn card_type_by_id(&self, id: CardId) -> CardType
pub fn card_type_by_id(&self, id: CardId) -> CardType
Cached card type for a card id, defaulting to character.
Sourcepub fn iter_card_abilities_in_canonical_order(
&self,
card_id: CardId,
) -> &[AbilitySpec]
pub fn iter_card_abilities_in_canonical_order( &self, card_id: CardId, ) -> &[AbilitySpec]
Abilities in canonical order for a given card id.
Sourcepub fn compiled_effects_for_ability(
&self,
card_id: CardId,
ability_index: usize,
) -> &[EffectSpec]
pub fn compiled_effects_for_ability( &self, card_id: CardId, ability_index: usize, ) -> &[EffectSpec]
Compiled effects for a specific ability on a card.
Sourcepub fn compiled_effects_flat(&self, card_id: CardId) -> Vec<EffectSpec>
pub fn compiled_effects_flat(&self, card_id: CardId) -> Vec<EffectSpec>
Flattened list of all compiled effects for a card.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for CardDb
impl<'de> Deserialize<'de> for CardDb
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for CardDb
impl RefUnwindSafe for CardDb
impl Send for CardDb
impl Sync for CardDb
impl Unpin for CardDb
impl UnsafeUnpin for CardDb
impl UnwindSafe for CardDb
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more