diff options
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/equipment.rs | 13 | ||||
| -rw-r--r-- | src/components/inventory.rs | 7 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/components/equipment.rs b/src/components/equipment.rs index ab573d8..e7c9734 100644 --- a/src/components/equipment.rs +++ b/src/components/equipment.rs @@ -5,6 +5,9 @@ use specs::{ Component, HashMapStorage }; +use crate::{ + Sprite +}; #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] @@ -46,7 +49,8 @@ impl Stat { #[derive(Debug, Clone, PartialEq)] pub struct Equippable { pub slot: Slot, - pub stats: HashMap<Stat, i64> + pub stats: HashMap<Stat, i64>, + pub sprite: Option<Sprite> } impl Equippable { @@ -60,7 +64,10 @@ impl Equippable { .map(|(k, v)| Some((Stat::from_str(k.as_str())?, v.as_i64()?)) ) - .collect::<Option<HashMap<Stat, i64>>>()? + .collect::<Option<HashMap<Stat, i64>>>()?, + sprite: if let Some(spr) = val.get("sprite") { + Some(Sprite{name: spr.as_str()?.to_string()}) + } else {None} }) } } @@ -101,7 +108,7 @@ mod tests { fn equippable_from_json() { assert_eq!( Equippable::from_json(&json!({"slot": "hand", "stats": {"strength": 10}})), - Some(Equippable {slot: Slot::Hand, stats: hashmap!(Stat::Strength => 10)}) + Some(Equippable {slot: Slot::Hand, stats: hashmap!(Stat::Strength => 10), sprite: None}) ); } diff --git a/src/components/inventory.rs b/src/components/inventory.rs index fa65b03..dc308bf 100644 --- a/src/components/inventory.rs +++ b/src/components/inventory.rs @@ -5,7 +5,8 @@ use crate::{ ItemId, item::{Item, ItemAction}, components::equipment::{Stat, Equippable}, - Encyclopedia + Encyclopedia, + Sprite }; #[derive(Debug, Clone)] @@ -58,4 +59,8 @@ impl Inventory { } bonuses } + + pub fn equipment_sprites(&self) -> Vec<Sprite> { + self.equipped().iter().filter_map(|e| e.sprite.clone()).collect() + } } |
