add GameVars struct

This commit is contained in:
yuni 2024-04-14 15:37:36 +02:00
parent 7b6b14a992
commit 07be89162c

View file

@ -1,4 +1,5 @@
use bevy::prelude::*; use bevy::prelude::*;
use std::collections::HashMap;
use std::env; use std::env;
pub const DEFAULT_CHAT_SPEED: f32 = 10.0; pub const DEFAULT_CHAT_SPEED: f32 = 10.0;
@ -188,3 +189,41 @@ impl Settings {
]; ];
} }
} }
#[derive(Resource)]
struct GameVars {
pub db: HashMap<String, String>,
}
impl GameVars {
#[allow(dead_code)]
fn get(&self, key: &str) -> Option<String> {
if let Some(value) = self.db.get(key) {
return Some(value.clone());
}
return None;
}
#[allow(dead_code)]
fn getf(&self, key: &str) -> Option<f64> {
if let Some(value) = self.db.get(key) {
if let Ok(float) = value.parse::<f64>() {
return Some(float);
}
}
return None;
}
#[allow(dead_code)]
fn getb(&self, key: &str) -> bool {
if let Some(value) = self.db.get(key) {
return value != "0";
}
return false;
}
#[allow(dead_code)]
fn set(&mut self, key: &str, value: String) {
self.db.insert(key.to_string(), value);
}
}