From 15f6cc70d4e92604127b6b00ac7bc2867d12f829 Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Sun, 13 Oct 2024 13:01:54 +0200 Subject: [PATCH] save solutions when renamed, fix solution filenames --- src/main.rs | 6 ++++-- src/solution.rs | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main.rs b/src/main.rs index 9e63b89..132552e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -219,14 +219,16 @@ impl Game { if let Some(solution) = solutions.get_mut(self.selected_solution) { let column_x = level_list_width + entry_width + 20; let bounds = Rectangle::new(column_x as f32, y as f32, 220., 30.); - text_input( + if text_input( d, bounds, &mut solution.name, &mut self.editing_solution_name, 24, true, - ); + ){ + solution.save(); + } let id_text = format!("{}", solution.id()); d.draw_text(&id_text, column_x, y + 35, 10, Color::GRAY); diff --git a/src/solution.rs b/src/solution.rs index ffc9b89..09fdee8 100644 --- a/src/solution.rs +++ b/src/solution.rs @@ -49,7 +49,7 @@ impl Solution { pub fn save(&self) { let dir = userdata_dir().join("solutions").join(&self.level_id); fs::create_dir_all(&dir).unwrap(); - let path = dir.join(format!("{}.json", &self.solution_id)); + let path = dir.join(format!("solution_{}.json", &self.solution_id)); let json = serde_json::to_string_pretty(self).unwrap(); let mut file = File::create(path).unwrap();