*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 {
MainMusic,
StopMainMusic,
@ -73,7 +73,7 @@ fn play_audio(mut events: Query<&AudioSource, Added<AudioSource>>) {
fn audio_trigger(
mut events: EventReader<AudioEvent>,
sources: Query<&AudioSource>,
sources: Query<(&AudioSource, &AudioEvent)>,
studio: Res<FmodStudio>,
mut commands: Commands,
server: Res<AssetServer>,
@ -112,26 +112,36 @@ fn audio_trigger(
if let Ok(event_description) = studio.0.get_event(event_str.as_str()) {
let audio_source = AudioSource::new(event_description);
// We are stopping a playing event
if *event == AudioEvent::StopIdle || *event == AudioEvent::StopMainMusic {
info!("Stopping audio {}", event_str);
// TODO: Find and stop playing instances of this audio
sources
.iter()
.filter(|source| {
format!("{:?}", source.event_instance)
== format!("{:?}", audio_source.event_instance)
})
.for_each(|source| source.stop());
// we are playing a sound
} else {
info!("Playing audio {}", event_str);
commands.spawn(audio_source);
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);
source.stop();
});
}
// Find and stop playing instances of main music
AudioEvent::StopMainMusic => {
sources
.iter()
.filter(|(_, source_event)| **source_event == AudioEvent::MainMusic)
.for_each(|(source, _)| {
info!("Stopping audio {}", event_str);
source.stop();
});
}
// we are playing a sound
_ => {
info!("Playing audio {}", event_str);
commands.spawn((audio_source, event.clone()));
}
}
} else {
warn!("Music not found for {:?}", event_str);
warn!("No music set for {:?} in {:?}", event, state);
}
} else {
warn!("No music set for {:?} in {:?}", event, state);
}
});
}

Loading…
Cancel
Save