summaryrefslogtreecommitdiff
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
parentcfd462a26b3ed4c5f23760a77ae87ce61dc9bbe2 (diff)
replaced harvest interaction with choosable trigger
-rw-r--r--content/encyclopediae/default_encyclopedia.json12
-rw-r--r--src/components/interactable.rs13
-rw-r--r--src/components/messages.rs14
-rw-r--r--src/systems/interact.rs5
4 files changed, 28 insertions, 16 deletions
diff --git a/content/encyclopediae/default_encyclopedia.json b/content/encyclopediae/default_encyclopedia.json
index 1747293..ad27795 100644
--- a/content/encyclopediae/default_encyclopedia.json
+++ b/content/encyclopediae/default_encyclopedia.json
@@ -215,7 +215,7 @@
"name": "radishplant",
"height": 0.5,
"components": [
- ["Interactable", {"action": ["interaction", "harvest"]}],
+ ["Interactable", {"action": ["interaction", ["trigger", "die"]]}],
["Loot", {"loot": ["list", [
["list", [{"type": "radishseed"}, 0.92]],
["list", [{"type": "radishseed"}, 0.20]],
@@ -262,8 +262,8 @@
"youngradishplant": {
"arguments": [["target_time", "int", 0]],
"sprite": "youngplant",
- "height": 0.05,
- "name": "youngradishplate",
+ "height": 0.8,
+ "name": "youngradishplant",
"components": [
["Grow", {
"delay": 600,
@@ -281,7 +281,7 @@
"height": 2,
"flags": ["Blocking"],
"components": [
- ["Interactable", {"action": ["interaction", "harvest"]}],
+ ["Interactable", {"action": ["interaction", ["trigger", "die"]]}],
["Loot", {"loot": ["list", [{"type": "opendoor", "save": false}]]}]
]
},
@@ -290,7 +290,7 @@
"height": 0.8,
"flags": ["Occupied"],
"components": [
- ["Interactable", {"action": ["interaction", "harvest"]}],
+ ["Interactable", {"action": ["interaction", ["trigger", "die"]]}],
["Loot", {"loot": ["list", [{"type": "closeddoor", "save": false}]]}]
]
},
@@ -379,7 +379,7 @@
"name": "carrotplant",
"height": 1.0,
"components": [
- ["Interactable", {"action": ["interaction", "harvest"]}],
+ ["Interactable", {"action": ["interaction", ["trigger", "die"]]}],
["Loot", {"loot": ["list", [
["list", [{"type": "carrotseed"}, 1.0]],
["list", [{"type": "carrot"}, 1.0]]
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>;
diff --git a/src/systems/interact.rs b/src/systems/interact.rs
index 2c6ee91..6df0066 100644
--- a/src/systems/interact.rs
+++ b/src/systems/interact.rs
@@ -16,7 +16,6 @@ use crate::{
Position,
ControlCooldown,
Interactable,
- Trigger,
TriggerBox,
Notification,
Ear,
@@ -66,8 +65,8 @@ impl <'a> System<'a> for Interact {
if let Some((ent, interactable, arg)) = target {
let name = visibles.get(ent).map(|v| v.name.as_str());
match interactable {
- Interactable::Harvest => {
- TriggerBox::add_message(&mut triggerbox, ent, Trigger::Die);
+ Interactable::Trigger(trigger) => {
+ TriggerBox::add_message(&mut triggerbox, ent, *trigger);
}
Interactable::Say(text) => {
say(ear, text.clone(), name);