2022-08-02 08:07:50 +00:00
|
|
|
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).
|
2022-07-31 18:32:58 +00:00
|
|
|
#[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:07:50 +00:00
|
|
|
/// Codes of other cards associated with this one.
|
2022-08-02 08:12:55 +00:00
|
|
|
///
|
|
|
|
/// 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.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub assets: Vec<Asset>,
|
2022-07-31 06:24:39 +00:00
|
|
|
|
2022-08-02 08:20:40 +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.
|
2022-08-02 08:22:14 +00:00
|
|
|
pub attack: u64,
|
2022-07-31 06:24:39 +00:00
|
|
|
/// Base cost of the card.
|
2022-08-02 08:22:14 +00:00
|
|
|
pub cost: u64,
|
2022-07-31 06:24:39 +00:00
|
|
|
/// Base health of the card.
|
2022-08-02 08:22:14 +00:00
|
|
|
pub health: u64,
|
2022-07-31 06:24:39 +00:00
|
|
|
|
|
|
|
/// Localized description of the card, in XML.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub description: String,
|
2022-07-31 06:24:39 +00:00
|
|
|
/// Localized description of the card, in plain text.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub description_raw: String,
|
2022-07-31 06:24:39 +00:00
|
|
|
|
|
|
|
/// Localized level up text of the card, in XML.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub levelup_description: String,
|
2022-07-31 06:24:39 +00:00
|
|
|
/// Localized level up text of the card, in plain text.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub levelup_description_raw: String,
|
2022-07-31 06:24:39 +00:00
|
|
|
|
|
|
|
/// Flavor text of the card, displayed when its image is inspected.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub flavor_text: String,
|
2022-07-31 06:24:39 +00:00
|
|
|
/// Name of the artist who drew the card.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub artist_name: String,
|
2022-07-31 06:24:39 +00:00
|
|
|
|
|
|
|
/// Localized name of the card.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub name: String,
|
2022-07-31 06:24:39 +00:00
|
|
|
/// Unique seven-character identifier of the card.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub card_code: String,
|
2022-07-31 06:24:39 +00:00
|
|
|
|
|
|
|
/// List of keywords of this card, with their localized names.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub keywords: Vec<String>,
|
2022-07-31 06:24:39 +00:00
|
|
|
/// List of keywords of this card, with their internal names.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub keyword_refs: Vec<String>,
|
2022-07-31 06:24:39 +00:00
|
|
|
|
|
|
|
/// Localized spell speed.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub spell_speed: String,
|
2022-07-31 06:24:39 +00:00
|
|
|
/// [SpellSpeed] of the card.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub spell_speed_ref: SpellSpeed,
|
2022-07-31 06:24:39 +00:00
|
|
|
|
|
|
|
/// Localized rarity of the card.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub rarity: String,
|
2022-07-31 06:24:39 +00:00
|
|
|
/// [CardRarity] of the card.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub rarity_ref: CardRarity,
|
2022-07-31 06:24:39 +00:00
|
|
|
|
|
|
|
/// The subtypes the card has, such as `PORO`.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub subtypes: Vec<String>,
|
2022-07-31 06:24:39 +00:00
|
|
|
/// The [CardSupertype] the card belongs to, such as `Champion`.
|
2022-08-01 02:22:05 +00:00
|
|
|
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.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub collectible: bool,
|
2022-07-31 06:24:39 +00:00
|
|
|
|
|
|
|
/// The [CardSet] the card belongs to.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub set: String,
|
2022-07-31 06:24:39 +00:00
|
|
|
|
|
|
|
#[serde(rename(serialize = "type", deserialize = "type"))]
|
2022-07-31 18:32:58 +00:00
|
|
|
pub card_type: CardType,
|
2022-07-31 06:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-02 08:07:50 +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 {
|
2022-08-02 08:12:55 +00:00
|
|
|
self.associated_card_codes.iter().map(|r| hashmap.get(r))
|
2022-08-02 08:07:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-08-02 08:20:40 +00:00
|
|
|
/// 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.
|
2022-07-31 18:32:58 +00:00
|
|
|
#[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.
|
2022-07-31 18:32:58 +00:00
|
|
|
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.
|
2022-07-31 18:32:58 +00:00
|
|
|
pub full_absolute_path: String,
|
2022-07-31 06:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Possible card types.
|
|
|
|
#[non_exhaustive]
|
2022-07-31 18:32:58 +00:00
|
|
|
#[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,
|
2022-07-31 18:32:58 +00:00
|
|
|
/// A trap or boon.
|
|
|
|
Trap,
|
2022-07-31 06:24:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// Possible card rarities.
|
|
|
|
#[non_exhaustive]
|
2022-07-31 18:32:58 +00:00
|
|
|
#[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]
|
2022-07-31 18:32:58 +00:00
|
|
|
#[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,
|
2022-07-31 10:51:09 +00:00
|
|
|
|
|
|
|
/// 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]
|
2022-07-31 18:32:58 +00:00
|
|
|
#[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,
|
2022-07-31 10:51:09 +00:00
|
|
|
#[serde(rename = "SetEvent")]
|
|
|
|
Events,
|
2022-07-31 06:24:39 +00:00
|
|
|
}
|