added some comments and polished up the code a bit

This commit is contained in:
grimsace
2026-03-19 13:49:42 -05:00
parent 8221040eed
commit 35cbf18d56
6 changed files with 127 additions and 7 deletions
+3
View File
@@ -7,12 +7,14 @@ use crate::ui::UiSettings;
const APP_DIR_NAME: &str = "desktop_dungeon_generator";
const SETTINGS_FILE_NAME: &str = "settings.json";
// Load settings JSON from the user data directory.
pub fn load_settings() -> Option<UiSettings> {
let path = settings_path()?;
let content = fs::read_to_string(path).ok()?;
serde_json::from_str::<UiSettings>(&content).ok()
}
// Save settings JSON to the user data directory.
pub fn save_settings(settings: &UiSettings) -> io::Result<()> {
let path = settings_path().ok_or_else(|| {
io::Error::new(
@@ -30,6 +32,7 @@ pub fn save_settings(settings: &UiSettings) -> io::Result<()> {
fs::write(path, json)
}
// Build the full path for the settings file.
fn settings_path() -> Option<PathBuf> {
let base = dirs::data_local_dir().or_else(dirs::data_dir)?;
Some(base.join(APP_DIR_NAME).join(SETTINGS_FILE_NAME))