*Actually* fix hovering sound not stopping issue

And avoid dumb string comparisons that don't even work!
main
Elijah C. Voigt 2 years ago
parent 96c3597c67
commit ff7b707bef

@ -43,7 +43,7 @@ impl Plugin for AudioPlugin {
} }
} }
#[derive(Event, Debug, PartialEq)] #[derive(Event, Debug, PartialEq, Component, Clone)]
pub enum AudioEvent { pub enum AudioEvent {
MainMusic, MainMusic,
StopMainMusic, StopMainMusic,
@ -73,7 +73,7 @@ fn play_audio(mut events: Query<&AudioSource, Added<AudioSource>>) {
fn audio_trigger( fn audio_trigger(
mut events: EventReader<AudioEvent>, mut events: EventReader<AudioEvent>,
sources: Query<&AudioSource>, sources: Query<(&AudioSource, &AudioEvent)>,
studio: Res<FmodStudio>, studio: Res<FmodStudio>,
mut commands: Commands, mut commands: Commands,
server: Res<AssetServer>, server: Res<AssetServer>,
@ -112,27 +112,37 @@ fn audio_trigger(
if let Ok(event_description) = studio.0.get_event(event_str.as_str()) { if let Ok(event_description) = studio.0.get_event(event_str.as_str()) {
let audio_source = AudioSource::new(event_description); let audio_source = AudioSource::new(event_description);
// We are stopping a playing event // We are stopping a playing event
if *event == AudioEvent::StopIdle || *event == AudioEvent::StopMainMusic { match event {
// Find and stop playing instances of idle audio
AudioEvent::StopIdle => {
sources
.iter()
.filter(|(_, source_event)| **source_event == AudioEvent::Idle)
.for_each(|(source, _)| {
info!("Stopping audio {}", event_str); info!("Stopping audio {}", event_str);
// TODO: Find and stop playing instances of this audio source.stop();
});
}
// Find and stop playing instances of main music
AudioEvent::StopMainMusic => {
sources sources
.iter() .iter()
.filter(|source| { .filter(|(_, source_event)| **source_event == AudioEvent::MainMusic)
format!("{:?}", source.event_instance) .for_each(|(source, _)| {
== format!("{:?}", audio_source.event_instance) info!("Stopping audio {}", event_str);
}) source.stop();
.for_each(|source| source.stop()); });
}
// we are playing a sound // we are playing a sound
} else { _ => {
info!("Playing audio {}", event_str); info!("Playing audio {}", event_str);
commands.spawn(audio_source); commands.spawn((audio_source, event.clone()));
} }
} else {
warn!("Music not found for {:?}", event_str);
} }
} else { } else {
warn!("No music set for {:?} in {:?}", event, state); warn!("No music set for {:?} in {:?}", event, state);
} }
}
}); });
} }

Loading…
Cancel
Save