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/components/interactable.rs | 6 ++++++ src/components/mod.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'src/components') diff --git a/src/components/interactable.rs b/src/components/interactable.rs index d97b742..636953f 100644 --- a/src/components/interactable.rs +++ b/src/components/interactable.rs @@ -74,3 +74,9 @@ impl Interactable { } } } + +#[derive(Component, Debug, Clone, PartialEq)] +#[storage(HashMapStorage)] +pub struct Talkable { + pub text: String +} diff --git a/src/components/mod.rs b/src/components/mod.rs index ee5176e..23f5488 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -16,7 +16,7 @@ pub use messages::{ TriggerBox }; pub use faction::Faction; -pub use interactable::Interactable; +pub use interactable::{Interactable, Talkable}; pub use equipment::Equipment; pub use inventory::Inventory; pub use serialise::Serialise; -- cgit From f47034bdf86e7ddc831ecb8f50689b9b07a0f6ca Mon Sep 17 00:00:00 2001 From: troido Date: Thu, 21 May 2020 12:45:44 +0200 Subject: actually added talk system and removed reply interaction --- src/components/interactable.rs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/components') diff --git a/src/components/interactable.rs b/src/components/interactable.rs index 636953f..ab1ac29 100644 --- a/src/components/interactable.rs +++ b/src/components/interactable.rs @@ -17,8 +17,6 @@ use crate::{ #[storage(HashMapStorage)] pub enum Interactable { Trigger(Trigger), - Say(String), - Reply(String), Exchange(String, HashMap), Visit(RoomId), Mine(Stat) @@ -32,8 +30,6 @@ impl Interactable { let arg = val.get(1)?; Some(match typ.as_str()? { "trigger" => Trigger(Trigger::from_str(arg.as_str()?)?), - "say" => Say(arg.as_str()?.to_string()), - "reply" => Reply(arg.as_str()?.to_string()), "exchange" => { let (prefix, change) = serde_json::value::from_value::< (String, HashMap, Vec)>) @@ -54,8 +50,6 @@ impl Interactable { pub fn accepts_arg(&self, arg: &Option) -> bool { match self { Trigger(_) => arg.is_none(), - Say(_) => arg.is_none(), - Reply(_) => arg.is_some(), Exchange(prefix, _exchanges) => { if let Some(txt) = arg { txt.starts_with(prefix) -- 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/components/interactable.rs | 29 +++++++++-------------------- src/components/mod.rs | 2 +- 2 files changed, 10 insertions(+), 21 deletions(-) (limited to 'src/components') 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 +} + diff --git a/src/components/mod.rs b/src/components/mod.rs index 23f5488..68e666c 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -16,7 +16,7 @@ pub use messages::{ TriggerBox }; pub use faction::Faction; -pub use interactable::{Interactable, Talkable}; +pub use interactable::{Interactable, Talkable, Exchanger}; pub use equipment::Equipment; pub use inventory::Inventory; pub use serialise::Serialise; -- 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/components/interactable.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/components') diff --git a/src/components/interactable.rs b/src/components/interactable.rs index 63e89e3..d5a6926 100644 --- a/src/components/interactable.rs +++ b/src/components/interactable.rs @@ -4,12 +4,13 @@ use serde_json; use serde_json::{Value}; use specs::{ Component, - HashMapStorage + HashMapStorage, }; use crate::{ exchange::Exchange, components::{Trigger, equipment::Stat}, - RoomId + RoomId, + parameter::Parameter }; #[derive(Component, Debug, Clone, PartialEq)] @@ -23,6 +24,16 @@ pub enum Interactable { use Interactable::*; impl Interactable { + + pub fn parse_from_parameter(typ: &str, arg: &Parameter) -> Option { + Some(match (typ, arg) { + ("trigger", Parameter::String(s)) => Trigger(Trigger::from_str(s)?), + ("visit", Parameter::String(s)) => Visit(RoomId::from_str(s)), + ("mine", Parameter::String(s)) => Mine(Stat::from_str(s)?), + _ => None? + }) + } + pub fn from_json(val: &Value) -> Option { let typ = val.get(0)?; let arg = val.get(1)?; -- 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/components/interactable.rs | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'src/components') diff --git a/src/components/interactable.rs b/src/components/interactable.rs index d5a6926..ec8c1db 100644 --- a/src/components/interactable.rs +++ b/src/components/interactable.rs @@ -1,7 +1,5 @@ use std::collections::HashMap; -use serde_json; -use serde_json::{Value}; use specs::{ Component, HashMapStorage, @@ -33,17 +31,6 @@ impl Interactable { _ => None? }) } - - pub fn from_json(val: &Value) -> Option { - let typ = val.get(0)?; - let arg = val.get(1)?; - Some(match typ.as_str()? { - "trigger" => Trigger(Trigger::from_str(arg.as_str()?)?), - "visit" => Visit(RoomId::from_str(arg.as_str()?)), - "mine" => Mine(Stat::from_str(arg.as_str()?)?), - _ => None? - }) - } pub fn accepts_arg(&self, arg: &Option) -> bool { match self { -- 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/components/interactable.rs | 16 ++++++++-------- src/components/mod.rs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'src/components') diff --git a/src/components/interactable.rs b/src/components/interactable.rs index ec8c1db..2e286cf 100644 --- a/src/components/interactable.rs +++ b/src/components/interactable.rs @@ -16,7 +16,9 @@ use crate::{ pub enum Interactable { Trigger(Trigger), Visit(RoomId), - Mine(Stat) + Mine(Stat), + Say(String), + Reply(String) } use Interactable::*; @@ -28,6 +30,8 @@ impl Interactable { ("trigger", Parameter::String(s)) => Trigger(Trigger::from_str(s)?), ("visit", Parameter::String(s)) => Visit(RoomId::from_str(s)), ("mine", Parameter::String(s)) => Mine(Stat::from_str(s)?), + ("say", Parameter::String(s)) => Say(s.clone()), + ("reply", Parameter::String(s)) => Reply(s.clone()), _ => None? }) } @@ -42,17 +46,13 @@ impl Interactable { true } } - Mine(_) => arg.is_none() + Mine(_) => arg.is_none(), + Say(_) => arg.is_none(), + Reply(_) => arg.is_some(), } } } -#[derive(Component, Debug, Clone, PartialEq)] -#[storage(HashMapStorage)] -pub struct Talkable { - pub text: String -} - #[derive(Component, Debug, Clone, PartialEq)] #[storage(HashMapStorage)] diff --git a/src/components/mod.rs b/src/components/mod.rs index 68e666c..f315060 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -16,7 +16,7 @@ pub use messages::{ TriggerBox }; pub use faction::Faction; -pub use interactable::{Interactable, Talkable, Exchanger}; +pub use interactable::{Interactable, Exchanger}; pub use equipment::Equipment; pub use inventory::Inventory; pub use serialise::Serialise; -- 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/components/interactable.rs | 28 ++++++++++++++++++---------- src/components/mod.rs | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) (limited to 'src/components') diff --git a/src/components/interactable.rs b/src/components/interactable.rs index 2e286cf..2f20966 100644 --- a/src/components/interactable.rs +++ b/src/components/interactable.rs @@ -8,7 +8,9 @@ use crate::{ exchange::Exchange, components::{Trigger, equipment::Stat}, RoomId, - parameter::Parameter + parameter::Parameter, + fromtoparameter::FromToParameter, + ItemId, }; #[derive(Component, Debug, Clone, PartialEq)] @@ -18,7 +20,8 @@ pub enum Interactable { Visit(RoomId), Mine(Stat), Say(String), - Reply(String) + Reply(String), + Exchange(String, HashMap), } use Interactable::*; @@ -32,7 +35,12 @@ impl Interactable { ("mine", Parameter::String(s)) => Mine(Stat::from_str(s)?), ("say", Parameter::String(s)) => Say(s.clone()), ("reply", Parameter::String(s)) => Reply(s.clone()), - _ => None? + ("exchange", p) => { + let (prefix, trades) = <(String, Vec<(String, Vec, Vec)>)>::from_parameter(p.clone())?; + let exchanges = trades.into_iter().map(|(k, cost, offer)| (k, Exchange{cost, offer})).collect(); + Exchange(prefix, exchanges) + } + _ => {return None} }) } @@ -49,15 +57,15 @@ impl Interactable { Mine(_) => arg.is_none(), Say(_) => arg.is_none(), Reply(_) => arg.is_some(), + Exchange(prefix, _exchanges) => { + if let Some(txt) = arg { + txt.starts_with(prefix) + } else { + true + } + }, } } } -#[derive(Component, Debug, Clone, PartialEq)] -#[storage(HashMapStorage)] -pub struct Exchanger { - pub prefix: String, - pub exchanges: HashMap -} - diff --git a/src/components/mod.rs b/src/components/mod.rs index f315060..38a14bd 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -16,7 +16,7 @@ pub use messages::{ TriggerBox }; pub use faction::Faction; -pub use interactable::{Interactable, Exchanger}; +pub use interactable::{Interactable}; pub use equipment::Equipment; pub use inventory::Inventory; pub use serialise::Serialise; -- cgit