summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortroido <troido@protonmail.com>2020-09-20 23:33:13 +0200
committertroido <troido@protonmail.com>2020-09-20 23:33:13 +0200
commit5eda37efbd1b34851364923069c0c3effdc32ca8 (patch)
treed2f6e035c32f49eeebc1149ef5a08bdd6229912f
parent39d7f4a123171a1dc5d5a8ec1c512599d4bec0f0 (diff)
create interactions from parameter instead of json
-rw-r--r--content/encyclopediae/crops.json4
-rw-r--r--content/encyclopediae/default_encyclopedia.json8
-rw-r--r--src/components/interactable.rs15
-rw-r--r--src/componentwrapper.rs2
4 files changed, 20 insertions, 9 deletions
diff --git a/content/encyclopediae/crops.json b/content/encyclopediae/crops.json
index 2d2b5ce..29901d9 100644
--- a/content/encyclopediae/crops.json
+++ b/content/encyclopediae/crops.json
@@ -5,7 +5,7 @@
"name": "radishplant",
"height": 0.5,
"components": [
- ["Interactable", {"action": ["interaction", ["trigger", "die"]]}],
+ ["Interactable", {"typ": "trigger", "arg": "die"}],
["Loot", {"loot": ["list", [
["list", [{"type": "radishseed"}, 0.92]],
["list", [{"type": "radishseed"}, 0.20]],
@@ -136,7 +136,7 @@
"name": "carrotplant",
"height": 1.0,
"components": [
- ["Interactable", {"action": ["interaction", ["trigger", "die"]]}],
+ ["Interactable", {"typ": "trigger", "arg": "die"}],
["Loot", {"loot": ["list", [
["list", [{"type": "carrotseed"}, 1.0]],
["list", [{"type": "carrot"}, 1.0]]
diff --git a/content/encyclopediae/default_encyclopedia.json b/content/encyclopediae/default_encyclopedia.json
index fdaa42f..9a9b526 100644
--- a/content/encyclopediae/default_encyclopedia.json
+++ b/content/encyclopediae/default_encyclopedia.json
@@ -12,7 +12,7 @@
"extract": {"allowed": ["Whitelist", "allowed"], "dedup_priority": ["Dedup", "priority"]},
"components": [
["RoomExit", {"destination": "_home+{player}", "dest_pos": ""}],
- ["Interactable", {"action": ["interaction", ["visit", "_home+{player}"]]}],
+ ["Interactable", {"typ": "visit", "arg": "_home+{player}"}],
["Whitelist", {"allowed": ["arg", "allowed"]}],
["Dedup", {"id": ["arg", "dedup_id"], "priority": ["arg", "dedup_priority"]}]
],
@@ -69,7 +69,7 @@
"height": 2,
"flags": ["Blocking"],
"components": [
- ["Interactable", {"action": ["interaction", ["trigger", "change"]]}],
+ ["Interactable", {"typ": "trigger", "arg": "change"}],
["Build", {"obj": {"type": "opendoor", "save": false}}]
]
},
@@ -78,7 +78,7 @@
"height": 0.8,
"flags": ["Occupied"],
"components": [
- ["Interactable", {"action": ["interaction", ["trigger", "change"]]}],
+ ["Interactable", {"typ": "trigger", "arg": "change"}],
["Build", {"obj": {"type": "closeddoor", "save": false}}]
]
},
@@ -94,7 +94,7 @@
"sprite": "quarry",
"height": 2,
"components": [
- ["Interactable", {"action": ["interaction", ["mine", "mining"]]}],
+ ["Interactable", {"typ": "mine", "arg": "mining"}],
["Minable", {"total": 20, "trigger": "loot"}],
["Loot", {"loot": ["list", [
["list", [{"type": "stone"}, 1.0]]
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<Self> {
+ 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<Self> {
let typ = val.get(0)?;
let arg = val.get(1)?;
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")),