mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-12-22 20:32:38 +01:00
Move win condition to Level class, move sound muting back to main
This commit is contained in:
parent
2c4f8cb26e
commit
3291f0a78b
3 changed files with 30 additions and 24 deletions
30
level.gd
30
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")
|
||||
|
||||
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
16
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()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue