Files
pomomon-garden/src/features/config/components.rs
2025-12-09 15:20:42 +01:00

72 lines
1.9 KiB
Rust

use crate::prelude::*;
use std::fs::File;
use std::io::BufReader;
#[derive(Resource, Deserialize, Debug)]
pub struct GameConfig {
pub grid_width: u32,
pub grid_height: u32,
pub pom_speed: f32,
pub shovel_base_price: u32,
pub shovel_rate: f32,
pub berry_seeds: Vec<BerrySeedConfig>,
pub wonder_event_url: String,
}
#[derive(Deserialize, Debug, Clone)]
pub struct BerrySeedConfig {
pub name: String,
pub cost: u32,
pub grants: u32,
pub slice: String,
pub growth_stages: u32,
}
impl Default for GameConfig {
fn default() -> Self {
Self {
grid_width: 12,
grid_height: 4,
pom_speed: 1.5,
shovel_base_price: 10,
shovel_rate: 0.2,
berry_seeds: vec![
BerrySeedConfig {
name: "Normale Samen".to_string(),
cost: 1,
grants: 2,
slice: "Seed1".to_string(),
growth_stages: 2,
},
BerrySeedConfig {
name: "Super-Samen".to_string(),
cost: 3,
grants: 9,
slice: "Seed2".to_string(),
growth_stages: 4,
},
BerrySeedConfig {
name: "Zauber-Samen".to_string(),
cost: 5,
grants: 20,
slice: "Seed3".to_string(),
growth_stages: 6,
},
],
wonder_event_url: "wss://pomomon.farm/ws".into(),
}
}
}
impl GameConfig {
pub fn read_config() -> Option<Self> {
Self::read_from_path(std::path::Path::new("assets/config.json"))
}
pub fn read_from_path(path: &std::path::Path) -> Option<Self> {
let file = File::open(path).ok()?;
let reader = BufReader::new(file);
serde_json::from_reader(reader).ok()
}
}