add audio::PauseAllSfxEvent
This commit is contained in:
parent
13fbe226e9
commit
ea25c7fed3
11
src/audio.rs
11
src/audio.rs
|
@ -21,9 +21,11 @@ impl Plugin for AudioPlugin {
|
||||||
app.add_systems(Startup, setup);
|
app.add_systems(Startup, setup);
|
||||||
app.add_systems(Update, toggle_bgm);
|
app.add_systems(Update, toggle_bgm);
|
||||||
app.add_systems(Update, play_zoom_sfx);
|
app.add_systems(Update, play_zoom_sfx);
|
||||||
|
app.add_systems(Update, pause_all.run_if(on_event::<PauseAllSfxEvent>()));
|
||||||
app.add_systems(PostUpdate, play_sfx);
|
app.add_systems(PostUpdate, play_sfx);
|
||||||
app.add_systems(PostUpdate, update_music);
|
app.add_systems(PostUpdate, update_music);
|
||||||
app.add_event::<PlaySfxEvent>();
|
app.add_event::<PlaySfxEvent>();
|
||||||
|
app.add_event::<PauseAllSfxEvent>();
|
||||||
app.add_event::<ToggleMusicEvent>();
|
app.add_event::<ToggleMusicEvent>();
|
||||||
app.insert_resource(ZoomTimer(
|
app.insert_resource(ZoomTimer(
|
||||||
Timer::from_seconds(0.09, TimerMode::Repeating)));
|
Timer::from_seconds(0.09, TimerMode::Repeating)));
|
||||||
|
@ -91,6 +93,7 @@ pub enum SfxType {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Event)] pub struct PlaySfxEvent(pub Sfx);
|
#[derive(Event)] pub struct PlaySfxEvent(pub Sfx);
|
||||||
|
#[derive(Event)] pub struct PauseAllSfxEvent;
|
||||||
#[derive(Event)] pub struct ToggleMusicEvent();
|
#[derive(Event)] pub struct ToggleMusicEvent();
|
||||||
#[derive(Resource)] pub struct Sounds(HashMap<Sfx, Handle<AudioSource>>);
|
#[derive(Resource)] pub struct Sounds(HashMap<Sfx, Handle<AudioSource>>);
|
||||||
|
|
||||||
|
@ -213,3 +216,11 @@ pub fn play_zoom_sfx(
|
||||||
*last_zoom_level = mapcam.target_zoom_level;
|
*last_zoom_level = mapcam.target_zoom_level;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn pause_all(
|
||||||
|
q_audiosinks: Query<&AudioSink, With<Sfx>>,
|
||||||
|
) {
|
||||||
|
for sink in &q_audiosinks {
|
||||||
|
sink.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -104,6 +104,7 @@ pub fn show_deathscreen(
|
||||||
mut er_deathscreen: EventReader<DeathScreenEvent>,
|
mut er_deathscreen: EventReader<DeathScreenEvent>,
|
||||||
mut q_vis: Query<&mut Visibility, With<DeathScreenElement>>,
|
mut q_vis: Query<&mut Visibility, With<DeathScreenElement>>,
|
||||||
mut q_text: Query<&mut Text, With<DeathText>>,
|
mut q_text: Query<&mut Text, With<DeathText>>,
|
||||||
|
mut ew_pausesfx: EventWriter<audio::PauseAllSfxEvent>,
|
||||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||||
mut ew_effect: EventWriter<visual::SpawnEffectEvent>,
|
mut ew_effect: EventWriter<visual::SpawnEffectEvent>,
|
||||||
mut ew_respawn: EventWriter<world::RespawnEvent>,
|
mut ew_respawn: EventWriter<world::RespawnEvent>,
|
||||||
|
@ -117,6 +118,7 @@ pub fn show_deathscreen(
|
||||||
settings.deathscreen_active = show;
|
settings.deathscreen_active = show;
|
||||||
|
|
||||||
if show {
|
if show {
|
||||||
|
ew_pausesfx.send(audio::PauseAllSfxEvent);
|
||||||
if let Ok(mut text) = q_text.get_single_mut() {
|
if let Ok(mut text) = q_text.get_single_mut() {
|
||||||
let poems: Vec<&str> = POEMS.split("\n\n").collect();
|
let poems: Vec<&str> = POEMS.split("\n\n").collect();
|
||||||
if poems.len() > 0 {
|
if poems.len() > 0 {
|
||||||
|
|
Loading…
Reference in a new issue