save solutions when renamed, fix solution filenames
This commit is contained in:
parent
866a4c7127
commit
15f6cc70d4
2 changed files with 5 additions and 3 deletions
|
@ -219,14 +219,16 @@ impl Game {
|
||||||
if let Some(solution) = solutions.get_mut(self.selected_solution) {
|
if let Some(solution) = solutions.get_mut(self.selected_solution) {
|
||||||
let column_x = level_list_width + entry_width + 20;
|
let column_x = level_list_width + entry_width + 20;
|
||||||
let bounds = Rectangle::new(column_x as f32, y as f32, 220., 30.);
|
let bounds = Rectangle::new(column_x as f32, y as f32, 220., 30.);
|
||||||
text_input(
|
if text_input(
|
||||||
d,
|
d,
|
||||||
bounds,
|
bounds,
|
||||||
&mut solution.name,
|
&mut solution.name,
|
||||||
&mut self.editing_solution_name,
|
&mut self.editing_solution_name,
|
||||||
24,
|
24,
|
||||||
true,
|
true,
|
||||||
);
|
){
|
||||||
|
solution.save();
|
||||||
|
}
|
||||||
let id_text = format!("{}", solution.id());
|
let id_text = format!("{}", solution.id());
|
||||||
d.draw_text(&id_text, column_x, y + 35, 10, Color::GRAY);
|
d.draw_text(&id_text, column_x, y + 35, 10, Color::GRAY);
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ impl Solution {
|
||||||
pub fn save(&self) {
|
pub fn save(&self) {
|
||||||
let dir = userdata_dir().join("solutions").join(&self.level_id);
|
let dir = userdata_dir().join("solutions").join(&self.level_id);
|
||||||
fs::create_dir_all(&dir).unwrap();
|
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 json = serde_json::to_string_pretty(self).unwrap();
|
||||||
let mut file = File::create(path).unwrap();
|
let mut file = File::create(path).unwrap();
|
||||||
|
|
Loading…
Reference in a new issue