diff options
| author | troido <troido@protonmail.com> | 2020-04-05 13:19:27 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-05 13:19:27 +0200 |
| commit | 84c70cee089b72720a85d285ee0437b65be298b9 (patch) | |
| tree | cf93ce44eadcb430e1b425a882659303a2b0382d /src/systems/interact.rs | |
| parent | 068f98cec100772defce8ba966e5b917558b191c (diff) | |
interactions can have an argument
Diffstat (limited to 'src/systems/interact.rs')
| -rw-r--r-- | src/systems/interact.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/systems/interact.rs b/src/systems/interact.rs index b932fd5..4bf2e4c 100644 --- a/src/systems/interact.rs +++ b/src/systems/interact.rs @@ -45,20 +45,22 @@ impl <'a> System<'a> for Interact { for (entity, controller, position) in (&entities, &controllers, &positions).join(){ let mut target = None; match &controller.control { - Control::Interact(directions) => { + Control::Interact(directions, arg) => { 'targets: for direction in directions { let pos = position.pos + direction.to_position(); for ent in ground.cells.get(&pos).unwrap_or(&HashSet::new()) { if let Some(interactable) = interactables.get(*ent) { - target = Some((*ent, interactable, pos)); - break 'targets; + if interactable.accepts_arg(arg){ + target = Some((*ent, interactable, pos, arg.clone())); + break 'targets; + } } } } } _ => {} } - if let Some((ent, interactable, pos)) = target { + if let Some((ent, interactable, pos, arg)) = target { match interactable { Interactable::Harvest => { deads.insert(ent, Dead).unwrap(); @@ -72,6 +74,11 @@ impl <'a> System<'a> for Interact { ear.sounds.push(Sound{source: None, text: text.clone()}); } } + Interactable::Reply(text) => { + if let Some(ear) = ears.get_mut(entity) { + ear.sounds.push(Sound{source: None, text: text.replace("{}", &arg.unwrap())}); + } + } } cooldowns.insert(entity, ControlCooldown{amount: 2}).unwrap(); } |
