From 5a8c37716094f23b5fc902484b1abf8fdaeb8ac0 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Tue, 8 Sep 2020 16:36:52 +0200 Subject: [PATCH] Copy fake-editor to /tmp when starting (the original might be in a .pck file) --- game.gd | 14 +++++++++----- main.gd | 11 +++++------ shell.gd | 10 +++++++--- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/game.gd b/game.gd index 8735b48..d4e8eeb 100644 --- a/game.gd +++ b/game.gd @@ -1,12 +1,19 @@ extends Node +var tmp_prefix = "/tmp/" var cwd +var global_shell func _ready(): - cwd = exec("pwd", [], true) + global_shell = Shell.new() + global_shell.cd(tmp_prefix) + + cwd = global_shell.run("pwd") + # Remove trailing newline. + cwd = cwd.substr(0,len(cwd)-1) # Run a simple command with arguments, blocking, using OS.execute. -func exec(command, args=[], remote_trailing_newline=false): +func exec(command, args=[]): var debug = true if debug: print("game.exec: %s [%s]" % [command, PoolStringArray(args).join(", ")]) @@ -17,9 +24,6 @@ func exec(command, args=[], remote_trailing_newline=false): if debug: print(output) - - if remote_trailing_newline: - output = output.substr(0,len(output)-1) return output diff --git a/main.gd b/main.gd index 661571e..65466ef 100644 --- a/main.gd +++ b/main.gd @@ -46,18 +46,17 @@ func load_level(id): var levels = list_levels() var level = levels[id] - var tmp_prefix = "/tmp/" var level_prefix = "res://levels/" - var goal_repository_path = tmp_prefix+"goal/" - var active_repository_path = tmp_prefix+"active/" + var goal_repository_path = game.tmp_prefix+"goal/" + var active_repository_path = game.tmp_prefix+"active/" var goal_script = level_prefix+level+"/goal" var active_script = level_prefix+level+"/start" var description = game.read_file(level_prefix+level+"/description") $LevelDescription.bbcode_text = description - # Danger zone! We're actually destroying stuff here. + # We're actually destroying stuff here. # Make sure that active_repository is in a temporary directory. var expected_prefix = "/tmp" if active_repository_path.substr(0,4) != expected_prefix: @@ -67,6 +66,7 @@ func load_level(id): push_error("Refusing to delete a directory that does not start with %s" % expected_prefix) get_tree().quit() + # Danger zone! game.exec("rm", ["-rf", active_repository_path]) game.exec("rm", ["-rf", goal_repository_path]) @@ -80,8 +80,7 @@ func construct_repo(script, path): # Becase in an exported game, all assets are in a .pck file, we need to put # the script somewhere in the filesystem. var content = game.read_file(script) - var tmp_prefix = "/tmp" - var script_path = tmp_prefix+"/git-hydra-script" + var script_path = game.tmp_prefix+"/git-hydra-script" game.write_file(script_path, content) var shell = Shell.new() diff --git a/shell.gd b/shell.gd index 2bba1bf..701f16e 100644 --- a/shell.gd +++ b/shell.gd @@ -2,9 +2,14 @@ extends Node class_name Shell var _cwd +var _fake_editor func _init(): - pass + # Copy fake-editor to tmp directory (because the original might be in a .pck file). + _fake_editor = game.tmp_prefix + "fake-editor" + var content = game.read_file("res://scripts/fake-editor") + game.write_file(_fake_editor, content) + run("chmod u+x " + _fake_editor) func cd(dir): _cwd = dir @@ -18,8 +23,7 @@ func run(command): print("$ %s" % command) var env = {} - env["EDITOR"] = game.cwd+"/scripts/fake-editor" - env["TEST"] = "hi" + env["EDITOR"] = _fake_editor var hacky_command = "" for variable in env: