feat: Add configuration fallback #39
This commit is contained in:
@@ -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);
|
||||||
|
|||||||
@@ -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((
|
||||||
|
|||||||
Reference in New Issue
Block a user