turn settings into a resource

This commit is contained in:
yuni 2024-03-17 18:26:44 +01:00
parent 25298b2951
commit d58e9ebb1e
2 changed files with 4 additions and 11 deletions

View file

@ -13,7 +13,6 @@ fn main() {
App::new() App::new()
.add_systems(Startup, ( .add_systems(Startup, (
setup, setup,
settings::setup,
audio::setup, audio::setup,
player::setup, player::setup,
world::setup, world::setup,
@ -33,6 +32,7 @@ fn main() {
FrameTimeDiagnosticsPlugin, FrameTimeDiagnosticsPlugin,
LogDiagnosticsPlugin::default(), LogDiagnosticsPlugin::default(),
)) ))
.insert_resource(settings::Settings::default())
.run(); .run();
} }
@ -50,16 +50,13 @@ fn setup(
fn handle_input( fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>, keyboard_input: Res<ButtonInput<KeyCode>>,
mut settings: Query<&mut settings::Settings>, mut settings: ResMut<settings::Settings>,
mut app_exit_events: ResMut<Events<bevy::app::AppExit>> mut app_exit_events: ResMut<Events<bevy::app::AppExit>>
) { ) {
if keyboard_input.pressed(KeyCode::KeyQ) { if keyboard_input.pressed(KeyCode::KeyQ) {
app_exit_events.send(bevy::app::AppExit); app_exit_events.send(bevy::app::AppExit);
} }
if keyboard_input.just_pressed(KeyCode::F12) { if keyboard_input.just_pressed(KeyCode::F12) {
let result = settings.get_single_mut(); settings.reset();
if result.is_ok() {
result.unwrap().reset()
}
} }
} }

View file

@ -1,6 +1,6 @@
use bevy::prelude::*; use bevy::prelude::*;
#[derive(Component)] #[derive(Resource)]
pub struct Settings { pub struct Settings {
pub mute_sfx: bool, pub mute_sfx: bool,
pub mute_music: bool, pub mute_music: bool,
@ -25,7 +25,3 @@ impl Settings {
*self = Self::default(); *self = Self::default();
} }
} }
pub fn setup(mut commands: Commands) {
commands.spawn(Settings::default());
}