run input handlers only when alive

This commit is contained in:
yuni 2024-05-13 04:47:47 +02:00
parent 48476e317f
commit cc67cf961a
7 changed files with 16 additions and 8 deletions

View file

@ -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,
));

View file

@ -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::<RespawnSinksEvent>()));
app.add_systems(Update, play_zoom_sfx);
app.add_systems(Update, pause_all.run_if(on_event::<PauseAllSfxEvent>()));
@ -158,7 +158,7 @@ pub fn respawn_sinks(
}
}
pub fn toggle_bgm(
pub fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut evwriter_toggle: EventWriter<ToggleMusicEvent>,
mut evwriter_sfx: EventWriter<PlaySfxEvent>,

View file

@ -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());

View file

@ -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<Settings>) -> bool {
return settings.alive;
}

View file

@ -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, (

View file

@ -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);

View file

@ -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,