From 656f567242774f7d7ce6a41cfd1c98c07b65465e Mon Sep 17 00:00:00 2001 From: CrispyPin Date: Mon, 16 Dec 2024 22:50:51 +0100 Subject: [PATCH] select the last solution for each level --- src/main.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index b2f0f76..2d30e18 100644 --- a/src/main.rs +++ b/src/main.rs @@ -53,14 +53,23 @@ impl Game { textures.load_dir("assets/tiles", rl, thread); textures.load_dir("assets/digits", rl, thread); + let levels = get_levels(); + let solutions = get_solutions(); + let mut selected_solution = 0; + + // select the last solution of the first level, if there is one + if let Some(s) = levels.first().and_then(|l| solutions.get(l.id())) { + selected_solution = s.len().saturating_sub(1); + } + Self { - levels: get_levels(), + levels, level_scroll: 0, - solutions: get_solutions(), + solutions, open_editor: None, textures, selected_level: 0, - selected_solution: 0, + selected_solution, editing_solution_name: false, } } @@ -137,9 +146,13 @@ impl Game { && bounds.check_collision_point_rec(mouse_pos) && self.selected_level != index { - self.selected_solution = 0; self.editing_solution_name = false; self.selected_level = index; + self.selected_solution = 0; + // select the last solution of the level, if there is one + if let Some(solutions) = self.solutions.get(level.id()) { + self.selected_solution = solutions.len().saturating_sub(1); + } } d.draw_rectangle_rec(bounds, widget_bg(self.selected_level == index));