mirror of
https://github.com/Steffo99/patched-porobot.git
synced 2024-12-23 01:54:22 +00:00
Implement supertypes enum (#11)
This commit is contained in:
parent
978074cfef
commit
383948c6e6
3 changed files with 46 additions and 11 deletions
|
@ -142,7 +142,7 @@ pub struct Card {
|
||||||
/// The subtypes the card belongs to, such as *Poro* or *Yordle*.
|
/// The subtypes the card belongs to, such as *Poro* or *Yordle*.
|
||||||
pub subtypes: Vec<CardSubtype>,
|
pub subtypes: Vec<CardSubtype>,
|
||||||
|
|
||||||
/// The supertype the card belongs to, such as *Champion*.
|
/// The supertype the card belongs to, such as [`Champion`](CardSupertype::Champion) or [`None`](CardSupertype::None).
|
||||||
pub supertype: CardSupertype,
|
pub supertype: CardSupertype,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ mod tests {
|
||||||
localized_flavor_text: String::from("The priestess' pupils were blown wide, and her hand trembled with nervous excitement. She was ready. This was the single moment Evelynn craved more than any other. She grinned, and slowly shed her visage. Then, as always, the screaming began."),
|
localized_flavor_text: String::from("The priestess' pupils were blown wide, and her hand trembled with nervous excitement. She was ready. This was the single moment Evelynn craved more than any other. She grinned, and slowly shed her visage. Then, as always, the screaming began."),
|
||||||
artist_name: String::from("Kudos Productions"),
|
artist_name: String::from("Kudos Productions"),
|
||||||
subtypes: vec![],
|
subtypes: vec![],
|
||||||
supertype: String::from("Champion"),
|
supertype: CardSupertype::Champion,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,39 @@
|
||||||
//! Module defining [CardSupertype].
|
//! Module defining [CardSupertype].
|
||||||
|
|
||||||
/// A supertype of a [Card](super::card::Card), such as *Champion*.
|
/// A supertype of a [`Card`](super::card::Card), such as *Champion*.
|
||||||
///
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
/// Capitalization of the various supertypes is inconsistent.
|
#[serde(rename_all = "UPPERCASE")]
|
||||||
///
|
pub enum CardSupertype {
|
||||||
/// TODO: As soon as all supertypes are known, make this a enum.
|
/// No supertype, like most cards in the game.
|
||||||
pub type CardSupertype = String;
|
#[serde(rename = "")]
|
||||||
|
None,
|
||||||
|
/// A [Champion](super::rarity::CardRarity::Champion).
|
||||||
|
#[serde(alias = "Champion")]
|
||||||
|
Champion,
|
||||||
|
/// A supertype of an unknown type.
|
||||||
|
#[serde(other)]
|
||||||
|
Unsupported,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::CardSupertype;
|
||||||
|
|
||||||
|
macro_rules! test_deserialization {
|
||||||
|
( $id:ident, $src:literal, $res:expr ) => {
|
||||||
|
#[test]
|
||||||
|
fn $id() {
|
||||||
|
assert_eq!(
|
||||||
|
serde_json::de::from_str::<'static, CardSupertype>($src).unwrap(),
|
||||||
|
$res
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
test_deserialization!(deserialize_none, r#""""#, CardSupertype::None);
|
||||||
|
test_deserialization!(deserialize_champion_uppercase, r#""CHAMPION""#, CardSupertype::Champion);
|
||||||
|
test_deserialization!(deserialize_champion_titlecase, r#""Champion""#, CardSupertype::Champion);
|
||||||
|
test_deserialization!(deserialize_unsupported, r#""sUs""#, CardSupertype::Unsupported);
|
||||||
|
}
|
||||||
|
|
|
@ -96,9 +96,13 @@ fn display_regions(regions: &[CardRegion], hm: &LocalizedCardRegionIndex) -> Str
|
||||||
fn display_types(r#type: &CardType, supertype: &CardSupertype, subtypes: &[CardSubtype]) -> String {
|
fn display_types(r#type: &CardType, supertype: &CardSupertype, subtypes: &[CardSubtype]) -> String {
|
||||||
let mut result = String::new();
|
let mut result = String::new();
|
||||||
|
|
||||||
if supertype != "" {
|
result.push_str(
|
||||||
result.push_str(&*format!("<i>{}</i> › ", escape(&supertype),));
|
match supertype {
|
||||||
};
|
CardSupertype::Champion => "<i>Champion</i> › ",
|
||||||
|
CardSupertype::Unsupported => "<i>Unknown</i> › ",
|
||||||
|
_ => "",
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
result.push_str(&*format!("<i>{}</i>", escape(&*String::from(r#type)),));
|
result.push_str(&*format!("<i>{}</i>", escape(&*String::from(r#type)),));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue