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

Run reformat code

This commit is contained in:
Steffo 2022-08-04 18:53:49 +02:00
parent d2b8eb4398
commit e346d3500a
Signed by: steffo
GPG key ID: 6965406171929D01
14 changed files with 63 additions and 45 deletions

View file

@ -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. //! 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::collections::HashMap;
use std::io::Read;
use crate::schema::corebundle::*; use crate::schema::corebundle::*;
use crate::schema::setbundle::*; use crate::schema::setbundle::*;
/// Deserialize a `globals.json` file into a [CoreGlobals] struct. /// Deserialize a `globals.json` file into a [CoreGlobals] struct.
pub fn globalsjson_to_coreglobals<R>(r: R) -> serde_json::Result<CoreGlobals> pub fn globalsjson_to_coreglobals<R>(r: R) -> serde_json::Result<CoreGlobals>
where R: Read where R: Read

View file

@ -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. //! 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 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. /// Deserialize a `set.json` file into a [Vec] of [Card]s.
pub fn setjson_to_cardvec<R>(r: R) -> serde_json::Result<Vec<Card>> pub fn setjson_to_cardvec<R>(r: R) -> serde_json::Result<Vec<Card>>
@ -27,10 +27,12 @@ pub fn cardvec_to_cardhashmap(v: Vec<Card>) -> HashMap<String, Card> {
#[allow(deprecated)] #[allow(deprecated)]
mod tests { mod tests {
use std::collections::HashMap; use std::collections::HashMap;
use super::setjson_to_cardvec;
use super::cardvec_to_cardhashmap;
use crate::schema::setbundle::*; use crate::schema::setbundle::*;
use super::cardvec_to_cardhashmap;
use super::setjson_to_cardvec;
const TEST_SETJSON: &str = r#" 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(), 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(), artist_name: "SIXMOREVODKA".to_string(),
subtypes: vec![], subtypes: vec![],
supertype: "".to_string() supertype: "".to_string(),
} }
} }
@ -181,7 +183,7 @@ mod tests {
art: vec![ art: vec![
CardArt { CardArt {
card_png: "http://dd.b.pvp.net/3_11_0/set1/en_us/img/cards/01IO012T2.png".to_string(), 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, attack: 0,
@ -204,7 +206,7 @@ mod tests {
flavor_text: "".to_string(), flavor_text: "".to_string(),
artist_name: "SIXMOREVODKA".to_string(), artist_name: "SIXMOREVODKA".to_string(),
subtypes: vec![], subtypes: vec![],
supertype: "".to_string() supertype: "".to_string(),
} }
} }

View file

@ -1,9 +1,8 @@
use super::vocabterm::CoreVocabTerm;
use super::keyword::CoreKeyword; use super::keyword::CoreKeyword;
use super::rarity::CoreRarity;
use super::region::CoreRegion; use super::region::CoreRegion;
use super::speed::CoreSpellSpeed; use super::speed::CoreSpellSpeed;
use super::rarity::CoreRarity; use super::vocabterm::CoreVocabTerm;
/// A complete `globals.json` file. /// A complete `globals.json` file.
/// ///

View file

@ -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. //! 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 globals;
mod vocabterm; mod vocabterm;
mod keyword; mod keyword;
@ -8,10 +16,3 @@ mod speed;
mod rarity; mod rarity;
mod set; 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;

View file

@ -1,5 +1,6 @@
//! This module defines [CoreVocabTerm]. //! This module defines [CoreVocabTerm].
/// A Legends of Runeterra vocabulary term, and its associated localization. /// A Legends of Runeterra vocabulary term, and its associated localization.
/// ///
/// I'm not sure where these are used, other than in in-game tooltips. /// I'm not sure where these are used, other than in in-game tooltips.

View file

@ -1,5 +1,6 @@
//! Module defining [CardArt]. //! Module defining [CardArt].
/// An art asset associated with a [super::Card]. /// An art asset associated with a [super::Card].
#[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)] #[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct CardArt { pub struct CardArt {

View file

@ -2,12 +2,11 @@
use std::collections::HashMap; use std::collections::HashMap;
use crate::schema::corebundle::*;
use super::*; use super::*;
/// A single Legends of Runeterra card. /// 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. /// 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)] #[derive(Clone, Debug, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct Card { pub struct Card {
@ -19,7 +18,7 @@ pub struct Card {
pub name: String, pub name: String,
/// The [CardType] of the card. /// The [CardType] of the card.
/// ///
/// The `r#` prefix is required by the Rust syntax, since `type` is a reserved keyword. /// The `r#` prefix is required by the Rust syntax, since `type` is a reserved keyword.
#[serde(rename = "type")] #[serde(rename = "type")]
pub r#type: CardType, pub r#type: CardType,
@ -38,6 +37,7 @@ pub struct Card {
/// Regions this card belongs to. /// Regions this card belongs to.
#[serde(rename = "regionRefs")] #[serde(rename = "regionRefs")]
pub regions: Vec<CardRegion>, pub regions: Vec<CardRegion>,
/// Localized names of the regions this card belongs to. /// Localized names of the regions this card belongs to.
/// ///
/// For serialization purposes only, use the [method with the same name](Card::localized_regions()] instead! /// 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. /// [SpellSpeed] of the card.
#[serde(rename = "spellSpeedRef")] #[serde(rename = "spellSpeedRef")]
pub spell_speed: SpellSpeed, pub spell_speed: SpellSpeed,
/// Localized name of the [SpellSpeed] of the card. /// Localized name of the [SpellSpeed] of the card.
/// ///
/// For serialization purposes only, use the [method with the same name](Card::localized_spell_speed()] instead! /// 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, pub(crate) localized_spell_speed: String,
/// [Vec] of [CardKeyword]s of the card. /// [Vec] of [CardKeyword]s of the card.
#[serde(rename="keywordRefs")] #[serde(rename = "keywordRefs")]
pub keywords: Vec<CardKeyword>, pub keywords: Vec<CardKeyword>,
/// [Vec] of localized names of [CardKeyword]s of the card. /// [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! /// 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<String>, pub(crate) localized_keywords: Vec<String>,
/// Localized description of the card, in pseudo-XML. /// Localized description of the card, in pseudo-XML.
#[serde(rename="description")] #[serde(rename = "description")]
pub localized_description_xml: String, pub localized_description_xml: String,
/// Localized description of the card, in plain text. /// Localized description of the card, in plain text.
#[serde(rename="descriptionRaw")] #[serde(rename = "descriptionRaw")]
pub localized_description_text: String, pub localized_description_text: String,
/// Localized level up text of the card, in pseudo-XML. /// Localized level up text of the card, in pseudo-XML.
/// ///
/// If the card has no level up text, contains an empty string. /// If the card has no level up text, contains an empty string.
#[serde(rename="levelupDescription")] #[serde(rename = "levelupDescription")]
pub localized_levelup_xml: String, pub localized_levelup_xml: String,
/// Localized level up text of the card, in plain text. /// Localized level up text of the card, in plain text.
/// ///
/// If the card has no level up text, contains an empty string. /// If the card has no level up text, contains an empty string.
#[serde(rename="levelupDescriptionRaw")] #[serde(rename = "levelupDescriptionRaw")]
pub localized_levelup_text: String, pub localized_levelup_text: String,
/// [Vec] with [Card::code]s of other cards associated with this one. /// [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]. /// To access references to the cards themselves, use [Card::associated_cards].
#[serde(rename = "associatedCardRefs")] #[serde(rename = "associatedCardRefs")]
pub associated_card_codes: Vec<String>, pub associated_card_codes: Vec<String>,
/// [Vec] with [Card::name]s of other cards associated with this one. /// [Vec] with [Card::name]s of other cards associated with this one.
/// ///
/// Sometimes, it may be missing some references. /// 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. /// Flavor text of the card, displayed when its image is inspected.
pub flavor_text: String, pub flavor_text: String,
/// Name of the artist who drew the card. /// Name of the artist who drew the card.
pub artist_name: String, pub artist_name: String,
/// The subtypes the card has, such as `"PORO"`. /// The subtypes the card has, such as `"PORO"`.
/// ///
/// Beware of Riot's inconsistent capitalization! /// Beware of Riot's inconsistent capitalization!
/// ///
/// TODO: Make this a enum. /// TODO: Make this a enum.
pub subtypes: Vec<String>, pub subtypes: Vec<String>,
/// The supertype the card belongs to, such as `"Champion"`. /// The supertype the card belongs to, such as `"Champion"`.
/// ///
/// Beware of Riot's inconsistent capitalization! /// Beware of Riot's inconsistent capitalization!
/// ///
/// TODO: Make this a enum. /// TODO: Make this a enum.
pub supertype: String, pub supertype: String,
} }
@ -156,11 +163,11 @@ impl Card {
mod tests { mod tests {
use super::Card; use super::Card;
use super::super::art::CardArt; use super::super::art::CardArt;
use super::super::r#type::CardType;
use super::super::rarity::CardRarity; use super::super::rarity::CardRarity;
use super::super::region::CardRegion; use super::super::region::CardRegion;
use super::super::set::CardSet; use super::super::set::CardSet;
use super::super::speed::SpellSpeed; use super::super::speed::SpellSpeed;
use super::super::r#type::CardType;
#[test] #[test]
fn deserialize_card() { fn deserialize_card() {

View file

@ -1,5 +1,6 @@
//! Module defining [CardKeyword]. //! Module defining [CardKeyword].
/// 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).
@ -252,7 +253,7 @@ pub enum CardKeyword {
/// Quick Attack. /// Quick Attack.
/// ///
/// > While attacking, strikes before its blocker. /// > While attacking, strikes before its blocker.
#[serde(rename="QuickStrike")] #[serde(rename = "QuickStrike")]
QuickAttack, QuickAttack,
/// Tough. /// Tough.
@ -303,7 +304,7 @@ pub enum CardKeyword {
/// Lurk. /// Lurk.
/// ///
/// > When you attack while I'm on top of your deck, I Lurk, granting Lurker allies everywhere +1|+0. Max once per round. /// > 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, Lurk,
/// Formidable. /// Formidable.

View file

@ -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. //! 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 card;
mod art; mod art;
mod r#type; mod r#type;
@ -9,11 +18,3 @@ mod set;
mod speed; mod speed;
mod keyword; 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;

View file

@ -1,5 +1,6 @@
//! Module defining [CardRarity]. //! Module defining [CardRarity].
/// 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 {

View file

@ -1,5 +1,6 @@
//! Module defining [CardRegion]. //! Module defining [CardRegion].
/// 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).

View file

@ -1,5 +1,6 @@
//! Module defining [CardSet]. //! Module defining [CardSet].
/// 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).

View file

@ -28,7 +28,7 @@ pub enum CardType {
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::CardType; use super::CardType;
macro_rules! test_deserialization { macro_rules! test_deserialization {
( $id:ident, $src:literal, $res:expr ) => { ( $id:ident, $src:literal, $res:expr ) => {
#[test] #[test]

View file

@ -1 +1,3 @@
//! This module implements full-text search on [crate::schema::Card]s of multiple locales. //! This module implements full-text search on [crate::schema::Card]s of multiple locales.
mod card;