From bd1da23cf18960b36f8683c09899044d64b4bd83 Mon Sep 17 00:00:00 2001 From: troido Date: Thu, 21 May 2020 12:25:36 +0200 Subject: made Talk its own component/system instead of part of interact --- src/componentwrapper.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src/componentwrapper.rs') diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index 2619d9c..e1b5bb8 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -50,12 +50,13 @@ macro_rules! components { ComponentType::$comp => Ok(Self::$comp({ use crate::components::$comp; $( - let $paramname = <$paramtype>::from_parameter( - parameters + let $paramname = { + let param = parameters .remove(stringify!($paramname)) - .ok_or(aerr!("required parameter '{}'not found", stringify!($paramname)))? - ) - .ok_or(aerr!("parameter {} is invalid type", stringify!($paramname)))?; + .ok_or(aerr!("required parameter '{}'not found", stringify!($paramname)))?; + <$paramtype>::from_parameter(param.clone()) + .ok_or(aerr!("parameter {} is invalid type: {:?} is not of type {}", stringify!($paramname), param, stringify!($paramtype)))? + }; )* $creation @@ -233,6 +234,7 @@ components!(all: } }; Substitute (into: Template); + Talkable (text: String); ); -- cgit 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/componentwrapper.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/componentwrapper.rs') diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index e1b5bb8..638d156 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -21,6 +21,7 @@ use crate::{ fromtoparameter::FromToParameter, Timestamp, Template, + exchange::Exchange, Pos, Result, aerr @@ -235,6 +236,17 @@ components!(all: }; Substitute (into: Template); Talkable (text: String); + Exchanger (prefix: String, exchanges: Vec<(String, Vec, Vec)>) { + Exchanger { + prefix, + exchanges: exchanges + .into_iter() + .map(|(key, cost, offer)| + (key, Exchange{cost, offer}) + ) + .collect() + } + }; ); -- cgit From 5eda37efbd1b34851364923069c0c3effdc32ca8 Mon Sep 17 00:00:00 2001 From: troido Date: Sun, 20 Sep 2020 23:33:13 +0200 Subject: create interactions from parameter instead of json --- src/componentwrapper.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/componentwrapper.rs') diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index 638d156..f3c2db0 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -185,7 +185,7 @@ components!(all: Clan (name: String); Home (home: Pos); Faction (faction: String) {Faction::from_str(faction.as_str()).ok_or(aerr!("invalid faction name"))?}; - Interactable (action: Interactable) {action}; + Interactable (typ: String, arg: Parameter) {Interactable::parse_from_parameter(&typ, &arg).ok_or(aerr!("invalid interaction"))?}; Loot (loot: Vec<(Template, f64)>); Timer ( trigger: String, (panic!("can't turn trigger to string")), -- cgit From 1e7c665728eb638cdf921824f4c22f54b81f29de Mon Sep 17 00:00:00 2001 From: troido Date: Sun, 20 Sep 2020 23:37:28 +0200 Subject: removed interactable as Parameter type --- src/componentwrapper.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/componentwrapper.rs') diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index f3c2db0..62e090e 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -14,8 +14,7 @@ use crate::{ AttackType, Clan, Flag, - Trigger, - interactable::Interactable + Trigger }, parameter::{Parameter}, fromtoparameter::FromToParameter, -- cgit From 92e437e50498f7705e33a556535ba39a2b918f9d Mon Sep 17 00:00:00 2001 From: troido Date: Mon, 21 Sep 2020 00:59:38 +0200 Subject: made talk and reply a form of interact again --- src/componentwrapper.rs | 1 - 1 file changed, 1 deletion(-) (limited to 'src/componentwrapper.rs') diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index 62e090e..96cedd3 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -234,7 +234,6 @@ components!(all: } }; Substitute (into: Template); - Talkable (text: String); Exchanger (prefix: String, exchanges: Vec<(String, Vec, Vec)>) { Exchanger { prefix, -- cgit From e2281d8c6293b311ccc187e3503093a1120e6215 Mon Sep 17 00:00:00 2001 From: troido Date: Mon, 21 Sep 2020 02:32:22 +0200 Subject: exchange is now an interaction again --- src/componentwrapper.rs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) (limited to 'src/componentwrapper.rs') diff --git a/src/componentwrapper.rs b/src/componentwrapper.rs index 96cedd3..08d95ee 100644 --- a/src/componentwrapper.rs +++ b/src/componentwrapper.rs @@ -20,7 +20,6 @@ use crate::{ fromtoparameter::FromToParameter, Timestamp, Template, - exchange::Exchange, Pos, Result, aerr @@ -184,7 +183,9 @@ components!(all: Clan (name: String); Home (home: Pos); Faction (faction: String) {Faction::from_str(faction.as_str()).ok_or(aerr!("invalid faction name"))?}; - Interactable (typ: String, arg: Parameter) {Interactable::parse_from_parameter(&typ, &arg).ok_or(aerr!("invalid interaction"))?}; + Interactable (typ: String, arg: Parameter) { + Interactable::parse_from_parameter(&typ, &arg).ok_or(aerr!("invalid interaction {:?} {:?}", typ, arg))? + }; Loot (loot: Vec<(Template, f64)>); Timer ( trigger: String, (panic!("can't turn trigger to string")), @@ -234,17 +235,6 @@ components!(all: } }; Substitute (into: Template); - Exchanger (prefix: String, exchanges: Vec<(String, Vec, Vec)>) { - Exchanger { - prefix, - exchanges: exchanges - .into_iter() - .map(|(key, cost, offer)| - (key, Exchange{cost, offer}) - ) - .collect() - } - }; ); -- cgit