From 1899b27b791734a6b72e28cfb1420536c6035ee4 Mon Sep 17 00:00:00 2001 From: troido Date: Thu, 21 May 2020 15:26:12 +0200 Subject: added exchanger as seperate component/system; refactored other interactions; parameter parsing returns result instead of option --- src/components/interactable.rs | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) (limited to 'src/components/interactable.rs') 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), 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, Vec)>) - >(arg.clone()).ok()?; - Exchange( - prefix, - change.into_iter().map( - |(id, (cost, offer))| (id, Exchange{cost, offer}) - ).collect::>() - ) - }, "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) -> 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 +} + -- cgit