diff --git a/src/load/corebundle.rs b/src/load/corebundle.rs index 2c8d7ea..b15788a 100644 --- a/src/load/corebundle.rs +++ b/src/load/corebundle.rs @@ -1,11 +1,11 @@ //! 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 std::io::Read; + 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 diff --git a/src/load/setbundle.rs b/src/load/setbundle.rs index e4e6823..1173d68 100644 --- a/src/load/setbundle.rs +++ b/src/load/setbundle.rs @@ -1,9 +1,9 @@ //! 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::*; +use std::io::Read; +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> @@ -27,10 +27,12 @@ pub fn cardvec_to_cardhashmap(v: Vec) -> HashMap { #[allow(deprecated)] mod tests { use std::collections::HashMap; - use super::setjson_to_cardvec; - use super::cardvec_to_cardhashmap; + use crate::schema::setbundle::*; + use super::cardvec_to_cardhashmap; + use super::setjson_to_cardvec; + const TEST_SETJSON: &str = r#" [ { @@ -160,7 +162,7 @@ mod tests { 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() + supertype: "".to_string(), } } @@ -181,7 +183,7 @@ mod tests { 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() + full_png: "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012T2-full.png".to_string(), } ], attack: 0, @@ -204,7 +206,7 @@ mod tests { flavor_text: "".to_string(), artist_name: "SIXMOREVODKA".to_string(), subtypes: vec![], - supertype: "".to_string() + supertype: "".to_string(), } } diff --git a/src/schema/corebundle/globals.rs b/src/schema/corebundle/globals.rs index 9dcf856..122a524 100644 --- a/src/schema/corebundle/globals.rs +++ b/src/schema/corebundle/globals.rs @@ -1,9 +1,8 @@ -use super::vocabterm::CoreVocabTerm; use super::keyword::CoreKeyword; +use super::rarity::CoreRarity; use super::region::CoreRegion; use super::speed::CoreSpellSpeed; -use super::rarity::CoreRarity; - +use super::vocabterm::CoreVocabTerm; /// A complete `globals.json` file. /// diff --git a/src/schema/corebundle/mod.rs b/src/schema/corebundle/mod.rs index 4faaea7..4ba16fd 100644 --- a/src/schema/corebundle/mod.rs +++ b/src/schema/corebundle/mod.rs @@ -1,5 +1,13 @@ //! 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. +pub use globals::CoreGlobals; +pub use keyword::CoreKeyword; +pub use rarity::CoreRarity; +pub use region::CoreRegion; +pub use set::CoreSet; +pub use speed::CoreSpellSpeed; +pub use vocabterm::CoreVocabTerm; + mod globals; mod vocabterm; mod keyword; @@ -8,10 +16,3 @@ 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/vocabterm.rs b/src/schema/corebundle/vocabterm.rs index 3b67867..ddf8580 100644 --- a/src/schema/corebundle/vocabterm.rs +++ b/src/schema/corebundle/vocabterm.rs @@ -1,5 +1,6 @@ //! 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. diff --git a/src/schema/setbundle/art.rs b/src/schema/setbundle/art.rs index ff000cb..4634f5b 100644 --- a/src/schema/setbundle/art.rs +++ b/src/schema/setbundle/art.rs @@ -1,5 +1,6 @@ //! Module defining [CardArt]. + /// An art asset associated with a [super::Card]. #[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub struct CardArt { diff --git a/src/schema/setbundle/card.rs b/src/schema/setbundle/card.rs index 921088d..47b972c 100644 --- a/src/schema/setbundle/card.rs +++ b/src/schema/setbundle/card.rs @@ -2,12 +2,11 @@ use std::collections::HashMap; -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, Hash, serde::Serialize, serde::Deserialize)] pub struct Card { @@ -19,7 +18,7 @@ pub struct Card { pub name: String, /// The [CardType] of the card. - /// + /// /// The `r#` prefix is required by the Rust syntax, since `type` is a reserved keyword. #[serde(rename = "type")] pub r#type: CardType, @@ -38,6 +37,7 @@ pub struct Card { /// Regions this card belongs to. #[serde(rename = "regionRefs")] pub regions: Vec, + /// Localized names of the regions this card belongs to. /// /// For serialization purposes only, use the [method with the same name](Card::localized_regions()] instead! @@ -70,6 +70,7 @@ pub struct Card { /// [SpellSpeed] of the card. #[serde(rename = "spellSpeedRef")] pub spell_speed: SpellSpeed, + /// Localized name of the [SpellSpeed] of the card. /// /// For serialization purposes only, use the [method with the same name](Card::localized_spell_speed()] instead! @@ -77,30 +78,33 @@ pub struct Card { pub(crate) localized_spell_speed: String, /// [Vec] of [CardKeyword]s of the card. - #[serde(rename="keywordRefs")] + #[serde(rename = "keywordRefs")] pub keywords: Vec, + /// [Vec] of localized names of [CardKeyword]s of the card. /// /// For serialization purposes only, use the [method with the same name](Card::localized_keywords()] instead! - #[serde(rename="keywords")] + #[serde(rename = "keywords")] pub(crate) localized_keywords: Vec, /// Localized description of the card, in pseudo-XML. - #[serde(rename="description")] + #[serde(rename = "description")] pub localized_description_xml: String, + /// Localized description of the card, in plain text. - #[serde(rename="descriptionRaw")] + #[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. - #[serde(rename="levelupDescription")] + #[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. - #[serde(rename="levelupDescriptionRaw")] + #[serde(rename = "levelupDescriptionRaw")] pub localized_levelup_text: String, /// [Vec] with [Card::code]s of other cards associated with this one. @@ -108,6 +112,7 @@ pub struct Card { /// To access references to the cards themselves, use [Card::associated_cards]. #[serde(rename = "associatedCardRefs")] pub associated_card_codes: Vec, + /// [Vec] with [Card::name]s of other cards associated with this one. /// /// Sometimes, it may be missing some references. @@ -116,19 +121,21 @@ pub struct Card { /// Flavor text of the card, displayed when its image is inspected. pub flavor_text: String, + /// Name of the artist who drew the card. pub artist_name: String, /// The subtypes the card has, such as `"PORO"`. - /// + /// /// Beware of Riot's inconsistent capitalization! - /// + /// /// TODO: Make this a enum. pub subtypes: Vec, + /// The supertype the card belongs to, such as `"Champion"`. - /// + /// /// Beware of Riot's inconsistent capitalization! - /// + /// /// TODO: Make this a enum. pub supertype: String, } @@ -156,11 +163,11 @@ impl Card { mod tests { use super::Card; use super::super::art::CardArt; + use super::super::r#type::CardType; 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() { diff --git a/src/schema/setbundle/keyword.rs b/src/schema/setbundle/keyword.rs index c578cfc..f7f89d5 100644 --- a/src/schema/setbundle/keyword.rs +++ b/src/schema/setbundle/keyword.rs @@ -1,5 +1,6 @@ //! Module defining [CardKeyword]. + /// 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). @@ -252,7 +253,7 @@ pub enum CardKeyword { /// Quick Attack. /// /// > While attacking, strikes before its blocker. - #[serde(rename="QuickStrike")] + #[serde(rename = "QuickStrike")] QuickAttack, /// Tough. @@ -303,7 +304,7 @@ pub enum CardKeyword { /// Lurk. /// /// > When you attack while I'm on top of your deck, I Lurk, granting Lurker allies everywhere +1|+0. Max once per round. - #[serde(rename="Lurker")] + #[serde(rename = "Lurker")] Lurk, /// Formidable. diff --git a/src/schema/setbundle/mod.rs b/src/schema/setbundle/mod.rs index 4c8acb2..f8346a5 100644 --- a/src/schema/setbundle/mod.rs +++ b/src/schema/setbundle/mod.rs @@ -1,5 +1,14 @@ //! 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. +pub use art::CardArt; +pub use card::Card; +pub use keyword::CardKeyword; +pub use r#type::CardType; +pub use rarity::CardRarity; +pub use region::CardRegion; +pub use set::CardSet; +pub use speed::SpellSpeed; + mod card; mod art; mod r#type; @@ -9,11 +18,3 @@ 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/setbundle/rarity.rs b/src/schema/setbundle/rarity.rs index c7660a5..88cad02 100644 --- a/src/schema/setbundle/rarity.rs +++ b/src/schema/setbundle/rarity.rs @@ -1,5 +1,6 @@ //! Module defining [CardRarity]. + /// A possible [super::Card] rarity. #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] pub enum CardRarity { diff --git a/src/schema/setbundle/region.rs b/src/schema/setbundle/region.rs index c8accec..8a3ef68 100644 --- a/src/schema/setbundle/region.rs +++ b/src/schema/setbundle/region.rs @@ -1,5 +1,6 @@ //! Module defining [CardRegion]. + /// 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). diff --git a/src/schema/setbundle/set.rs b/src/schema/setbundle/set.rs index 67b6513..bb75af1 100644 --- a/src/schema/setbundle/set.rs +++ b/src/schema/setbundle/set.rs @@ -1,5 +1,6 @@ //! Module defining [CardSet]. + /// 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). diff --git a/src/schema/setbundle/type.rs b/src/schema/setbundle/type.rs index 940e90c..49aba52 100644 --- a/src/schema/setbundle/type.rs +++ b/src/schema/setbundle/type.rs @@ -28,7 +28,7 @@ pub enum CardType { #[cfg(test)] mod tests { use super::CardType; - + macro_rules! test_deserialization { ( $id:ident, $src:literal, $res:expr ) => { #[test] diff --git a/src/search/mod.rs b/src/search/mod.rs index fc7e124..4579909 100644 --- a/src/search/mod.rs +++ b/src/search/mod.rs @@ -1 +1,3 @@ //! This module implements full-text search on [crate::schema::Card]s of multiple locales. + +mod card; \ No newline at end of file