From 2c4f8cb26e71ea1d12d0263e9a4bd223063fe5da Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Tue, 29 Sep 2020 19:50:58 +0200 Subject: [PATCH] Move level construction stuff to Level class --- level.gd | 42 ++++++++++++++++++++++++++++++++++++++++++ main.gd | 47 +++++------------------------------------------ 2 files changed, 47 insertions(+), 42 deletions(-) diff --git a/level.gd b/level.gd index 15c8e17..e891ccc 100644 --- a/level.gd +++ b/level.gd @@ -23,3 +23,45 @@ func load(path): start_commands = helpers.read_file(path+"/start", "") goal_commands = helpers.read_file(path+"/goal", "") 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) + + _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. + + var script_path_outside = game.tmp_prefix_outside+"/git-hydra-script" + var script_path_inside = game.tmp_prefix_inside+"/git-hydra-script" + helpers.write_file(script_path_outside, script_content) + + game.global_shell.run("mkdir " + path) + game.global_shell.cd(path) + game.global_shell.run("git init") + 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+"