diff options
Diffstat (limited to 'src/components/interactable.rs')
| -rw-r--r-- | src/components/interactable.rs | 29 |
1 files changed, 9 insertions, 20 deletions
diff --git a/src/components/interactable.rs b/src/components/interactable.rs index ab1ac29..63e89e3 100644 --- a/src/components/interactable.rs +++ b/src/components/interactable.rs @@ -8,7 +8,6 @@ use specs::{ }; use crate::{ exchange::Exchange, - ItemId, components::{Trigger, equipment::Stat}, RoomId }; @@ -17,7 +16,6 @@ use crate::{ #[storage(HashMapStorage)] pub enum Interactable { Trigger(Trigger), - Exchange(String, HashMap<String, Exchange>), Visit(RoomId), Mine(Stat) } @@ -30,17 +28,6 @@ impl Interactable { let arg = val.get(1)?; Some(match typ.as_str()? { "trigger" => Trigger(Trigger::from_str(arg.as_str()?)?), - "exchange" => { - let (prefix, change) = serde_json::value::from_value::< - (String, HashMap<String, (Vec<ItemId>, Vec<ItemId>)>) - >(arg.clone()).ok()?; - Exchange( - prefix, - change.into_iter().map( - |(id, (cost, offer))| (id, Exchange{cost, offer}) - ).collect::<HashMap<String, Exchange>>() - ) - }, "visit" => Visit(RoomId::from_str(arg.as_str()?)), "mine" => Mine(Stat::from_str(arg.as_str()?)?), _ => None? @@ -50,13 +37,6 @@ impl Interactable { pub fn accepts_arg(&self, arg: &Option<String>) -> bool { match self { Trigger(_) => arg.is_none(), - Exchange(prefix, _exchanges) => { - if let Some(txt) = arg { - txt.starts_with(prefix) - } else { - true - } - }, Visit(_) => { if let Some(txt) = arg { txt.starts_with("visit ") || txt.starts_with("disallow ") || txt.starts_with("allow ") || txt.starts_with("whitelist") @@ -74,3 +54,12 @@ impl Interactable { pub struct Talkable { pub text: String } + + +#[derive(Component, Debug, Clone, PartialEq)] +#[storage(HashMapStorage)] +pub struct Exchanger { + pub prefix: String, + pub exchanges: HashMap<String, Exchange> +} + |
