diff --git a/src/load/corebundle.rs b/src/load/corebundle.rs new file mode 100644 index 0000000..2c8d7ea --- /dev/null +++ b/src/load/corebundle.rs @@ -0,0 +1,64 @@ +//! This module provides ways to load official data files from Riot Games' [Core Bundles](https://developer.riotgames.com/docs/lor#data-dragon_core-bundles) into Rust structs. + +use std::io::Read; +use std::collections::HashMap; +use crate::schema::corebundle::*; +use crate::schema::setbundle::*; + + +/// Deserialize a `globals.json` file into a [CoreGlobals] struct. +pub fn globalsjson_to_coreglobals(r: R) -> serde_json::Result + where R: Read +{ + serde_json::de::from_reader::(r) +} + + +/// Convert a [Vec] of [CoreVocabTerm]s into a [HashMap] of [CoreVocabTerm]s, indexed by their [CoreVocabTerm::vocabterm]. +pub fn vocabtermvec_to_vocabtermhashmap(v: Vec) -> HashMap { + let mut hm = HashMap::::new(); + for vocabterm in v { + hm.insert(vocabterm.vocabterm.clone(), vocabterm); + } + hm +} + + +/// Convert a [Vec] of [CoreKeyword]s into a [HashMap] of [CoreKeyword]s, indexed by their [CoreKeyword::keyword]. +pub fn keywordvec_to_keywordhashmap(v: Vec) -> HashMap { + let mut hm = HashMap::::new(); + for keyword in v { + hm.insert(keyword.keyword, keyword); + } + hm +} + + +/// Convert a [Vec] of [CoreRegion]s into a [HashMap] of [CoreRegion]s, indexed by their [CoreRegion::region]. +pub fn regionvec_to_regionhashmap(v: Vec) -> HashMap { + let mut hm = HashMap::::new(); + for region in v { + hm.insert(region.region, region); + } + hm +} + + +/// Convert a [Vec] of [CoreSpellSpeed]s into a [HashMap] of [CoreSpellSpeed]s, indexed by their [CoreSpellSpeed::spell_speed]. +pub fn spellspeedvec_to_spellspeedhashmap(v: Vec) -> HashMap { + let mut hm = HashMap::::new(); + for spell_speed in v { + hm.insert(spell_speed.spell_speed, spell_speed); + } + hm +} + + +/// Convert a [Vec] of [CoreRarity]s into a [HashMap] of [CoreRarity]s, indexed by their [CoreRarity::spell_speed]. +pub fn rarityvec_to_rarityhashmap(v: Vec) -> HashMap { + let mut hm = HashMap::::new(); + for rarity in v { + hm.insert(rarity.rarity, rarity); + } + hm +} diff --git a/src/load/mod.rs b/src/load/mod.rs index fffb684..7e57ff7 100644 --- a/src/load/mod.rs +++ b/src/load/mod.rs @@ -1,237 +1,4 @@ -//! This module offers ways to load official data files from Riot Games' [Data Dragon](https://developer.riotgames.com/docs/lor#data-dragon) into [Card] objects. -//! -//! Since [Card] implements both [serde::Serialize] and [serde::Deserialize], both operations can be performed manually; this module just provides shortcuts and useful utility functions. +//! This module provides ways to load official data files from Riot Games' [Data Dragon](https://developer.riotgames.com/docs/lor#data-dragon) into Rust structs. - -use std::io::Read; -use std::collections::HashMap; -use crate::schema::Card; - - -/// Deserialize Data Dragon [Set Bundle](https://developer.riotgames.com/docs/lor#data-dragon_set-bundles) JSON data into a [Card] [Vec]. -pub fn vec_from_reader(r: R) -> serde_json::Result> - where R: Read -{ - serde_json::de::from_reader::>(r) -} - - -/// Deserialize Data Dragon [Set Bundle](https://developer.riotgames.com/docs/lor#data-dragon_set-bundles) JSON data into a [Card] [HashMap], with card codes as keys. -pub fn hashmap_from_reader(r: R) -> serde_json::Result> - where R: Read -{ - let vec = vec_from_reader(r)?; - let mut hm = HashMap::::new(); - for card in vec { - hm.insert(card.code.clone(), card); - } - Ok(hm) -} - - -#[cfg(test)] -#[allow(deprecated)] -mod tests { - use super::*; - use crate::schema::*; - - const TEST_DATA: &str = r#" - [ - { - "associatedCards": [], - "associatedCardRefs": [], - "assets": [ - { - "gameAbsolutePath": "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012.png", - "fullAbsolutePath": "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012-full.png" - } - ], - "regions": [ - "Ionia" - ], - "regionRefs": [ - "Ionia" - ], - "attack": 0, - "cost": 2, - "health": 0, - "description": "Give an ally +2|+0 or +0|+3 this round.", - "descriptionRaw": "Give an ally +2|+0 or +0|+3 this round.", - "levelupDescription": "", - "levelupDescriptionRaw": "", - "flavorText": "\"Never fear change. It will question you, test your limits. It is our greatest teacher.\" - Karma", - "artistName": "SIXMOREVODKA", - "name": "Twin Disciplines", - "cardCode": "01IO012", - "keywords": [ - "Burst" - ], - "keywordRefs": [ - "Burst" - ], - "spellSpeed": "Burst", - "spellSpeedRef": "Burst", - "rarity": "COMMON", - "rarityRef": "Common", - "subtypes": [], - "supertype": "", - "type": "Spell", - "collectible": true, - "set": "Set1" - }, - { - "associatedCards": [], - "associatedCardRefs": [], - "assets": [ - { - "gameAbsolutePath": "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012T2.png", - "fullAbsolutePath": "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012T2-full.png" - } - ], - "regions": [ - "Ionia" - ], - "regionRefs": [ - "Ionia" - ], - "attack": 0, - "cost": 2, - "health": 0, - "description": "Give an ally +0|+3 this round.", - "descriptionRaw": "Give an ally +0|+3 this round.", - "levelupDescription": "", - "levelupDescriptionRaw": "", - "flavorText": "", - "artistName": "SIXMOREVODKA", - "name": "Discipline of Fortitude", - "cardCode": "01IO012T2", - "keywords": [ - "Burst" - ], - "keywordRefs": [ - "Burst" - ], - "spellSpeed": "Burst", - "spellSpeedRef": "Burst", - "rarity": "None", - "rarityRef": "None", - "subtypes": [], - "supertype": "", - "type": "Spell", - "collectible": false, - "set": "Set1" - } - ] - "#; - - fn expected_card_1() -> Card { - Card { - code: "01IO012".to_string(), - name: "Twin Disciplines".to_string(), - r#type: CardType::Spell, - set: CardSet::Foundations, - rarity: CardRarity::Common, - collectible: true, - regions: vec![ - CardRegion::Ionia, - ], - regions_localized: vec![ - "Ionia".to_string(), - ], - art: vec![ - CardArt { - card_png: "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012.png".to_string(), - full_png: "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012-full.png".to_string(), - } - ], - attack: 0, - cost: 2, - health: 0, - spell_speed: SpellSpeed::Burst, - spell_speed_localized: "Burst".to_string(), - keywords: vec![ - CardKeyword::Burst, - ], - keywords_localized: vec![ - "Burst".to_string(), - ], - description: "Give an ally +2|+0 or +0|+3 this round.".to_string(), - description_raw: "Give an ally +2|+0 or +0|+3 this round.".to_string(), - levelup_description: "".to_string(), - levelup_description_raw: "".to_string(), - associated_card_codes: vec![], - associated_card_names_localized: vec![], - flavor_text: r#""Never fear change. It will question you, test your limits. It is our greatest teacher." - Karma"#.to_string(), - artist_name: "SIXMOREVODKA".to_string(), - subtypes: vec![], - supertype: "".to_string() - } - } - - fn expected_card_2() -> Card { - Card { - code: "01IO012T2".to_string(), - name: "Discipline of Fortitude".to_string(), - r#type: CardType::Spell, - set: CardSet::Foundations, - rarity: CardRarity::None, - collectible: false, - regions: vec![ - CardRegion::Ionia, - ], - regions_localized: vec![ - "Ionia".to_string(), - ], - art: vec![ - CardArt { - card_png: "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012T2.png".to_string(), - full_png: "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012T2-full.png".to_string() - } - ], - attack: 0, - cost: 2, - health: 0, - spell_speed: SpellSpeed::Burst, - spell_speed_localized: "Burst".to_string(), - keywords: vec![ - CardKeyword::Burst, - ], - keywords_localized: vec![ - "Burst".to_string(), - ], - description: "Give an ally +0|+3 this round.".to_string(), - description_raw: "Give an ally +0|+3 this round.".to_string(), - levelup_description: "".to_string(), - levelup_description_raw: "".to_string(), - associated_card_codes: vec![], - associated_card_names_localized: vec![], - flavor_text: "".to_string(), - artist_name: "SIXMOREVODKA".to_string(), - subtypes: vec![], - supertype: "".to_string() - } - } - - fn expected_hashmap() -> HashMap { - let mut hm = HashMap::::new(); - hm.insert("01IO012".to_string(), expected_card_1()); - hm.insert("01IO012T2".to_string(), expected_card_2()); - hm - } - - #[test] - fn test_vec_from_reader() { - assert_eq!( - vec_from_reader(TEST_DATA.as_bytes()).unwrap(), - vec![expected_card_1(), expected_card_2()] - ) - } - - #[test] - fn test_hashmap_from_reader() { - assert_eq!( - hashmap_from_reader(TEST_DATA.as_bytes()).unwrap(), - expected_hashmap() - ) - } -} \ No newline at end of file +pub mod corebundle; +pub mod setbundle; diff --git a/src/load/setbundle.rs b/src/load/setbundle.rs new file mode 100644 index 0000000..e4e6823 --- /dev/null +++ b/src/load/setbundle.rs @@ -0,0 +1,237 @@ +//! This module provides ways to load official data files from Riot Games' [Set Bundles](https://developer.riotgames.com/docs/lor#data-dragon_set-bundles) into Rust structs. + +use std::io::Read; +use std::collections::HashMap; +use crate::schema::setbundle::*; + + +/// Deserialize a `set.json` file into a [Vec] of [Card]s. +pub fn setjson_to_cardvec(r: R) -> serde_json::Result> + where R: Read +{ + serde_json::de::from_reader::>(r) +} + + +/// Convert a [Vec] of [Card]s (probably from [setjson_to_vec]) into a [HashMap] of [Card]s, indexed by their [Card::code]. +pub fn cardvec_to_cardhashmap(v: Vec) -> HashMap { + let mut hm = HashMap::::new(); + for card in v { + hm.insert(card.code.clone(), card); + } + hm +} + + +#[cfg(test)] +#[allow(deprecated)] +mod tests { + use std::collections::HashMap; + use super::setjson_to_cardvec; + use super::cardvec_to_cardhashmap; + use crate::schema::setbundle::*; + + const TEST_SETJSON: &str = r#" + [ + { + "associatedCards": [], + "associatedCardRefs": [], + "assets": [ + { + "gameAbsolutePath": "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012.png", + "fullAbsolutePath": "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012-full.png" + } + ], + "regions": [ + "Ionia" + ], + "regionRefs": [ + "Ionia" + ], + "attack": 0, + "cost": 2, + "health": 0, + "description": "Give an ally +2|+0 or +0|+3 this round.", + "descriptionRaw": "Give an ally +2|+0 or +0|+3 this round.", + "levelupDescription": "", + "levelupDescriptionRaw": "", + "flavorText": "\"Never fear change. It will question you, test your limits. It is our greatest teacher.\" - Karma", + "artistName": "SIXMOREVODKA", + "name": "Twin Disciplines", + "cardCode": "01IO012", + "keywords": [ + "Burst" + ], + "keywordRefs": [ + "Burst" + ], + "spellSpeed": "Burst", + "spellSpeedRef": "Burst", + "rarity": "COMMON", + "rarityRef": "Common", + "subtypes": [], + "supertype": "", + "type": "Spell", + "collectible": true, + "set": "Set1" + }, + { + "associatedCards": [], + "associatedCardRefs": [], + "assets": [ + { + "gameAbsolutePath": "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012T2.png", + "fullAbsolutePath": "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012T2-full.png" + } + ], + "regions": [ + "Ionia" + ], + "regionRefs": [ + "Ionia" + ], + "attack": 0, + "cost": 2, + "health": 0, + "description": "Give an ally +0|+3 this round.", + "descriptionRaw": "Give an ally +0|+3 this round.", + "levelupDescription": "", + "levelupDescriptionRaw": "", + "flavorText": "", + "artistName": "SIXMOREVODKA", + "name": "Discipline of Fortitude", + "cardCode": "01IO012T2", + "keywords": [ + "Burst" + ], + "keywordRefs": [ + "Burst" + ], + "spellSpeed": "Burst", + "spellSpeedRef": "Burst", + "rarity": "None", + "rarityRef": "None", + "subtypes": [], + "supertype": "", + "type": "Spell", + "collectible": false, + "set": "Set1" + } + ] + "#; + + fn expected_card_1() -> Card { + Card { + code: "01IO012".to_string(), + name: "Twin Disciplines".to_string(), + r#type: CardType::Spell, + set: CardSet::Foundations, + rarity: CardRarity::Common, + collectible: true, + regions: vec![ + CardRegion::Ionia, + ], + localized_regions: vec![ + "Ionia".to_string(), + ], + art: vec![ + CardArt { + card_png: "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012.png".to_string(), + full_png: "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012-full.png".to_string(), + } + ], + attack: 0, + cost: 2, + health: 0, + spell_speed: SpellSpeed::Burst, + localized_spell_speed: "Burst".to_string(), + keywords: vec![ + CardKeyword::Burst, + ], + localized_keywords: vec![ + "Burst".to_string(), + ], + localized_description_xml: "Give an ally +2|+0 or +0|+3 this round.".to_string(), + localized_description_text: "Give an ally +2|+0 or +0|+3 this round.".to_string(), + localized_levelup_xml: "".to_string(), + localized_levelup_text: "".to_string(), + associated_card_codes: vec![], + associated_card_names_localized: vec![], + flavor_text: r#""Never fear change. It will question you, test your limits. It is our greatest teacher." - Karma"#.to_string(), + artist_name: "SIXMOREVODKA".to_string(), + subtypes: vec![], + supertype: "".to_string() + } + } + + fn expected_card_2() -> Card { + Card { + code: "01IO012T2".to_string(), + name: "Discipline of Fortitude".to_string(), + r#type: CardType::Spell, + set: CardSet::Foundations, + rarity: CardRarity::None, + collectible: false, + regions: vec![ + CardRegion::Ionia, + ], + localized_regions: vec![ + "Ionia".to_string(), + ], + art: vec![ + CardArt { + card_png: "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012T2.png".to_string(), + full_png: "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012T2-full.png".to_string() + } + ], + attack: 0, + cost: 2, + health: 0, + spell_speed: SpellSpeed::Burst, + localized_spell_speed: "Burst".to_string(), + keywords: vec![ + CardKeyword::Burst, + ], + localized_keywords: vec![ + "Burst".to_string(), + ], + localized_description_xml: "Give an ally +0|+3 this round.".to_string(), + localized_description_text: "Give an ally +0|+3 this round.".to_string(), + localized_levelup_xml: "".to_string(), + localized_levelup_text: "".to_string(), + associated_card_codes: vec![], + associated_card_names_localized: vec![], + flavor_text: "".to_string(), + artist_name: "SIXMOREVODKA".to_string(), + subtypes: vec![], + supertype: "".to_string() + } + } + + fn expected_vec() -> Vec { + vec![expected_card_1(), expected_card_2()] + } + + fn expected_hashmap() -> HashMap { + let mut hm = HashMap::::new(); + hm.insert("01IO012".to_string(), expected_card_1()); + hm.insert("01IO012T2".to_string(), expected_card_2()); + hm + } + + #[test] + fn test_setjson_to_cardvec() { + assert_eq!( + setjson_to_cardvec(TEST_SETJSON.as_bytes()).unwrap(), + expected_vec() + ) + } + + #[test] + fn test_cardvec_to_cardhashmap() { + assert_eq!( + cardvec_to_cardhashmap(expected_vec()), + expected_hashmap() + ) + } +} \ No newline at end of file diff --git a/src/schema/corebundle/globals.rs b/src/schema/corebundle/globals.rs new file mode 100644 index 0000000..9dcf856 --- /dev/null +++ b/src/schema/corebundle/globals.rs @@ -0,0 +1,29 @@ +use super::vocabterm::CoreVocabTerm; +use super::keyword::CoreKeyword; +use super::region::CoreRegion; +use super::speed::CoreSpellSpeed; +use super::rarity::CoreRarity; + + +/// A complete `globals.json` file. +/// +/// It contains a list of all vocabulary terms, [CardKeyword]s, [CardRegion]s, [SpellSpeed]s, and [CardRarity]s present in the game. +#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] +pub struct CoreGlobals { + /// A [Vec] of all [CoreVocabTerm]s in the game. + #[serde(rename = "vocabTerms")] + pub vocab_terms: Vec, + + /// A [Vec] of all [CoreKeyword]s in the game. + pub keywords: Vec, + + /// A [Vec] of all [CoreRegion]s in the game. + pub regions: Vec, + + /// A [Vec] of all [CoreSpellSpeed]s in the game. + #[serde(rename = "spellSpeeds")] + pub spell_speeds: Vec, + + /// A [Vec] of all [CoreRarity]s in the game. + pub rarities: Vec, +} \ No newline at end of file diff --git a/src/schema/corebundle/keyword.rs b/src/schema/corebundle/keyword.rs new file mode 100644 index 0000000..699574a --- /dev/null +++ b/src/schema/corebundle/keyword.rs @@ -0,0 +1,17 @@ +//! This module defines [CoreKeyword]. + +use crate::schema::setbundle::CardKeyword; + +/// A Legends of Runeterra [CardKeyword], and its associated localization. +#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] +pub struct CoreKeyword { + /// The [CardKeyword] these strings refer to. + #[serde(rename = "nameRef")] + pub keyword: CardKeyword, + + /// The localized name of the keyword. + pub name: String, + + /// The description of the keyword, the text of the in-game tooltip. + pub description: String, +} diff --git a/src/schema/corebundle/mod.rs b/src/schema/corebundle/mod.rs new file mode 100644 index 0000000..4faaea7 --- /dev/null +++ b/src/schema/corebundle/mod.rs @@ -0,0 +1,17 @@ +//! This module defines the types used in Data Dragon's [Core Bundle](https://developer.riotgames.com/docs/lor#data-dragon_core-bundles) `globals.json` files. + +mod globals; +mod vocabterm; +mod keyword; +mod region; +mod speed; +mod rarity; +mod set; + +pub use globals::CoreGlobals; +pub use vocabterm::CoreVocabTerm; +pub use keyword::CoreKeyword; +pub use region::CoreRegion; +pub use speed::CoreSpellSpeed; +pub use rarity::CoreRarity; +pub use set::CoreSet; diff --git a/src/schema/corebundle/rarity.rs b/src/schema/corebundle/rarity.rs new file mode 100644 index 0000000..73610e0 --- /dev/null +++ b/src/schema/corebundle/rarity.rs @@ -0,0 +1,14 @@ +//! This module defines [CoreRarity]. + +use crate::schema::setbundle::CardRarity; + +/// A Legends of Runeterra [CardRarity], and its associated localization. +#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] +pub struct CoreRarity { + /// The [CardRarity] these strings refer to. + #[serde(rename = "nameRef")] + pub rarity: CardRarity, + + /// The localized name of the rarity. + pub name: String, +} diff --git a/src/schema/corebundle/region.rs b/src/schema/corebundle/region.rs new file mode 100644 index 0000000..451698b --- /dev/null +++ b/src/schema/corebundle/region.rs @@ -0,0 +1,23 @@ +//! This module defines [CoreRegion]. + +use crate::schema::setbundle::CardRegion; + +/// A Legends of Runeterra [CardRegion], and its associated localization. +#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] +pub struct CoreRegion { + /// The [CardRegion] these strings refer to. + #[serde(rename = "nameRef")] + pub region: CardRegion, + + /// The localized name of the region. + pub name: String, + + /// The abbreviation for the region. + /// + /// Usually two letters long, but may be longer for "Origin" regions. + pub abbreviation: String, + + /// URL to the icon of the region in `.png` format. + #[serde(rename = "iconAbsolutePath")] + pub icon_png: String, +} diff --git a/src/schema/corebundle/set.rs b/src/schema/corebundle/set.rs new file mode 100644 index 0000000..174dd8e --- /dev/null +++ b/src/schema/corebundle/set.rs @@ -0,0 +1,18 @@ +//! This module defines [CoreSet]. + +use crate::schema::setbundle::CardSet; + +/// A Legends of Runeterra [CardSet], and its associated localization. +#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] +pub struct CoreSet { + /// The [CardSet] these strings refer to. + #[serde(rename = "nameRef")] + set: CardSet, + + /// The localized name of the set. + name: String, + + /// URL to the icon of the set in `.png` format. + #[serde(rename = "iconAbsolutePath")] + icon_png: String, +} diff --git a/src/schema/corebundle/speed.rs b/src/schema/corebundle/speed.rs new file mode 100644 index 0000000..bc84568 --- /dev/null +++ b/src/schema/corebundle/speed.rs @@ -0,0 +1,14 @@ +//! This module defines [CoreSpellSpeed]. + +use crate::schema::setbundle::SpellSpeed; + +/// A Legends of Runeterra [SpellSpeed], and its associated localization. +#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] +pub struct CoreSpellSpeed { + /// The [SpellSpeed] these strings refer to. + #[serde(rename = "nameRef")] + pub spell_speed: SpellSpeed, + + /// The localized name of the spell speed. + pub name: String, +} diff --git a/src/schema/corebundle/vocabterm.rs b/src/schema/corebundle/vocabterm.rs new file mode 100644 index 0000000..3b67867 --- /dev/null +++ b/src/schema/corebundle/vocabterm.rs @@ -0,0 +1,21 @@ +//! This module defines [CoreVocabTerm]. + +/// A Legends of Runeterra vocabulary term, and its associated localization. +/// +/// I'm not sure where these are used, other than in in-game tooltips. +/// +/// TODO: Find out where these are used. +#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] +pub struct CoreVocabTerm { + /// The internal name used by the vocabulary term. + /// + /// TODO: Map these to an enum. + #[serde(rename = "nameRef")] + pub vocabterm: String, + + /// The localized name of the vocabulary term. + pub name: String, + + /// The description of the vocabulary term, the text of the in-game tooltip. + pub description: String, +} \ No newline at end of file diff --git a/src/schema/mod.rs b/src/schema/mod.rs index 4f4be07..d10e3b2 100644 --- a/src/schema/mod.rs +++ b/src/schema/mod.rs @@ -1,19 +1,4 @@ -//! This module defines the [Card] type and the types used in it to better describe attributes. +//! This module contains the [corebundle] and [setbundle] submodules. -mod card; -mod art; -mod r#type; -mod rarity; -mod region; -mod set; -mod speed; -mod keyword; - -pub use card::Card; -pub use art::CardArt; -pub use r#type::CardType; -pub use rarity::CardRarity; -pub use region::CardRegion; -pub use set::CardSet; -pub use speed::SpellSpeed; -pub use keyword::CardKeyword; +pub mod corebundle; +pub mod setbundle; diff --git a/src/schema/art.rs b/src/schema/setbundle/art.rs similarity index 96% rename from src/schema/art.rs rename to src/schema/setbundle/art.rs index 6cb7e4e..ff000cb 100644 --- a/src/schema/art.rs +++ b/src/schema/setbundle/art.rs @@ -1,7 +1,7 @@ //! Module defining [CardArt]. /// An art asset associated with a [super::Card]. -#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub struct CardArt { /// URL to the `.png` image of the rendered card. /// diff --git a/src/schema/card.rs b/src/schema/setbundle/card.rs similarity index 82% rename from src/schema/card.rs rename to src/schema/setbundle/card.rs index 211e014..921088d 100644 --- a/src/schema/card.rs +++ b/src/schema/setbundle/card.rs @@ -2,20 +2,14 @@ use std::collections::HashMap; -use super::art::CardArt; -use super::set::CardSet; -use super::r#type::CardType; -use super::region::CardRegion; -use super::keyword::CardKeyword; -use super::rarity::CardRarity; -use super::speed::SpellSpeed; +use crate::schema::corebundle::*; +use super::*; /// A single Legends of Runeterra card. /// /// The information is represented in a developer-friendly manner, but it can be serialized and deserialized via [serde] in the exact same format used in Data Dragon. -#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] -#[serde(rename_all="camelCase")] +#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub struct Card { /// Unique seven-character identifier of the card. #[serde(rename = "cardCode")] @@ -45,9 +39,10 @@ pub struct Card { #[serde(rename = "regionRefs")] pub regions: Vec, /// Localized names of the regions this card belongs to. - #[deprecated = "Only for re-serialization purposes, use regions instead!"] + /// + /// For serialization purposes only, use the [method with the same name](Card::localized_regions()] instead! #[serde(rename = "regions")] - pub regions_localized: Vec, + pub(crate) localized_regions: Vec, /// A [Vec] of [CardArt] assets of the card. /// @@ -76,31 +71,37 @@ pub struct Card { #[serde(rename = "spellSpeedRef")] pub spell_speed: SpellSpeed, /// Localized name of the [SpellSpeed] of the card. - #[deprecated = "Only for re-serialization purposes, use spell_speed instead!"] + /// + /// For serialization purposes only, use the [method with the same name](Card::localized_spell_speed()] instead! #[serde(rename = "spellSpeed")] - pub spell_speed_localized: String, + pub(crate) localized_spell_speed: String, /// [Vec] of [CardKeyword]s of the card. #[serde(rename="keywordRefs")] pub keywords: Vec, /// [Vec] of localized names of [CardKeyword]s of the card. - #[deprecated = "Only for re-serialization purposes, use keywords instead!"] + /// + /// For serialization purposes only, use the [method with the same name](Card::localized_keywords()] instead! #[serde(rename="keywords")] - pub keywords_localized: Vec, + pub(crate) localized_keywords: Vec, /// Localized description of the card, in pseudo-XML. - pub description: String, + #[serde(rename="description")] + pub localized_description_xml: String, /// Localized description of the card, in plain text. - pub description_raw: String, + #[serde(rename="descriptionRaw")] + pub localized_description_text: String, /// Localized level up text of the card, in pseudo-XML. /// /// If the card has no level up text, contains an empty string. - pub levelup_description: String, + #[serde(rename="levelupDescription")] + pub localized_levelup_xml: String, /// Localized level up text of the card, in plain text. /// /// If the card has no level up text, contains an empty string. - pub levelup_description_raw: String, + #[serde(rename="levelupDescriptionRaw")] + pub localized_levelup_text: String, /// [Vec] with [Card::code]s of other cards associated with this one. /// @@ -110,9 +111,8 @@ pub struct Card { /// [Vec] with [Card::name]s 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, + pub(crate) associated_card_names_localized: Vec, /// Flavor text of the card, displayed when its image is inspected. pub flavor_text: String, @@ -135,7 +135,7 @@ pub struct Card { impl Card { - /// Get references to the cards associated with this one, given an hashmap of all cards. + /// Get references to the cards associated with this one, given an [HashMap] of cards indexed by code. pub fn associated_cards<'c, 'hm: 'c>(&'c self, hashmap: &'hm HashMap) -> impl Iterator> + 'c { self.associated_card_codes.iter().map(|r| hashmap.get(r)) } @@ -219,7 +219,7 @@ mod tests { regions: vec![ CardRegion::Runeterra ], - regions_localized: vec![ + localized_regions: vec![ String::from("Runeterra") ], art: vec![ @@ -232,13 +232,13 @@ mod tests { cost: 4u64, health: 5u64, spell_speed: SpellSpeed::None, - spell_speed_localized: String::from(""), + localized_spell_speed: String::from(""), keywords: vec![], - 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."), + localized_keywords: vec![], + localized_description_xml: String::from("Origin: Agony's Embrace.\r\nWhen I'm summoned, summon a random Husk."), + localized_description_text: String::from("Origin: Agony's Embrace.\r\nWhen I'm summoned, summon a random Husk."), + localized_levelup_xml: String::from("When you or an ally kill an allied Husk, give me its positive keywords this round and I level up."), + localized_levelup_text: 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"), diff --git a/src/schema/keyword.rs b/src/schema/setbundle/keyword.rs similarity index 99% rename from src/schema/keyword.rs rename to src/schema/setbundle/keyword.rs index 8501502..c578cfc 100644 --- a/src/schema/keyword.rs +++ b/src/schema/setbundle/keyword.rs @@ -4,7 +4,7 @@ /// /// 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). #[non_exhaustive] -#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub enum CardKeyword { /// Like [CardKeyword::Overwhelm], but on [super::CardType::Spell]s. /// diff --git a/src/schema/setbundle/mod.rs b/src/schema/setbundle/mod.rs new file mode 100644 index 0000000..4c8acb2 --- /dev/null +++ b/src/schema/setbundle/mod.rs @@ -0,0 +1,19 @@ +//! This module defines the types used in Data Dragon's [Set Bundle](https://developer.riotgames.com/docs/lor#data-dragon_set-bundles) `set.json` files. + +mod card; +mod art; +mod r#type; +mod rarity; +mod region; +mod set; +mod speed; +mod keyword; + +pub use card::Card; +pub use art::CardArt; +pub use r#type::CardType; +pub use rarity::CardRarity; +pub use region::CardRegion; +pub use set::CardSet; +pub use speed::SpellSpeed; +pub use keyword::CardKeyword; diff --git a/src/schema/rarity.rs b/src/schema/setbundle/rarity.rs similarity index 93% rename from src/schema/rarity.rs rename to src/schema/setbundle/rarity.rs index ef5560f..c7660a5 100644 --- a/src/schema/rarity.rs +++ b/src/schema/setbundle/rarity.rs @@ -1,7 +1,7 @@ //! Module defining [CardRarity]. /// A possible [super::Card] rarity. -#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub enum CardRarity { /// The card has no rarity, as it probably is not collectible. #[serde(alias = "")] diff --git a/src/schema/region.rs b/src/schema/setbundle/region.rs similarity index 96% rename from src/schema/region.rs rename to src/schema/setbundle/region.rs index 002a723..c8accec 100644 --- a/src/schema/region.rs +++ b/src/schema/setbundle/region.rs @@ -4,7 +4,7 @@ /// /// 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). #[non_exhaustive] -#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub enum CardRegion { /// Noxus. Noxus, diff --git a/src/schema/set.rs b/src/schema/setbundle/set.rs similarity index 95% rename from src/schema/set.rs rename to src/schema/setbundle/set.rs index fb32fe2..67b6513 100644 --- a/src/schema/set.rs +++ b/src/schema/setbundle/set.rs @@ -4,7 +4,7 @@ /// /// 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). #[non_exhaustive] -#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub enum CardSet { /// Foundations, or "base". #[serde(rename = "Set1")] diff --git a/src/schema/speed.rs b/src/schema/setbundle/speed.rs similarity index 92% rename from src/schema/speed.rs rename to src/schema/setbundle/speed.rs index 44801f3..7f8d1bf 100644 --- a/src/schema/speed.rs +++ b/src/schema/setbundle/speed.rs @@ -2,7 +2,7 @@ /// A possible spell speed. -#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub enum SpellSpeed { /// Non-spell cards have this speed. #[serde(rename = "")] diff --git a/src/schema/type.rs b/src/schema/setbundle/type.rs similarity index 94% rename from src/schema/type.rs rename to src/schema/setbundle/type.rs index f571070..940e90c 100644 --- a/src/schema/type.rs +++ b/src/schema/setbundle/type.rs @@ -5,7 +5,7 @@ /// /// Since more types might be added in the future, as it happened with landmarks, this enum is [non_exaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute). #[non_exhaustive] -#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub enum CardType { /// A spell. Spell,