select the last solution for each level
This commit is contained in:
parent
4427b4c2fc
commit
656f567242
1 changed files with 17 additions and 4 deletions
21
src/main.rs
21
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));
|
||||
|
||||
|
|
Loading…
Reference in a new issue