diff --git a/level.gd b/level.gd index e891ccc..46d99b9 100644 --- a/level.gd +++ b/level.gd @@ -8,6 +8,9 @@ var start_commands var goal_commands var win_commands +var _goal_repository_path = game.tmp_prefix_inside+"/repos/goal/" +var _active_repository_path = game.tmp_prefix_inside+"/repos/active/" + # The path is an outer path. func load(path): var parts = path.split("/") @@ -25,32 +28,17 @@ func load(path): win_commands = helpers.read_file(path+"/win", "exit 1\n") func construct(): - AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), true) - - var goal_repository_path = game.tmp_prefix_inside+"/repos/goal/" - var active_repository_path = game.tmp_prefix_inside+"/repos/active/" - # We're actually destroying stuff here. # Make sure that active_repository is in a temporary directory. - helpers.careful_delete(active_repository_path) - helpers.careful_delete(goal_repository_path) + helpers.careful_delete(_active_repository_path) + helpers.careful_delete(_goal_repository_path) - _construct_repo(start_commands +"\n"+ goal_commands, goal_repository_path) - _construct_repo(start_commands, active_repository_path) + _construct_repo(start_commands +"\n"+ goal_commands, _goal_repository_path) + _construct_repo(start_commands, _active_repository_path) var win_script_target = game.tmp_prefix_outside+"/win" helpers.write_file(win_script_target, win_commands) - # Unmute the audio after a while, so that player can hear pop sounds for - # nodes they create. - var t = Timer.new() - t.wait_time = 3 - add_child(t) - t.start() - yield(t, "timeout") - AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), false) - # FIXME: Need to clean these up when switching levels somehow. - func _construct_repo(script_content, path): # Becase in an exported game, all assets are in a .pck file, we need to put # the script somewhere in the filesystem. @@ -65,3 +53,7 @@ func _construct_repo(script_content, path): game.global_shell.run("git symbolic-ref HEAD refs/heads/main") # Read stdin from /dev/null so that interactive commands don't block. game.global_shell.run("bash "+script_path_inside+" /dev/null >/dev/null && echo yes || echo no" % game.tmp_prefix_inside) == "yes\n" diff --git a/main.gd b/main.gd index 9c5481f..56c2c51 100644 --- a/main.gd +++ b/main.gd @@ -54,6 +54,8 @@ func load_level(level_id): level_description.show() current_level = level_id + AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), true) + levels.chapters[current_chapter].levels[current_level].construct() var goal_repository_path = game.tmp_prefix_inside+"/repos/goal/" @@ -67,6 +69,16 @@ func load_level(level_id): goal_repository.path = goal_repository_path active_repository.path = active_repository_path terminal.clear() + + # Unmute the audio after a while, so that player can hear pop sounds for + # nodes they create. + var t = Timer.new() + t.wait_time = 3 + add_child(t) + t.start() + yield(t, "timeout") + AudioServer.set_bus_mute(AudioServer.get_bus_index("Master"), false) + # FIXME: Need to clean these up when switching levels somehow. func reload_level(): load_level(current_level) @@ -91,3 +103,7 @@ func repopulate_chapters(): chapter_select.clear() for c in levels.chapters: chapter_select.add_item(c.slug) + +func check_win_condition(): + if levels.chapters[current_chapter].levels[current_level].check_win(): + show_win_status() diff --git a/terminal.gd b/terminal.gd index 8e97fdc..77c3130 100644 --- a/terminal.gd +++ b/terminal.gd @@ -94,7 +94,9 @@ func send_command_async(command): func run_command_in_a_thread(command): var o = repository.shell.run(command, false) - check_win_condition() + + if main: + main.check_win_condition() input.text = "" input.editable = true @@ -115,10 +117,6 @@ func clear(): func editor_closed(): input.grab_focus() - -func check_win_condition(): - if repository.shell.run("bash %s/win 2>/dev/null >/dev/null && echo yes || echo no" % game.tmp_prefix_inside) == "yes\n": - main.show_win_status() func regenerate_completions_menu(new_text): var comp = generate_completions(new_text)