From 34841c496ba89a538098fe6d6a7a2a21957cfb57 Mon Sep 17 00:00:00 2001 From: bleeptrack Date: Tue, 22 Dec 2020 12:44:07 +0100 Subject: [PATCH] Show win states in level description --- scenes/level.gd | 10 ++++------ scenes/main.gd | 23 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/scenes/level.gd b/scenes/level.gd index 25ef896..1604fce 100644 --- a/scenes/level.gd +++ b/scenes/level.gd @@ -103,15 +103,13 @@ func construct(): game.global_shell.run(repo.setup_commands) func check_win(): - var won = true - var any_checked = false + var win_states = {} for r in repos: var repo = repos[r] if repo.win_conditions.size() > 0: - any_checked = true game.global_shell.cd(repo.path) for description in repo.win_conditions: var commands = repo.win_conditions[description] - if not game.global_shell.run("function win { %s\n}; win 2>/dev/null >/dev/null && echo yes || echo no" % commands) == "yes\n": - won = false - return won and any_checked + var won = game.global_shell.run("function win { %s\n}; win 2>/dev/null >/dev/null && echo yes || echo no" % commands) == "yes\n" + win_states[description] = won + return win_states diff --git a/scenes/main.gd b/scenes/main.gd index 5882b6c..b4f0c2d 100644 --- a/scenes/main.gd +++ b/scenes/main.gd @@ -96,6 +96,8 @@ func load_level(level_id): terminal.clear() terminal.find_node("TextEditor").close() + update_repos() + # Unmute the audio after a while, so that player can hear pop sounds for # nodes they create. var t = Timer.new() @@ -108,6 +110,7 @@ func load_level(level_id): chapter_select.select(current_chapter) level_select.select(current_level) + func reload_level(): levels.reload() @@ -117,8 +120,16 @@ func load_next_level(): current_level = (current_level + 1) % levels.chapters[current_chapter].levels.size() load_level(current_level) -func show_win_status(): - if not level_congrats.visible: +func show_win_status(win_states): + var all_won = true + var win_text = "\n\n" + for state in win_states: + win_text += "%s: %s\n" % [state, win_states[state]] + if not win_states[state]: + all_won = false + level_description.text = levels.chapters[current_chapter].levels[current_level].description + win_text + + if not level_congrats.visible and all_won and win_states.size() > 0: next_level_button.show() level_description.hide() level_congrats.show() @@ -145,8 +156,12 @@ func update_repos(): file_browser.update() index.update() - if levels.chapters[current_chapter].levels[current_level].check_win(): - show_win_status() + #if levels.chapters[current_chapter].levels[current_level].check_win(): + # show_win_status() + + var win_states = levels.chapters[current_chapter].levels[current_level].check_win() + show_win_status(win_states) + func toggle_cards(): cards.visible = not cards.visible