From f7002fd064dc03f14a328f094388f8b1e5758b86 Mon Sep 17 00:00:00 2001 From: yuni Date: Sun, 2 Jun 2024 21:03:40 +0200 Subject: [PATCH] reset chat variables (GameVars) on death --- src/game.rs | 4 ++++ src/main.rs | 2 -- src/var.rs | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/game.rs b/src/game.rs index 870cac1..29f4395 100644 --- a/src/game.rs +++ b/src/game.rs @@ -33,6 +33,8 @@ impl Plugin for GamePlugin { app.add_systems(Update, check_achievements); app.insert_resource(Id2Pos(HashMap::new())); app.insert_resource(var::AchievementTracker::default()); + app.insert_resource(var::Settings::default()); + app.insert_resource(var::GameVars::default()); app.insert_resource(AchievementCheckTimer(Timer::from_seconds( 1.0, TimerMode::Repeating, @@ -176,6 +178,7 @@ fn handle_player_death( mut ew_effect: EventWriter, mut ew_deathscreen: EventWriter, mut log: ResMut, + mut gamevars: ResMut, mut settings: ResMut, ) { for death in er_playerdies.read() { @@ -183,6 +186,7 @@ fn handle_player_death( return; } settings.reset_player_settings(); + gamevars.reset(); active_asteroids.0.clear(); for entity in &q_noscenes { cmd.entity(entity).despawn(); diff --git a/src/main.rs b/src/main.rs index c6194b0..918fc51 100644 --- a/src/main.rs +++ b/src/main.rs @@ -122,8 +122,6 @@ impl Plugin for OutFlyPlugin { fn build(&self, app: &mut App) { app.add_systems(Startup, setup); app.add_systems(Update, handle_input); - app.insert_resource(var::Settings::default()); - app.insert_resource(var::GameVars::default()); app.add_plugins(( DefaultPlugins, //.set(ImagePlugin::default_nearest()), FrameTimeDiagnosticsPlugin, diff --git a/src/var.rs b/src/var.rs index 8500a77..965de51 100644 --- a/src/var.rs +++ b/src/var.rs @@ -519,6 +519,10 @@ impl Default for GameVars { } impl GameVars { + pub fn reset(&mut self) { + self.db.clear(); + } + #[allow(dead_code)] pub fn get(&self, key: &str) -> Option { if let Some(value) = self.db.get(key) {