1
Fork 0
mirror of https://github.com/Steffo99/patched-porobot.git synced 2024-12-24 10:34:20 +00:00
patched-porobot/src/data/schema.rs

167 lines
4.7 KiB
Rust
Raw Normal View History

use std::collections::HashMap;
2022-07-31 06:24:39 +00:00
/// A single Legends of Runeterra card as represented in the data files from [Data Dragon](https://developer.riotgames.com/docs/lor).
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
2022-07-31 06:24:39 +00:00
#[serde(rename_all="camelCase")]
2022-07-31 06:47:01 +00:00
pub struct Card {
/// Codes of other cards associated with this one.
/// To access
pub associated_card_refs: Vec<String>,
2022-07-31 06:24:39 +00:00
/// Art assets of this card.
pub assets: Vec<Asset>,
2022-07-31 06:24:39 +00:00
/// Localized names of the regions this card belongs to.
pub regions: Vec<String>,
2022-07-31 06:24:39 +00:00
/// IDs of the regions this card belongs to.
pub region_refs: Vec<String>,
2022-07-31 06:24:39 +00:00
/// Base attack of the card.
pub attack: i8,
2022-07-31 06:24:39 +00:00
/// Base cost of the card.
pub cost: i8,
2022-07-31 06:24:39 +00:00
/// Base health of the card.
pub health: i8,
2022-07-31 06:24:39 +00:00
/// Localized description of the card, in XML.
pub description: String,
2022-07-31 06:24:39 +00:00
/// Localized description of the card, in plain text.
pub description_raw: String,
2022-07-31 06:24:39 +00:00
/// Localized level up text of the card, in XML.
pub levelup_description: String,
2022-07-31 06:24:39 +00:00
/// Localized level up text of the card, in plain text.
pub levelup_description_raw: String,
2022-07-31 06:24:39 +00:00
/// Flavor text of the card, displayed when its image is inspected.
pub flavor_text: String,
2022-07-31 06:24:39 +00:00
/// Name of the artist who drew the card.
pub artist_name: String,
2022-07-31 06:24:39 +00:00
/// Localized name of the card.
pub name: String,
2022-07-31 06:24:39 +00:00
/// Unique seven-character identifier of the card.
pub card_code: String,
2022-07-31 06:24:39 +00:00
/// List of keywords of this card, with their localized names.
pub keywords: Vec<String>,
2022-07-31 06:24:39 +00:00
/// List of keywords of this card, with their internal names.
pub keyword_refs: Vec<String>,
2022-07-31 06:24:39 +00:00
/// Localized spell speed.
pub spell_speed: String,
2022-07-31 06:24:39 +00:00
/// [SpellSpeed] of the card.
pub spell_speed_ref: SpellSpeed,
2022-07-31 06:24:39 +00:00
/// Localized rarity of the card.
pub rarity: String,
2022-07-31 06:24:39 +00:00
/// [CardRarity] of the card.
pub rarity_ref: CardRarity,
2022-07-31 06:24:39 +00:00
/// The subtypes the card has, such as `PORO`.
pub subtypes: Vec<String>,
2022-07-31 06:24:39 +00:00
/// The [CardSupertype] the card belongs to, such as `Champion`.
pub supertype: String,
2022-07-31 06:24:39 +00:00
/// If `true`, the card can be found in chests, crafted, or used in decks.
/// If `false`, the card is not available for direct use, as it is probably created by another card.
pub collectible: bool,
2022-07-31 06:24:39 +00:00
/// The [CardSet] the card belongs to.
pub set: String,
2022-07-31 06:24:39 +00:00
#[serde(rename(serialize = "type", deserialize = "type"))]
pub card_type: CardType,
2022-07-31 06:24:39 +00:00
}
impl Card {
/// Get references to the cards associated with this one, given an hashmap of all cards.
pub fn associated_cards<'c, 'hm: 'c>(&'c self, hashmap: &'hm HashMap<String, Card>) -> impl Iterator<Item=Option<&'hm Card>> + 'c {
self.associated_card_refs.iter().map(|r| hashmap.get(r))
}
}
2022-07-31 06:24:39 +00:00
/// An art asset associated with a given card.
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
2022-07-31 06:24:39 +00:00
#[serde(rename_all="camelCase")]
2022-07-31 06:47:01 +00:00
pub struct Asset {
2022-07-31 06:24:39 +00:00
/// URL to the card art as it is displayed in-game.
pub game_absolute_path: String,
2022-07-31 06:24:39 +00:00
/// URL to the full-size card art as it is displayed when the card is inspected.
pub full_absolute_path: String,
2022-07-31 06:24:39 +00:00
}
/// Possible card types.
#[non_exhaustive]
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
2022-07-31 06:47:01 +00:00
pub enum CardType {
2022-07-31 06:24:39 +00:00
/// A spell.
Spell,
/// An unit: either a minion, or a champion.
/// Champions have their `supertype` set to `Champion`.
Unit,
/// An ability triggered by an unit.
Ability,
/// A landmark.
Landmark,
/// A trap or boon.
Trap,
2022-07-31 06:24:39 +00:00
}
/// Possible card rarities.
#[non_exhaustive]
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
2022-07-31 06:47:01 +00:00
pub enum CardRarity {
2022-07-31 06:24:39 +00:00
#[serde(alias = "NONE")]
None,
#[serde(alias = "COMMON")]
Common,
#[serde(alias = "RARE")]
Rare,
#[serde(alias = "EPIC")]
Epic,
#[serde(alias = "CHAMPION")]
Champion,
}
/// Possible spell speeds.
#[non_exhaustive]
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
2022-07-31 06:47:01 +00:00
pub enum SpellSpeed {
2022-07-31 06:24:39 +00:00
/// Non-spell cards have this speed.
#[serde(alias = "")]
None,
Slow,
Fast,
/// Both Focus and Burst cards have `Burst` speed; to disambiguate between the two, check for the `Focus` keyword.
2022-07-31 06:24:39 +00:00
Burst,
}
/// Release sets [Card]s may belong to.
#[non_exhaustive]
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
2022-07-31 06:47:01 +00:00
pub enum CardSet {
2022-07-31 06:24:39 +00:00
#[serde(rename = "Set1")]
Foundations,
#[serde(rename = "Set2")]
RisingTides,
#[serde(rename = "Set3")]
CallOfTheMountain,
#[serde(rename = "Set4")]
EmpiresOfTheAscended,
#[serde(rename = "Set5")]
BeyondTheBandlewood,
#[serde(rename = "Set6")]
Worldwalker,
#[serde(rename = "SetEvent")]
Events,
2022-07-31 06:24:39 +00:00
}