From 4718271ba201b8d39eb1f0ed18d4d3e9dfe7c6df Mon Sep 17 00:00:00 2001 From: demenik Date: Mon, 24 Nov 2025 18:03:14 +0100 Subject: [PATCH] feat: Add configuration fallback #39 --- src/config.rs | 10 ++++++++++ src/main.rs | 4 ++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 979ccb8..74b828b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,6 +10,16 @@ pub struct GameConfig { 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 { let file = File::open("assets/config.json").ok()?; let reader = BufReader::new(file); diff --git a/src/main.rs b/src/main.rs index 9404c2c..e7b159d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,11 +1,11 @@ use bevy::prelude::*; use bevy_aseprite_ultra::prelude::*; use bevy_dev_tools::fps_overlay::*; -use pomomon_garden::config::read_config; +use pomomon_garden::config::{GameConfig, read_config}; use pomomon_garden::plugins; fn main() { - let config = read_config().expect("Error reading config"); + let config = read_config().unwrap_or(GameConfig::default()); App::new() .add_plugins((