add settings.rs

This commit is contained in:
yuni 2024-03-16 22:20:23 +01:00
parent 50e731a3ca
commit b223dcdb29
2 changed files with 40 additions and 0 deletions

View file

@ -2,6 +2,7 @@ mod audio;
mod player;
mod camera;
mod world;
mod settings;
use bevy::window::{Window, WindowMode, PrimaryWindow, CursorGrabMode };
use bevy::prelude::*;
@ -10,6 +11,7 @@ fn main() {
App::new()
.add_systems(Startup, (
setup,
settings::setup,
audio::setup,
player::setup,
world::setup,
@ -37,9 +39,16 @@ fn setup(
fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>,
mut settings: Query<&mut settings::Settings>,
mut app_exit_events: ResMut<Events<bevy::app::AppExit>>
) {
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()
}
}
}

31
src/settings.rs Normal file
View file

@ -0,0 +1,31 @@
use bevy::prelude::*;
#[derive(Component)]
pub struct Settings {
pub mute_sfx: bool,
pub mute_music: bool,
pub volume_sfx: u8,
pub volume_music: u8,
}
impl Default for Settings {
fn default() -> Self {
Settings {
mute_sfx: false,
mute_music: false,
volume_sfx: 100,
volume_music: 100,
}
}
}
impl Settings {
pub fn reset(&mut self) {
println!("Resetting settings!");
*self = Self::default();
}
}
pub fn setup(mut commands: Commands) {
commands.spawn(Settings::default());
}