collapse chapters that are completely solved by default

This commit is contained in:
Crispy 2025-04-13 21:14:45 +02:00
parent 563c819900
commit 454c836b38
2 changed files with 19 additions and 7 deletions

View file

@ -44,6 +44,7 @@ logic mostly like https://git.crispypin.cc/CrispyPin/marble
- show histograms
- author name in solutions and blueprints
### undecided
- option to skip (speed through with settable multiplier) first N stages, for when you are debugging something that happens in later stages
- hide some tile tools in early levels to make it less overwhelming
- footprint score (tiles that were non-empty at any point in the run)
- option to use 8-bit marbles?

View file

@ -46,11 +46,8 @@ fn main() {
impl Game {
fn new(rl: &mut RaylibHandle, thread: &RaylibThread) -> Self {
let mut chapters = get_chapters();
let solutions = get_solutions();
if let Some(orphans) = find_orphans(&chapters, &solutions) {
chapters.push(orphans);
}
let chapters = get_chapters(&solutions);
Self {
chapters,
@ -358,11 +355,23 @@ impl Game {
}
}
fn get_chapters() -> Vec<Chapter> {
fn get_chapters(solutions: &HashMap<String, Vec<Solution>>) -> Vec<Chapter> {
let mut chapters = Vec::<Chapter>::new();
for d in read_dir("levels").unwrap().flatten() {
if let Ok(text) = read_to_string(d.path()) {
if let Ok(chapter) = serde_json::from_str(&text) {
if let Ok(mut chapter) = serde_json::from_str::<Chapter>(&text) {
chapter.visible = false;
for level in &chapter.levels {
if solutions
.get(level.id())
.map(|s| s.iter().any(|s| s.score.is_some()))
!= Some(true)
{
// only expand chapters where at least one level has no complete solutions
chapter.visible = true;
break;
}
}
chapters.push(chapter);
}
}
@ -386,7 +395,9 @@ fn get_chapters() -> Vec<Chapter> {
levels: custom_levels,
visible: true,
});
if let Some(orphans) = find_orphans(&chapters, solutions) {
chapters.push(orphans);
}
chapters
}