summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--content/encyclopediae/default_encyclopedia.json2
-rw-r--r--src/controls.rs18
-rw-r--r--src/systems/useitem.rs2
3 files changed, 14 insertions, 8 deletions
diff --git a/content/encyclopediae/default_encyclopedia.json b/content/encyclopediae/default_encyclopedia.json
index a94f388..47fa9d2 100644
--- a/content/encyclopediae/default_encyclopedia.json
+++ b/content/encyclopediae/default_encyclopedia.json
@@ -224,7 +224,7 @@
["Item", {
"ent": ["template", "radishes"],
"name": ["string", "radishes"],
- "action": ["action", ["eat", 1]]
+ "action": ["action", ["eat", 3]]
}]
]
}
diff --git a/src/controls.rs b/src/controls.rs
index 3254e00..63f418a 100644
--- a/src/controls.rs
+++ b/src/controls.rs
@@ -1,6 +1,6 @@
-use serde_json::Value;
+use serde_json::{Value, json};
use specs::Entity;
use crate::{PlayerId, Pos};
@@ -60,14 +60,22 @@ impl Control {
Some(dir) => Some(Control::Move(dir)),
None => None
},
- "take" => Some(Control::Take(val.get(1)?.as_u64().map(|idx| idx as usize))),
+ "take" => Some(Control::Take(val.get(1).unwrap_or(&json!(0)).as_u64().map(|idx| idx as usize))),
"drop" => Some(Control::Drop(val.get(1)?.as_u64().unwrap_or(0) as usize)),
"use" => Some({
- println!("use argument {:?}", val);
- if val.get(1)?.as_str()? != "inventory" {
+ let arr = val.as_array()?;
+ let mut rank = 0;
+ if arr.len() == 3 {
+ if arr[1].as_str()? != "inventory" {
+ return None;
+ }
+ rank = arr[2].as_u64()?;
+ } else if arr.len() == 2 {
+ rank = arr[1].as_u64()?;
+ } else if arr.len() > 1 {
return None;
}
- Control::Use(val.get(2)?.as_u64().unwrap_or(0) as usize)
+ Control::Use(rank as usize)
}),
"attack" => Some(Control::Attack({
let mut directions = Vec::new();
diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs
index 43f38be..89a301c 100644
--- a/src/systems/useitem.rs
+++ b/src/systems/useitem.rs
@@ -39,9 +39,7 @@ impl <'a> System<'a> for Use {
for (ent, controller, position, inventory) in (&entities, &controllers, &positions, &mut inventories).join(){
match &controller.control {
Control::Use(rank) => {
- println!("rank {:?}", rank);
if let Some(item) = inventory.items.get(*rank) {
- println!("rank {:?}", item);
match &item.action {
Build(template) => {
new.create(position.pos, template.clone()).unwrap();