1
Fork 0
mirror of https://github.com/Steffo99/patched-porobot.git synced 2024-12-23 10:04:21 +00:00

Refactor associated_cards so that only codes are kept

This commit is contained in:
Steffo 2022-08-02 10:07:50 +02:00
parent 1e7230994a
commit 0f25aaebc4
Signed by: steffo
GPG key ID: 6965406171929D01

View file

@ -1,11 +1,11 @@
use std::collections::HashMap;
/// A single Legends of Runeterra card as represented in the data files from [Data Dragon](https://developer.riotgames.com/docs/lor). /// 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)] #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
#[serde(rename_all="camelCase")] #[serde(rename_all="camelCase")]
pub struct Card { pub struct Card {
/// Localized names of the cards associated with this one. /// Codes of other cards associated with this one.
/// For some reason, might not match what is contained in `associated_card_refs`. /// To access
pub associated_cards: Vec<String>,
/// `card_code`s of the cards associated with this one.
pub associated_card_refs: Vec<String>, pub associated_card_refs: Vec<String>,
/// Art assets of this card. /// Art assets of this card.
@ -75,6 +75,14 @@ pub struct Card {
} }
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))
}
}
/// An art asset associated with a given card. /// An art asset associated with a given card.
#[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)]
#[serde(rename_all="camelCase")] #[serde(rename_all="camelCase")]