Merge branch '39-game-configuration-fallback' into 'dev'

Resolve "Game Configuration Fallback"

See merge request softwaregrundprojekt/2025-2026/einzelprojekt/tutorium-moritz/bernroider-dominik/bernroider-dominik!9
This commit is contained in:
Dominik Bernroider
2025-11-24 17:04:14 +00:00
3 changed files with 15 additions and 5 deletions

View File

@@ -1,5 +1,5 @@
{ {
"grid_width": 10, "grid_width": 12,
"grid_height": 10, "grid_height": 4,
"pom_speed": 2 "pom_speed": 1.5
} }

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((