diff options
| author | troido <troido@protonmail.com> | 2020-02-21 19:22:26 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-02-21 19:22:26 +0100 |
| commit | 4ed2d71e76f04c75a214e43363dc1b64e109fe3d (patch) | |
| tree | 1ae0375ff74216dacc6f5a2b443b84e85b257059 /src/controls.rs | |
| parent | 60b56b39488f7704f42580363d1343a4dc9732e8 (diff) | |
used rank in taking objects
Diffstat (limited to 'src/controls.rs')
| -rw-r--r-- | src/controls.rs | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/controls.rs b/src/controls.rs index a27348d..b944a93 100644 --- a/src/controls.rs +++ b/src/controls.rs @@ -42,24 +42,24 @@ impl Direction { #[derive(Debug, Clone)] pub enum Control { Move(Direction), - Take(u64), - Drop(u64) + Take(Option<u64>), + Drop(usize) } impl Control { pub fn from_json(val: &Value) -> Option<Control>{ - if let Value::String(control_type) = &val[0] { + if let Value::String(control_type) = val.get(0)? { match control_type.as_str() { - "move" => match Direction::from_json(&val[1]) { + "move" => match Direction::from_json(val.get(1)?) { Some(dir) => Some(Control::Move(dir)), None => None }, - "take" => Some(Control::Take(0)), /*match val[1].as_u64() { + "take" => Some(Control::Take(val.get(1)?.as_u64())), /*match val[1].as_u64() { Some(rank) => Some(Control::Take(rank)), _ => None }*/ - "drop" => Some(Control::Drop(0)), + "drop" => Some(Control::Drop(val.get(1)?.as_u64().unwrap_or(0) as usize)), _ => None } } else {None} |
