From d58e9ebb1e0bc29e7d022e33f30de0e66b69a6b4 Mon Sep 17 00:00:00 2001 From: hut Date: Sun, 17 Mar 2024 18:26:44 +0100 Subject: [PATCH] turn settings into a resource --- src/main.rs | 9 +++------ src/settings.rs | 6 +----- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index ce56acf..1c33c03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,7 +13,6 @@ fn main() { App::new() .add_systems(Startup, ( setup, - settings::setup, audio::setup, player::setup, world::setup, @@ -33,6 +32,7 @@ fn main() { FrameTimeDiagnosticsPlugin, LogDiagnosticsPlugin::default(), )) + .insert_resource(settings::Settings::default()) .run(); } @@ -50,16 +50,13 @@ fn setup( fn handle_input( keyboard_input: Res>, - mut settings: Query<&mut settings::Settings>, + mut settings: ResMut, mut app_exit_events: ResMut> ) { if keyboard_input.pressed(KeyCode::KeyQ) { app_exit_events.send(bevy::app::AppExit); } if keyboard_input.just_pressed(KeyCode::F12) { - let result = settings.get_single_mut(); - if result.is_ok() { - result.unwrap().reset() - } + settings.reset(); } } diff --git a/src/settings.rs b/src/settings.rs index b0c2285..0308c77 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -1,6 +1,6 @@ use bevy::prelude::*; -#[derive(Component)] +#[derive(Resource)] pub struct Settings { pub mute_sfx: bool, pub mute_music: bool, @@ -25,7 +25,3 @@ impl Settings { *self = Self::default(); } } - -pub fn setup(mut commands: Commands) { - commands.spawn(Settings::default()); -}