1
Fork 0
mirror of https://github.com/redstrate/Kawari.git synced 2025-04-23 15:47:45 +00:00
kawari/src/config.rs

41 lines
929 B
Rust
Raw Normal View History

2023-10-05 12:09:05 -04:00
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
pub struct Config {
2024-05-11 13:41:00 -04:00
#[serde(default)]
2024-06-29 14:06:44 -04:00
pub worlds_open: bool,
#[serde(default)]
pub login_open: bool,
2024-05-11 13:41:00 -04:00
#[serde(default = "default_supported_platforms")]
pub supported_platforms: Vec<String>,
}
impl Default for Config {
fn default() -> Self {
Self {
2024-06-29 14:06:44 -04:00
worlds_open: false,
login_open: false,
2024-05-11 13:41:00 -04:00
supported_platforms: default_supported_platforms()
}
}
2024-05-11 13:41:00 -04:00
}
impl Config {
pub fn supports_platform(&self, platform: &String) -> bool {
self.supported_platforms.contains(platform)
}
}
fn default_supported_platforms() -> Vec<String> {
vec!["win32".to_string()]
}
pub fn get_config() -> Config {
if let Ok(data) = std::fs::read_to_string("config.json") {
serde_json::from_str(&data).expect("Failed to parse")
} else {
Config::default()
}
2023-10-05 12:09:05 -04:00
}