From 0f25aaebc43cb3a35f302d434d1389b1264101d9 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 2 Aug 2022 10:07:50 +0200 Subject: [PATCH] Refactor `associated_cards` so that only codes are kept --- src/data/schema.rs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/data/schema.rs b/src/data/schema.rs index 91c2c47..227ff30 100644 --- a/src/data/schema.rs +++ b/src/data/schema.rs @@ -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). #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] #[serde(rename_all="camelCase")] pub struct Card { - /// Localized names of the cards associated with this one. - /// For some reason, might not match what is contained in `associated_card_refs`. - pub associated_cards: Vec, - /// `card_code`s of the cards associated with this one. + /// Codes of other cards associated with this one. + /// To access pub associated_card_refs: Vec, /// 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) -> impl Iterator> + 'c { + self.associated_card_refs.iter().map(|r| hashmap.get(r)) + } +} + + /// An art asset associated with a given card. #[derive(serde::Serialize, serde::Deserialize, Clone, Debug)] #[serde(rename_all="camelCase")]