1
Fork 0
mirror of https://github.com/Steffo99/patched-porobot.git synced 2024-10-16 17:47:29 +00:00

Add localized methods to access localized data about some Card* enums

This commit is contained in:
Steffo 2022-08-04 19:54:21 +02:00
parent e346d3500a
commit a84bb04d7d
Signed by: steffo
GPG key ID: 6965406171929D01
5 changed files with 70 additions and 0 deletions

View file

@ -1,6 +1,10 @@
//! Module defining [CardKeyword]. //! Module defining [CardKeyword].
use std::collections::HashMap;
use crate::schema::corebundle::CoreKeyword;
/// A keyword which cards can have. /// 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). /// 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)] #[cfg(test)]
mod tests { mod tests {
use super::CardKeyword; use super::CardKeyword;

View file

@ -1,6 +1,10 @@
//! Module defining [CardRarity]. //! Module defining [CardRarity].
use std::collections::HashMap;
use crate::schema::corebundle::CoreRarity;
/// A possible [super::Card] rarity. /// A possible [super::Card] rarity.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum CardRarity { 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)] #[cfg(test)]
mod tests { mod tests {
use super::CardRarity; use super::CardRarity;

View file

@ -1,6 +1,10 @@
//! Module defining [CardRegion]. //! Module defining [CardRegion].
use std::collections::HashMap;
use crate::schema::corebundle::CoreRegion;
/// A region to which [super::Card]s can belong to. /// 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). /// 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)] #[cfg(test)]
mod tests { mod tests {
use super::CardRegion; use super::CardRegion;

View file

@ -1,6 +1,10 @@
//! Module defining [CardSet]. //! Module defining [CardSet].
use std::collections::HashMap;
use crate::schema::corebundle::CoreSet;
/// The release set a [super::Card] may belong to. /// 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). /// 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)] #[cfg(test)]
mod tests { mod tests {
use super::CardSet; use super::CardSet;

View file

@ -1,6 +1,10 @@
//! Module defining [SpellSpeed]. //! Module defining [SpellSpeed].
use std::collections::HashMap;
use crate::schema::corebundle::CoreSpellSpeed;
/// A possible spell speed. /// A possible spell speed.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub enum SpellSpeed { 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)] #[cfg(test)]
mod tests { mod tests {
use super::SpellSpeed; use super::SpellSpeed;