From 37ad98cf725aa22f1c793b66102c99c9a76a4ec2 Mon Sep 17 00:00:00 2001 From: troido Date: Tue, 22 Sep 2020 15:36:58 +0200 Subject: can base sprite on equipped items --- src/components/equipment.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/components/equipment.rs') 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 + pub stats: HashMap, + pub sprite: Option } impl Equippable { @@ -60,7 +64,10 @@ impl Equippable { .map(|(k, v)| Some((Stat::from_str(k.as_str())?, v.as_i64()?)) ) - .collect::>>()? + .collect::>>()?, + 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}) ); } -- cgit