use std::fs;
use serde::Deserialize;
use crate::base::{
JEXT,
PrependErrorString
};
const CONFIG_FILEPATH_NOEXT: &str = "config";
#[derive(Deserialize)]
pub struct Config {
pub width: i32,
pub height: i32,
pub vsync: bool,
pub frame_rate: i32,
pub mouse_sensitivity: i32,
pub left_hand: bool,
pub mute: bool,
pub vol_music: i32,
pub vol_sound: i32,
pub vol_speech: i32,
pub lang: String
}
impl Config {
pub fn load() -> Result<Config, String> {
let filepath = format!("{}.{}", CONFIG_FILEPATH_NOEXT, JEXT);
let b = fs::read(&filepath).pre_err("cannot read config file")?;
let c: Config = serde_json::from_slice(&b).pre_err("cannot parse config json")?;
Ok(c)
}
}