From cc67cf961af0523bb803920bcf631ed85e3280e7 Mon Sep 17 00:00:00 2001 From: hut Date: Mon, 13 May 2024 04:47:47 +0200 Subject: [PATCH] run input handlers only when alive --- src/actor.rs | 2 +- src/audio.rs | 4 ++-- src/camera.rs | 8 ++++---- src/common.rs | 5 +++++ src/hud.rs | 2 +- src/menu.rs | 1 + src/var.rs | 2 ++ 7 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/actor.rs b/src/actor.rs index 48a4fd7..39ff121 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -35,7 +35,7 @@ impl Plugin for ActorPlugin { .after(PhysicsSet::Sync) .after(sync::position_to_transform)); app.add_systems(Update, ( - handle_input, + handle_input.run_if(alive), handle_collisions, handle_damage, )); diff --git a/src/audio.rs b/src/audio.rs index c217ca5..b48ef2c 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -19,7 +19,7 @@ pub struct AudioPlugin; impl Plugin for AudioPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, setup); - app.add_systems(Update, toggle_bgm); + app.add_systems(Update, handle_input.run_if(alive)); app.add_systems(Update, respawn_sinks.run_if(on_event::())); app.add_systems(Update, play_zoom_sfx); app.add_systems(Update, pause_all.run_if(on_event::())); @@ -158,7 +158,7 @@ pub fn respawn_sinks( } } -pub fn toggle_bgm( +pub fn handle_input( keyboard_input: Res>, mut evwriter_toggle: EventWriter, mut evwriter_sfx: EventWriter, diff --git a/src/camera.rs b/src/camera.rs index 6b286b5..fc527a2 100644 --- a/src/camera.rs +++ b/src/camera.rs @@ -31,8 +31,8 @@ pub struct CameraPlugin; impl Plugin for CameraPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, setup_camera); - app.add_systems(Update, handle_input); - app.add_systems(Update, update_map_only_object_visibility); + app.add_systems(Update, handle_input.run_if(alive)); + app.add_systems(Update, update_map_only_object_visibility.run_if(alive)); app.add_systems(Update, manage_player_actor.after(handle_input)); app.add_systems(PostUpdate, sync_camera_to_player .after(PhysicsSet::Sync) @@ -41,8 +41,8 @@ impl Plugin for CameraPlugin { app.add_systems(PostUpdate, update_mapcam_center .before(sync::position_to_transform) .in_set(sync::SyncSet::PositionToTransform)); - app.add_systems(Update, update_map_camera); - app.add_systems(Update, update_fov); + app.add_systems(Update, update_map_camera.run_if(alive)); + app.add_systems(Update, update_fov.run_if(alive)); app.add_systems(PreUpdate, apply_input_to_player); app.insert_resource(MapCam::default()); diff --git a/src/common.rs b/src/common.rs index 43e9dd3..8795797 100644 --- a/src/common.rs +++ b/src/common.rs @@ -11,6 +11,7 @@ // Various common functions and constants use bevy::prelude::*; +use crate::prelude::*; pub use bevy::math::{DVec3, DQuat}; pub use std::f32::consts::PI as PI32; @@ -54,3 +55,7 @@ pub fn style_centered() -> Style { ..default() } } + +pub fn alive(settings: Res) -> bool { + return settings.alive; +} diff --git a/src/hud.rs b/src/hud.rs index abb45ec..f7f9c29 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -41,7 +41,7 @@ impl Plugin for HudPlugin { update_dashboard, update_speedometer, update_gauges, - handle_input, + handle_input.run_if(alive), handle_target_event, )); app.add_systems(PostUpdate, ( diff --git a/src/menu.rs b/src/menu.rs index ba32eeb..e051c95 100644 --- a/src/menu.rs +++ b/src/menu.rs @@ -117,6 +117,7 @@ pub fn show_deathscreen( *vis = bool2vis(show); } settings.deathscreen_active = show; + settings.alive = !show; if show { ew_pausesfx.send(audio::PauseAllSfxEvent); diff --git a/src/var.rs b/src/var.rs index e1e0116..13f73f3 100644 --- a/src/var.rs +++ b/src/var.rs @@ -37,6 +37,7 @@ pub struct Settings { pub dev_mode: bool, pub god_mode: bool, pub version: String, + pub alive: bool, pub mute_sfx: bool, pub mute_music: bool, pub volume_sfx: u8, @@ -152,6 +153,7 @@ impl Default for Settings { dev_mode, god_mode: false, version, + alive: true, mute_sfx: default_mute_sfx, mute_music: default_mute_music, volume_sfx: 100,