track the source of the preferences

This commit is contained in:
yuni 2024-04-30 23:15:55 +02:00
parent f9e3046799
commit 00ce509935

View file

@ -15,7 +15,6 @@ use bevy::prelude::*;
use std::collections::HashMap; use std::collections::HashMap;
use serde::Deserialize; use serde::Deserialize;
use toml_edit::DocumentMut; use toml_edit::DocumentMut;
use toml_edit::de::from_document;
use std::env; use std::env;
use std::fs; use std::fs;
@ -37,6 +36,9 @@ pub struct Preferences {
pub fullscreen_mode: String, pub fullscreen_mode: String,
pub window_mode: String, pub window_mode: String,
pub render_mode: String, pub render_mode: String,
#[serde(skip)]
pub source_file: Option<String>,
} }
impl Default for Preferences { impl Default for Preferences {
@ -45,6 +47,7 @@ impl Default for Preferences {
fullscreen_mode: "borderless".to_string(), fullscreen_mode: "borderless".to_string(),
window_mode: "fullscreen".to_string(), window_mode: "fullscreen".to_string(),
render_mode: "vulkan".to_string(), render_mode: "vulkan".to_string(),
source_file: None,
} }
} }
} }
@ -90,9 +93,10 @@ pub fn load_prefs() -> Preferences {
}; };
match toml.parse::<DocumentMut>() { match toml.parse::<DocumentMut>() {
Ok(doc) => { Ok(doc) => {
match from_document::<Preferences>(doc) { match toml_edit::de::from_document::<Preferences>(doc) {
Ok(pref) => { Ok(mut pref) => {
info!("Loaded preference file from {prefs_path}"); info!("Loaded preference file from {prefs_path}");
pref.source_file = Some(prefs_path);
dbg!(&pref); dbg!(&pref);
return pref; return pref;
} }