summaryrefslogtreecommitdiff
path: root/src/controls.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/controls.rs')
-rw-r--r--src/controls.rs27
1 files changed, 12 insertions, 15 deletions
diff --git a/src/controls.rs b/src/controls.rs
index 63f418a..7ed8374 100644
--- a/src/controls.rs
+++ b/src/controls.rs
@@ -48,7 +48,7 @@ pub enum Control {
Use(usize),
Attack(Vec<Direction>),
AttackTarget(Entity),
- Interact(Vec<Direction>)
+ Interact(Vec<Direction>, Option<String>),
}
@@ -77,26 +77,23 @@ impl Control {
}
Control::Use(rank as usize)
}),
- "attack" => Some(Control::Attack({
- let mut directions = Vec::new();
- for dir in val.get(1)?.as_array()? {
- directions.push(Direction::from_json(dir)?);
- }
- directions
- })),
- "interact" => Some(Control::Interact({
- let mut directions = Vec::new();
- for dir in val.get(1)?.as_array()? {
- directions.push(Direction::from_json(dir)?);
- }
- directions
- })),
+ "attack" => Some(Control::Attack(
+ parse_directions(val.get(1)?)?
+ )),
+ "interact" => Some(Control::Interact(
+ parse_directions(val.get(1)?)?,
+ val.get(2).map(|v| Some(v.as_str()?.to_string())).flatten()
+ )),
_ => None
}
} else {None}
}
}
+fn parse_directions(val: &Value) -> Option<Vec<Direction>> {
+ val.as_array()?.into_iter().map(Direction::from_json).collect()
+}
+
#[derive(Debug, Clone)]
pub enum Action {
Join(PlayerId),