From 2cc5b468cfd4c28bf1ad17ef1b3600c3d42f8b83 Mon Sep 17 00:00:00 2001 From: troido Date: Sat, 4 Apr 2020 14:01:17 +0200 Subject: listen to sounds in the world --- src/systems/interact.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'src/systems/interact.rs') diff --git a/src/systems/interact.rs b/src/systems/interact.rs index e3b8358..b932fd5 100644 --- a/src/systems/interact.rs +++ b/src/systems/interact.rs @@ -16,7 +16,9 @@ use crate::components::{ ControlCooldown, Interactable, Dead, - Removed + Removed, + Sound, + Ear }; use crate::controls::{Control}; @@ -35,10 +37,11 @@ impl <'a> System<'a> for Interact { ReadStorage<'a, Interactable>, WriteStorage<'a, Dead>, WriteStorage<'a, Removed>, - Write<'a, NewEntities> + Write<'a, NewEntities>, + WriteStorage<'a, Ear> ); - fn run(&mut self, (entities, controllers, positions, ground, mut cooldowns, interactables, mut deads, mut removeds, mut new): Self::SystemData) { + fn run(&mut self, (entities, controllers, positions, ground, mut cooldowns, interactables, mut deads, mut removeds, mut new, mut ears): Self::SystemData) { for (entity, controller, position) in (&entities, &controllers, &positions).join(){ let mut target = None; match &controller.control { @@ -64,6 +67,11 @@ impl <'a> System<'a> for Interact { new.create(pos, into).unwrap(); removeds.insert(ent, Removed).unwrap(); } + Interactable::Say(text) => { + if let Some(ear) = ears.get_mut(entity) { + ear.sounds.push(Sound{source: None, text: text.clone()}); + } + } } cooldowns.insert(entity, ControlCooldown{amount: 2}).unwrap(); } -- cgit