feat: Add configuration fallback #39

This commit is contained in:
demenik
2025-11-24 18:03:14 +01:00
parent 09a8282688
commit 4718271ba2
2 changed files with 12 additions and 2 deletions

View File

@@ -10,6 +10,16 @@ pub struct GameConfig {
pub pom_speed: f32, pub pom_speed: f32,
} }
impl Default for GameConfig {
fn default() -> Self {
Self {
grid_width: 12,
grid_height: 4,
pom_speed: 1.5,
}
}
}
pub fn read_config() -> Option<GameConfig> { pub fn read_config() -> Option<GameConfig> {
let file = File::open("assets/config.json").ok()?; let file = File::open("assets/config.json").ok()?;
let reader = BufReader::new(file); let reader = BufReader::new(file);

View File

@@ -1,11 +1,11 @@
use bevy::prelude::*; use bevy::prelude::*;
use bevy_aseprite_ultra::prelude::*; use bevy_aseprite_ultra::prelude::*;
use bevy_dev_tools::fps_overlay::*; use bevy_dev_tools::fps_overlay::*;
use pomomon_garden::config::read_config; use pomomon_garden::config::{GameConfig, read_config};
use pomomon_garden::plugins; use pomomon_garden::plugins;
fn main() { fn main() {
let config = read_config().expect("Error reading config"); let config = read_config().unwrap_or(GameConfig::default());
App::new() App::new()
.add_plugins(( .add_plugins((