mirror of
https://github.com/Steffo99/patched-porobot.git
synced 2024-12-22 17:44:22 +00:00
Add localized
methods to access localized data about some Card*
enums
This commit is contained in:
parent
e346d3500a
commit
a84bb04d7d
5 changed files with 70 additions and 0 deletions
|
@ -1,6 +1,10 @@
|
|||
//! Module defining [CardKeyword].
|
||||
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::schema::corebundle::CoreKeyword;
|
||||
|
||||
/// A keyword which cards can have.
|
||||
///
|
||||
/// Since more keywords will probably be added in the future, this enum is [non_exaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute).
|
||||
|
@ -334,6 +338,16 @@ pub enum CardKeyword {
|
|||
}
|
||||
|
||||
|
||||
impl CardKeyword {
|
||||
/// Get localized text about the keyword from [crate::schema::corebundle] data.
|
||||
///
|
||||
/// Returns `None` if no matching [CoreKeyword] was found, for example for [CardKeyword::Unsupported] keywords.
|
||||
pub fn localized<'hm>(&self, hm: &'hm HashMap<CardKeyword, CoreKeyword>) -> Option<&'hm CoreKeyword> {
|
||||
hm.get(&self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::CardKeyword;
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
//! Module defining [CardRarity].
|
||||
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::schema::corebundle::CoreRarity;
|
||||
|
||||
/// A possible [super::Card] rarity.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub enum CardRarity {
|
||||
|
@ -23,6 +27,16 @@ pub enum CardRarity {
|
|||
}
|
||||
|
||||
|
||||
impl CardRarity {
|
||||
/// Get localized text about the rarity from [crate::schema::corebundle] data.
|
||||
///
|
||||
/// Returns `None` if no matching [CoreRarity] was found, for example if the hashmap is incomplete.
|
||||
pub fn localized<'hm>(&self, hm: &'hm HashMap<CardRarity, CoreRarity>) -> Option<&'hm CoreRarity> {
|
||||
hm.get(&self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::CardRarity;
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
//! Module defining [CardRegion].
|
||||
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::schema::corebundle::CoreRegion;
|
||||
|
||||
/// A region to which [super::Card]s can belong to.
|
||||
///
|
||||
/// Since more regions might be added in the future, especially Origin ones, this enum is [non_exaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute).
|
||||
|
@ -42,6 +46,16 @@ pub enum CardRegion {
|
|||
}
|
||||
|
||||
|
||||
impl CardRegion {
|
||||
/// Get localized text about the region from [crate::schema::corebundle] data.
|
||||
///
|
||||
/// Returns `None` if no matching [CoreRegion] was found, for example for [CardRegion::Unsupported] regions.
|
||||
pub fn localized<'hm>(&self, hm: &'hm HashMap<CardRegion, CoreRegion>) -> Option<&'hm CoreRegion> {
|
||||
hm.get(&self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::CardRegion;
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
//! Module defining [CardSet].
|
||||
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::schema::corebundle::CoreSet;
|
||||
|
||||
/// The release set a [super::Card] may belong to.
|
||||
///
|
||||
/// Since more sets will definitely be added in the future, this enum is [non_exaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute).
|
||||
|
@ -41,6 +45,16 @@ pub enum CardSet {
|
|||
}
|
||||
|
||||
|
||||
impl CardSet {
|
||||
/// Get localized text about the set from [crate::schema::corebundle] data.
|
||||
///
|
||||
/// Returns `None` if no matching [CoreSet] was found, for example for [CardSet::Unsupported] sets.
|
||||
pub fn localized<'hm>(&self, hm: &'hm HashMap<CardSet, CoreSet>) -> Option<&'hm CoreSet> {
|
||||
hm.get(&self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::CardSet;
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
//! Module defining [SpellSpeed].
|
||||
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::schema::corebundle::CoreSpellSpeed;
|
||||
|
||||
/// A possible spell speed.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
|
||||
pub enum SpellSpeed {
|
||||
|
@ -16,6 +20,16 @@ pub enum SpellSpeed {
|
|||
}
|
||||
|
||||
|
||||
impl SpellSpeed {
|
||||
/// Get localized text about the speed from [crate::schema::corebundle] data.
|
||||
///
|
||||
/// Returns `None` if no matching [CoreSpellSpeed] was found, for example if the hashmap is incomplete.
|
||||
pub fn localized<'hm>(&self, hm: &'hm HashMap<SpellSpeed, CoreSpellSpeed>) -> Option<&'hm CoreSpellSpeed> {
|
||||
hm.get(&self)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::SpellSpeed;
|
||||
|
|
Loading…
Reference in a new issue