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

193 lines
5.1 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 {
2022-08-02 08:26:31 +00:00
/// Codes of other cards associated with this one.
///
/// To access references to the cards themselves, use [associated_cards].
#[serde(rename = "associated_card_refs")]
pub associated_card_codes: 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
/// Regions this card belongs to.
#[serde(rename = "region_refs")]
pub regions: Vec<CardRegion>,
2022-07-31 06:24:39 +00:00
/// Base attack of the card.
pub attack: u64,
2022-07-31 06:24:39 +00:00
/// Base cost of the card.
pub cost: u64,
2022-07-31 06:24:39 +00:00
/// Base health of the card.
pub health: u64,
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.
2022-08-02 08:26:31 +00:00
#[serde(rename = "card_code")]
pub 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_codes.iter().map(|r| hashmap.get(r))
}
}
/// Regions to which cards can belong to.
#[non_exhaustive]
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
pub enum CardRegion {
Noxus,
Demacia,
Freljord,
ShadowIsles,
Targon,
Ionia,
Shurima,
PiltoverZaun,
BandleCity,
// I'm not sure what this region is for.
Runeterra,
Jhin,
Evelynn,
Bard,
}
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
}