mirror of
https://github.com/Steffo99/patched-porobot.git
synced 2024-12-22 17:44:22 +00:00
Refactor data loading
This commit is contained in:
parent
dc3203388f
commit
d2b8eb4398
21 changed files with 515 additions and 290 deletions
64
src/load/corebundle.rs
Normal file
64
src/load/corebundle.rs
Normal file
|
@ -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: R) -> serde_json::Result<CoreGlobals>
|
||||
where R: Read
|
||||
{
|
||||
serde_json::de::from_reader::<R, CoreGlobals>(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<CoreVocabTerm>) -> HashMap<String, CoreVocabTerm> {
|
||||
let mut hm = HashMap::<String, CoreVocabTerm>::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<CoreKeyword>) -> HashMap<CardKeyword, CoreKeyword> {
|
||||
let mut hm = HashMap::<CardKeyword, CoreKeyword>::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<CoreRegion>) -> HashMap<CardRegion, CoreRegion> {
|
||||
let mut hm = HashMap::<CardRegion, CoreRegion>::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<CoreSpellSpeed>) -> HashMap<SpellSpeed, CoreSpellSpeed> {
|
||||
let mut hm = HashMap::<SpellSpeed, CoreSpellSpeed>::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<CoreRarity>) -> HashMap<CardRarity, CoreRarity> {
|
||||
let mut hm = HashMap::<CardRarity, CoreRarity>::new();
|
||||
for rarity in v {
|
||||
hm.insert(rarity.rarity, rarity);
|
||||
}
|
||||
hm
|
||||
}
|
239
src/load/mod.rs
239
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: R) -> serde_json::Result<Vec<Card>>
|
||||
where R: Read
|
||||
{
|
||||
serde_json::de::from_reader::<R, Vec<Card>>(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: R) -> serde_json::Result<HashMap<String, Card>>
|
||||
where R: Read
|
||||
{
|
||||
let vec = vec_from_reader(r)?;
|
||||
let mut hm = HashMap::<String, Card>::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<String, Card> {
|
||||
let mut hm = HashMap::<String, Card>::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()
|
||||
)
|
||||
}
|
||||
}
|
||||
pub mod corebundle;
|
||||
pub mod setbundle;
|
||||
|
|
237
src/load/setbundle.rs
Normal file
237
src/load/setbundle.rs
Normal file
|
@ -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: R) -> serde_json::Result<Vec<Card>>
|
||||
where R: Read
|
||||
{
|
||||
serde_json::de::from_reader::<R, Vec<Card>>(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<Card>) -> HashMap<String, Card> {
|
||||
let mut hm = HashMap::<String, Card>::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<Card> {
|
||||
vec![expected_card_1(), expected_card_2()]
|
||||
}
|
||||
|
||||
fn expected_hashmap() -> HashMap<String, Card> {
|
||||
let mut hm = HashMap::<String, Card>::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()
|
||||
)
|
||||
}
|
||||
}
|
29
src/schema/corebundle/globals.rs
Normal file
29
src/schema/corebundle/globals.rs
Normal file
|
@ -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<CoreVocabTerm>,
|
||||
|
||||
/// A [Vec] of all [CoreKeyword]s in the game.
|
||||
pub keywords: Vec<CoreKeyword>,
|
||||
|
||||
/// A [Vec] of all [CoreRegion]s in the game.
|
||||
pub regions: Vec<CoreRegion>,
|
||||
|
||||
/// A [Vec] of all [CoreSpellSpeed]s in the game.
|
||||
#[serde(rename = "spellSpeeds")]
|
||||
pub spell_speeds: Vec<CoreSpellSpeed>,
|
||||
|
||||
/// A [Vec] of all [CoreRarity]s in the game.
|
||||
pub rarities: Vec<CoreRarity>,
|
||||
}
|
17
src/schema/corebundle/keyword.rs
Normal file
17
src/schema/corebundle/keyword.rs
Normal file
|
@ -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,
|
||||
}
|
17
src/schema/corebundle/mod.rs
Normal file
17
src/schema/corebundle/mod.rs
Normal file
|
@ -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;
|
14
src/schema/corebundle/rarity.rs
Normal file
14
src/schema/corebundle/rarity.rs
Normal file
|
@ -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,
|
||||
}
|
23
src/schema/corebundle/region.rs
Normal file
23
src/schema/corebundle/region.rs
Normal file
|
@ -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,
|
||||
}
|
18
src/schema/corebundle/set.rs
Normal file
18
src/schema/corebundle/set.rs
Normal file
|
@ -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,
|
||||
}
|
14
src/schema/corebundle/speed.rs
Normal file
14
src/schema/corebundle/speed.rs
Normal file
|
@ -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,
|
||||
}
|
21
src/schema/corebundle/vocabterm.rs
Normal file
21
src/schema/corebundle/vocabterm.rs
Normal file
|
@ -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,
|
||||
}
|
|
@ -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;
|
||||
|
|
|
@ -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.
|
||||
///
|
|
@ -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<CardRegion>,
|
||||
/// 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<String>,
|
||||
pub(crate) localized_regions: Vec<String>,
|
||||
|
||||
/// 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<CardKeyword>,
|
||||
/// [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<String>,
|
||||
pub(crate) localized_keywords: Vec<String>,
|
||||
|
||||
/// 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<String>,
|
||||
pub(crate) associated_card_names_localized: Vec<String>,
|
||||
|
||||
/// 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<String, Card>) -> impl Iterator<Item=Option<&'hm Card>> + '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("<link=vocab.Origin><style=Vocab>Origin</style></link>: <link=card.origin><style=AssociatedCard>Agony's Embrace</style></link>.\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("<link=vocab.Origin><style=Vocab>Origin</style></link>: <link=card.origin><style=AssociatedCard>Agony's Embrace</style></link>.\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"),
|
|
@ -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.
|
||||
///
|
19
src/schema/setbundle/mod.rs
Normal file
19
src/schema/setbundle/mod.rs
Normal file
|
@ -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;
|
|
@ -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 = "")]
|
|
@ -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,
|
|
@ -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")]
|
|
@ -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 = "")]
|
|
@ -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,
|
Loading…
Reference in a new issue