fix crash when saving config before user dir exists

This commit is contained in:
Crispy 2025-04-20 19:54:53 +02:00
parent 509b577aaa
commit f0b878e93d
3 changed files with 17 additions and 5 deletions

View file

@ -3,6 +3,7 @@ Game store page: https://crispypin.itch.io/marble-machinations
## [unreleased] ## [unreleased]
### fixed ### fixed
- crash when saving config if no user dir exists
- keybindings activated even when typing in a text field, making especially renaming blueprints difficult - keybindings activated even when typing in a text field, making especially renaming blueprints difficult
- after removing a binding that was a superset of another, the remaining one did not stop being blocked by the removed ones additional modifiers until another binding was added or edited - after removing a binding that was a superset of another, the remaining one did not stop being blocked by the removed ones additional modifiers until another binding was added or edited

View file

@ -9,12 +9,17 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
- engine tests - engine tests
- blag post about marble movement logic? - blag post about marble movement logic?
### bugs ### bugs
- input tiles still consume input when their marble creation is blocked
- Shift+A and A+Shift conflict
- rigt side grid rendering broken
### features ### features
#### 0.3.x #### 0.3.x
- more levels - more levels
- packet routing? - packet routing?
- game of life sim (width;height;steps;grid -> grid) - game of life sim (width;height;steps;grid -> grid)
- show level name in end popup
- hide timing debug info by default
- shrink button
#### 0.4.0 #### 0.4.0
- UI layout engine - UI layout engine
- global scale setting - global scale setting
@ -26,6 +31,7 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
- button + binding to flip selection that is being pasted - button + binding to flip selection that is being pasted
- accessibility - accessibility
- background colour setting (requires color picker => after UI rework) - background colour setting (requires color picker => after UI rework)
- light theme for UI
- hotkeys for everything (no mouse needed to play) - hotkeys for everything (no mouse needed to play)
- menu navigation (requires UI rework) - menu navigation (requires UI rework)
- speed up/down - speed up/down
@ -42,7 +48,7 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
- show histograms - show histograms
- author name in solutions and blueprints - author name in solutions and blueprints
### undecided ### undecided
- option to skip (speed through with settable multiplier) first N stages, for when you are debugging something that happens in later stages - option to skip (speed through with settable multiplier) first N stages or cycles, for when you are debugging something that happens in later stages
- hide some tile tools in early levels to make it less overwhelming - hide some tile tools in early levels to make it less overwhelming
- footprint score (tiles that were non-empty at any point in the run) - footprint score (tiles that were non-empty at any point in the run)
- option to use 8-bit marbles? - option to use 8-bit marbles?

View file

@ -1,6 +1,6 @@
use std::{ use std::{
collections::HashMap, collections::HashMap,
fs::{read_dir, read_to_string, File}, fs::{create_dir_all, read_dir, read_to_string, File},
io::Write, io::Write,
}; };
@ -348,10 +348,15 @@ impl Game {
} }
fn save_config(&self) { fn save_config(&self) {
_ = create_dir_all(userdata_dir());
let path = userdata_dir().join(CONFIG_FILE_NAME); let path = userdata_dir().join(CONFIG_FILE_NAME);
let json = serde_json::to_string_pretty(&self.globals.config).unwrap(); let json = serde_json::to_string_pretty(&self.globals.config).unwrap();
let mut f = File::create(path).unwrap(); match File::create(path) {
f.write_all(json.as_bytes()).unwrap(); Ok(mut f) => {
_ = f.write_all(json.as_bytes());
}
Err(e) => println!("error saving config: {e}"),
}
} }
} }