Move win condition to Level class, move sound muting back to main

This commit is contained in:
Sebastian Morr 2020-09-29 20:01:25 +02:00
parent 2c4f8cb26e
commit 3291f0a78b
3 changed files with 30 additions and 24 deletions

View file

@ -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")
func check_win():
game.global_shell.cd(_active_repository_path)
return game.global_shell.run("bash %s/win 2>/dev/null >/dev/null && echo yes || echo no" % game.tmp_prefix_inside) == "yes\n"

16
main.gd
View file

@ -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/"
@ -68,6 +70,16 @@ func load_level(level_id):
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()

View file

@ -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
@ -116,10 +118,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)