From f0b878e93d0426f8d02b18723002271679c4fce0 Mon Sep 17 00:00:00 2001
From: CrispyPin <crispin@tasa.se>
Date: Sun, 20 Apr 2025 19:54:53 +0200
Subject: [PATCH] fix crash when saving config before user dir exists

---
 CHANGELOG.md |  1 +
 README.md    | 10 ++++++++--
 src/main.rs  | 11 ++++++++---
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc9425d..e3ad623 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@ Game store page: https://crispypin.itch.io/marble-machinations
 
 ## [unreleased]
 ### fixed
+- crash when saving config if no user dir exists
 - 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
 
diff --git a/README.md b/README.md
index f873cb3..f2233e7 100644
--- a/README.md
+++ b/README.md
@@ -9,12 +9,17 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
 - engine tests
 - blag post about marble movement logic?
 ### bugs
-
+- input tiles still consume input when their marble creation is blocked
+- Shift+A and A+Shift conflict
+- rigt side grid rendering broken
 ### features
 #### 0.3.x
 - more levels
   - packet routing?
   - 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
 - UI layout engine
   - 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
 - accessibility
   - background colour setting (requires color picker => after UI rework)
+  - light theme for UI
   - hotkeys for everything (no mouse needed to play)
     - menu navigation (requires UI rework)
     - speed up/down
@@ -42,7 +48,7 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
 - show histograms
 - author name in solutions and blueprints
 ### 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
 - footprint score (tiles that were non-empty at any point in the run)
 - option to use 8-bit marbles?
diff --git a/src/main.rs b/src/main.rs
index c0978e6..6d2b0eb 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,6 +1,6 @@
 use std::{
 	collections::HashMap,
-	fs::{read_dir, read_to_string, File},
+	fs::{create_dir_all, read_dir, read_to_string, File},
 	io::Write,
 };
 
@@ -348,10 +348,15 @@ impl Game {
 	}
 
 	fn save_config(&self) {
+		_ = create_dir_all(userdata_dir());
 		let path = userdata_dir().join(CONFIG_FILE_NAME);
 		let json = serde_json::to_string_pretty(&self.globals.config).unwrap();
-		let mut f = File::create(path).unwrap();
-		f.write_all(json.as_bytes()).unwrap();
+		match File::create(path) {
+			Ok(mut f) => {
+				_ = f.write_all(json.as_bytes());
+			}
+			Err(e) => println!("error saving config: {e}"),
+		}
 	}
 }