diff options
| author | troido <troido@protonmail.com> | 2020-04-04 14:01:17 +0200 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-04-04 14:01:17 +0200 |
| commit | 2cc5b468cfd4c28bf1ad17ef1b3600c3d42f8b83 (patch) | |
| tree | 835e67143e56fafef795e320ce8fc5d50cb9cc6c /src/systems | |
| parent | 0b17829846adf9482b460e4cc616382ede1df6dd (diff) | |
listen to sounds in the world
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/interact.rs | 14 | ||||
| -rw-r--r-- | src/systems/view.rs | 13 |
2 files changed, 21 insertions, 6 deletions
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(); } diff --git a/src/systems/view.rs b/src/systems/view.rs index 0ed1cf7..49338ac 100644 --- a/src/systems/view.rs +++ b/src/systems/view.rs @@ -3,6 +3,7 @@ use std::collections::{HashSet}; use specs::{ ReadStorage, + WriteStorage, Read, Write, System, @@ -13,7 +14,7 @@ use specs::{ use crate::{ Pos, Sprite, - components::{Visible, Player, Position, Inventory, New, Moved, Removed, Health}, + components::{Visible, Player, Position, Inventory, New, Moved, Removed, Health, Ear}, resources::{Size, Output, Ground}, worldmessages::{WorldMessage, FieldMessage} }; @@ -34,9 +35,10 @@ impl <'a> System<'a> for View { ReadStorage<'a, New>, ReadStorage<'a, Moved>, ReadStorage<'a, Removed>, - Read<'a, Ground> + Read<'a, Ground>, + WriteStorage<'a, Ear> ); - fn run(&mut self, (entities, positions, inventories, healths, visible, size, players, mut output, new, moved, removed, ground): Self::SystemData) { + fn run(&mut self, (entities, positions, inventories, healths, visible, size, players, mut output, new, moved, removed, ground, mut ears): Self::SystemData) { let mut changed = HashSet::new(); for (pos, _new) in (&positions, &new).join() { @@ -78,6 +80,11 @@ impl <'a> System<'a> for View { if let Some(health) = healths.get(ent){ updates.health = Some((health.health, health.maxhealth)); } + if let Some(ear) = ears.get_mut(ent){ + if !ear.sounds.is_empty(){ + updates.sounds = Some(ear.sounds.drain(..).map(|s| s.as_message()).collect()); + } + } updates.ground = Some( ground .by_height(&pos.pos, &visible, &ent) |
