From 84c70cee089b72720a85d285ee0437b65be298b9 Mon Sep 17 00:00:00 2001 From: troido Date: Sun, 5 Apr 2020 13:19:27 +0200 Subject: interactions can have an argument --- src/systems/interact.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/systems/interact.rs') 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(); } -- cgit