summaryrefslogtreecommitdiff
path: root/src/components
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-04-13 10:20:37 +0200
committertroido <troido@protonmail.com>2020-04-13 10:20:37 +0200
commit9d6348a8c8d24bda6c229f72662c8eddc101e92b (patch)
tree48b7923c340fe6a0ae320e8c52187b81d385d5f5 /src/components
parentcfd462a26b3ed4c5f23760a77ae87ce61dc9bbe2 (diff)
replaced harvest interaction with choosable trigger
Diffstat (limited to 'src/components')
-rw-r--r--src/components/interactable.rs13
-rw-r--r--src/components/messages.rs14
2 files changed, 20 insertions, 7 deletions
diff --git a/src/components/interactable.rs b/src/components/interactable.rs
index eafe977..1787a33 100644
--- a/src/components/interactable.rs
+++ b/src/components/interactable.rs
@@ -7,13 +7,14 @@ use specs::{
};
use crate::{
exchange::Exchange,
- ItemId
+ ItemId,
+ components::Trigger
};
#[derive(Component, Debug, Clone, PartialEq)]
#[storage(HashMapStorage)]
pub enum Interactable {
- Harvest,
+ Trigger(Trigger),
Say(String),
Reply(String),
Exchange(String, HashMap<String, Exchange>)
@@ -23,10 +24,10 @@ use Interactable::*;
impl Interactable {
pub fn from_json(val: &Value) -> Option<Self> {
- let typ = if val.is_string() {val} else {val.get(0)?};
- let arg = if val.is_string() {&Value::Null} else {val.get(1)?};
+ let typ = val.get(0)?;
+ let arg = val.get(1)?;
Some(match typ.as_str()? {
- "harvest" => Harvest,
+ "trigger" => Trigger(Trigger::from_str(arg.as_str()?)?),
"say" => Say(arg.as_str()?.to_string()),
"reply" => Reply(arg.as_str()?.to_string()),
"exchange" => Exchange(
@@ -49,7 +50,7 @@ impl Interactable {
pub fn accepts_arg(&self, arg: &Option<String>) -> bool {
match self {
- Harvest => arg.is_none(),
+ Trigger(_) => arg.is_none(),
Say(_) => arg.is_none(),
Reply(_) => arg.is_some(),
Exchange(prefix, _exchanges) => {
diff --git a/src/components/messages.rs b/src/components/messages.rs
index fa4d747..ac21ea1 100644
--- a/src/components/messages.rs
+++ b/src/components/messages.rs
@@ -73,12 +73,24 @@ pub type AttackInbox = Inbox<AttackMessage>;
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Trigger {
Loot,
Die,
Remove
}
+
+impl Trigger {
+ pub fn from_str(txt: &str) -> Option<Self> {
+ Some(match txt {
+ "loot" => Self::Loot,
+ "die" => Self::Die,
+ "remove" => Self::Remove,
+ _ => {return None}
+ })
+ }
+}
+
impl Message for Trigger {}
pub type TriggerBox = Inbox<Trigger>;