From 4b0f23c0db97587131806b79f2d17c1bf93036c6 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 24 May 2021 15:34:38 -0500 Subject: [PATCH] Flatten sound icons. --- src/sound.rs | 112 +++++++++++++++++++++------------------------------ 1 file changed, 45 insertions(+), 67 deletions(-) diff --git a/src/sound.rs b/src/sound.rs index 508f1d7..f873242 100644 --- a/src/sound.rs +++ b/src/sound.rs @@ -1,11 +1,6 @@ use std::{collections::HashMap, fmt::Debug, hash::Hash, time::Duration}; -use bevy::{ - asset::{HandleId, LoadState}, - ecs::component::Component, - prelude::*, - transform::TransformSystem, -}; +use bevy::{asset::HandleId, ecs::component::Component, prelude::*, transform::TransformSystem}; use bevy_openal::{Buffer, Context, Sound, SoundState}; use rand::random; @@ -133,22 +128,38 @@ fn footstep( } } -fn sound_icon( +fn add_sound_icon_sounds( mut commands: Commands, + icons: Query<(Entity, &SoundIcon), Added>, + assets: Res>, +) { + for (entity, icon) in icons.iter() { + let buffer = assets.get_handle(icon.sound); + let looping = icon.interval.is_none(); + commands.entity(entity).insert(Sound { + buffer, + gain: icon.gain, + pitch: icon.pitch, + looping, + state: SoundState::Stopped, + ..Default::default() + }); + } +} + +fn sound_icon( config: Res>, state: Res>, time: Res