add more levels and organise them into sections
This commit is contained in:
parent
172cfc9409
commit
67557832fa
12 changed files with 96 additions and 28 deletions
21
src/main.rs
21
src/main.rs
|
@ -94,7 +94,7 @@ impl Game {
|
|||
fn draw(&mut self, d: &mut RaylibDrawHandle) {
|
||||
d.clear_background(Color::new(64, 64, 64, 255));
|
||||
|
||||
let level_list_width = d.get_screen_width() / 3;
|
||||
let level_list_width = (d.get_screen_width() / 3).min(400);
|
||||
let screen_height = d.get_screen_height();
|
||||
d.draw_rectangle(0, 0, level_list_width, screen_height, Color::GRAY);
|
||||
|
||||
|
@ -230,21 +230,30 @@ impl Game {
|
|||
|
||||
fn get_levels() -> Vec<Level> {
|
||||
let mut levels = Vec::<Level>::new();
|
||||
for d in read_dir("levels").unwrap().flatten() {
|
||||
let l = read_to_string(d.path())
|
||||
let mut add_level = |path| {
|
||||
let l = read_to_string(path)
|
||||
.ok()
|
||||
.as_deref()
|
||||
.and_then(|s| serde_json::from_str(s).ok());
|
||||
if let Some(level) = l {
|
||||
levels.push(level);
|
||||
}
|
||||
};
|
||||
for d in read_dir("levels").unwrap().flatten() {
|
||||
if d.path().is_dir() {
|
||||
for d in read_dir(d.path()).unwrap().flatten() {
|
||||
add_level(d.path());
|
||||
}
|
||||
} else {
|
||||
add_level(d.path());
|
||||
}
|
||||
}
|
||||
levels.sort_by_key(Level::sort_order);
|
||||
levels
|
||||
}
|
||||
|
||||
fn get_solutions() -> HashMap<String, Vec<Solution>> {
|
||||
let mut levels = HashMap::new();
|
||||
let mut by_level = HashMap::new();
|
||||
let solution_dir = userdata_dir().join("solutions");
|
||||
if let Ok(dir_contents) = read_dir(solution_dir) {
|
||||
for dir in dir_contents.flatten() {
|
||||
|
@ -263,11 +272,11 @@ fn get_solutions() -> HashMap<String, Vec<Solution>> {
|
|||
}
|
||||
}
|
||||
|
||||
levels.insert(level_name, solutions);
|
||||
by_level.insert(level_name, solutions);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
levels
|
||||
by_level
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue