From 881e2796a52a99db81cde32a7e7016635a1bb25d Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 3 Aug 2022 02:56:59 +0200 Subject: [PATCH] Finish up the schema module --- src/data/schema/art.rs | 8 +-- src/data/schema/card.rs | 111 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/src/data/schema/art.rs b/src/data/schema/art.rs index 92815b9..c9afb84 100644 --- a/src/data/schema/art.rs +++ b/src/data/schema/art.rs @@ -63,8 +63,8 @@ mod tests { assert_eq!( serde_json::de::from_str::<'static, CardArt>(r#"{"gameAbsolutePath": https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001.png, "fullAbsolutePath": "https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001-full.png"}"#).unwrap(), CardArt { - card_png: "https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001.png", - full_png: "https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001-full.png", + card_png: String::from("https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001.png"), + full_png: String::from("https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001-full.png"), } ); } @@ -72,8 +72,8 @@ mod tests { #[test] fn png_to_jpg() { let art = CardArt { - card_png: "https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001.png", - full_png: "https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001-full.png", + card_png: String::from("https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001.png"), + full_png: String::from("https://dd.b.pvp.net/latest/set1/en_us/img/cards/01DE001-full.png"), }; assert_eq!(art.card_jpg(), "https://poro.steffo.eu/set1-en_us/en_us/img/cards/01DE001.jpg"); diff --git a/src/data/schema/card.rs b/src/data/schema/card.rs index 2ec263d..dca5a7b 100644 --- a/src/data/schema/card.rs +++ b/src/data/schema/card.rs @@ -1,5 +1,6 @@ //! Module defining [Card]. + use std::collections::HashMap; use super::art::CardArt; use super::set::CardSet; @@ -9,6 +10,7 @@ use super::keyword::CardKeyword; use super::rarity::CardRarity; use super::speed::SpellSpeed; + /// A single Legends of Runeterra card as represented in the data files from [Data Dragon](https://developer.riotgames.com/docs/lor). #[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] #[serde(rename_all="camelCase")] @@ -95,6 +97,8 @@ pub struct Card { #[serde(rename = "associatedCardRefs")] pub associated_card_codes: Vec, /// [Names](name) of other cards associated with this one. + /// + /// Sometimes, it may be missing some references. #[deprecated = "Only for re-serialization purposes, use associated_card_codes instead!"] #[serde(rename = "associatedCards")] pub associated_card_names_localized: Vec, @@ -125,4 +129,111 @@ impl Card { pub fn main_art(&self) -> &CardArt { self.art.get(0).expect("card to have at least one art asset") } +} + + +#[cfg(test)] +mod tests { + use super::Card; + use super::super::art::CardArt; + use super::super::keyword::CardKeyword; + use super::super::rarity::CardRarity; + use super::super::region::CardRegion; + use super::super::set::CardSet; + use super::super::speed::SpellSpeed; + use super::super::r#type::CardType; + + #[test] + fn deserialize_card() { + assert_eq!( + serde_json::de::from_str(r#" + { + "associatedCards": [], + "associatedCardRefs": [ + "06RU025T14", + "06RU025T6", + "06RU025T5" + ], + "assets": [ + { + "gameAbsolutePath": "http://dd.b.pvp.net/3_11_0/set6/en_us/img/cards/06RU025.png", + "fullAbsolutePath": "http://dd.b.pvp.net/3_11_0/set6/en_us/img/cards/06RU025-full.png" + } + ], + "regions": [ + "Runeterra" + ], + "regionRefs": [ + "Runeterra" + ], + "attack": 0, + "cost": 4, + "health": 5, + "description": "Origin: Agony's Embrace.\r\nWhen I'm summoned, summon a random Husk.", + "descriptionRaw": "Origin: Agony's Embrace.\r\nWhen I'm summoned, summon a random Husk.", + "levelupDescription": "When you or an ally kill an allied Husk, give me its positive keywords this round and I level up.", + "levelupDescriptionRaw": "When you or an ally kill an allied Husk, give me its positive keywords this round and I level up.", + "flavorText": "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.", + "artistName": "Kudos Productions", + "name": "Evelynn", + "cardCode": "06RU025", + "keywords": [], + "keywordRefs": [], + "spellSpeed": "", + "spellSpeedRef": "", + "rarity": "Champion", + "rarityRef": "Champion", + "subtypes": [], + "supertype": "Champion", + "type": "Unit", + "collectible": true, + "set": "Set6" + } + "#).unwrap(), + Card { + code: String::from("06RU025"), + name: String::from("Evelynn"), + r#type: CardType::Unit, + set: CardSet::Worldwalker, + rarity: CardRarity::Champion, + collectible: true, + regions: vec![ + CardRegion::Runeterra + ], + #[allow(deprecated)] + regions_localized: vec![ + String::from("Runeterra") + ], + art: vec![ + CardArt { + card_png: String::from("http://dd.b.pvp.net/3_11_0/set6/en_us/img/cards/06RU025.png"), + full_png: String::from("http://dd.b.pvp.net/3_11_0/set6/en_us/img/cards/06RU025-full.png"), + } + ], + attack: 0u64, + cost: 4u64, + health: 5u64, + spell_speed: SpellSpeed::None, + #[allow(deprecated)] + spell_speed_localized: String::from(""), + keywords: vec![], + #[allow(deprecated)] + keywords_localized: vec![], + description: String::from("Origin: Agony's Embrace.\r\nWhen I'm summoned, summon a random Husk."), + description_raw: String::from("Origin: Agony's Embrace.\r\nWhen I'm summoned, summon a random Husk."), + levelup_description: String::from("When you or an ally kill an allied Husk, give me its positive keywords this round and I level up."), + levelup_description_raw: String::from("When you or an ally kill an allied Husk, give me its positive keywords this round and I level up."), + associated_card_codes: vec![ + String::from("06RU025T14"), + String::from("06RU025T6"), + String::from("06RU025T5"), + ], + associated_card_names_localized: vec![], + 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"), + subtypes: vec![], + supertype: String::from("Champion"), + } + ) + } } \ No newline at end of file