save solutions when renamed, fix solution filenames

This commit is contained in:
Crispy 2024-10-13 13:01:54 +02:00
parent 866a4c7127
commit 15f6cc70d4
2 changed files with 5 additions and 3 deletions

View file

@ -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);

View file

@ -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();