|
|
|
|
@ -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,27 +112,37 @@ 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 {
|
|
|
|
|
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);
|
|
|
|
|
// TODO: Find and stop playing instances of this audio
|
|
|
|
|
source.stop();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// Find and stop playing instances of main music
|
|
|
|
|
AudioEvent::StopMainMusic => {
|
|
|
|
|
sources
|
|
|
|
|
.iter()
|
|
|
|
|
.filter(|source| {
|
|
|
|
|
format!("{:?}", source.event_instance)
|
|
|
|
|
== format!("{:?}", audio_source.event_instance)
|
|
|
|
|
})
|
|
|
|
|
.for_each(|source| source.stop());
|
|
|
|
|
.filter(|(_, source_event)| **source_event == AudioEvent::MainMusic)
|
|
|
|
|
.for_each(|(source, _)| {
|
|
|
|
|
info!("Stopping audio {}", event_str);
|
|
|
|
|
source.stop();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
// we are playing a sound
|
|
|
|
|
} else {
|
|
|
|
|
_ => {
|
|
|
|
|
info!("Playing audio {}", event_str);
|
|
|
|
|
commands.spawn(audio_source);
|
|
|
|
|
commands.spawn((audio_source, event.clone()));
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
warn!("Music not found for {:?}", event_str);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
warn!("No music set for {:?} in {:?}", event, state);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|