From 4fff68253c3bbc5fd34e3bde521d31aa562e3aa5 Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Tue, 8 Sep 2020 16:27:36 +0200 Subject: [PATCH] Allow exported Linux builds to run When referring to local game files, we always need to use "res://". --- game.gd | 7 ++++--- main.gd | 17 ++++++++++++----- shell.gd | 2 +- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/game.gd b/game.gd index ce3a99e..8735b48 100644 --- a/game.gd +++ b/game.gd @@ -7,7 +7,7 @@ func _ready(): # Run a simple command with arguments, blocking, using OS.execute. func exec(command, args=[], remote_trailing_newline=false): - var debug = false + var debug = true if debug: print("game.exec: %s [%s]" % [command, PoolStringArray(args).join(", ")]) @@ -20,11 +20,11 @@ func exec(command, args=[], remote_trailing_newline=false): if remote_trailing_newline: output = output.substr(0,len(output)-1) - + return output func read_file(path): - print("read "+path) + print ("reading " + path) var file = File.new() file.open(path, File.READ) var content = file.get_as_text() @@ -32,6 +32,7 @@ func read_file(path): return content func write_file(path, content): + print ("writing " + path) var file = File.new() file.open(path, File.WRITE) file.store_string(content) diff --git a/main.gd b/main.gd index 5639b87..661571e 100644 --- a/main.gd +++ b/main.gd @@ -28,7 +28,7 @@ func _ready(): func list_levels(): var levels = [] var dir = Directory.new() - dir.open("levels") + dir.open("res://levels") dir.list_dir_begin() while true: @@ -47,7 +47,7 @@ func load_level(id): var level = levels[id] var tmp_prefix = "/tmp/" - var level_prefix = game.cwd + "/levels/" + var level_prefix = "res://levels/" var goal_repository_path = tmp_prefix+"goal/" var active_repository_path = tmp_prefix+"active/" @@ -67,8 +67,8 @@ func load_level(id): push_error("Refusing to delete a directory that does not start with %s" % expected_prefix) get_tree().quit() - game.exec("rm", ["-r", active_repository_path]) - game.exec("rm", ["-r", goal_repository_path]) + game.exec("rm", ["-rf", active_repository_path]) + game.exec("rm", ["-rf", goal_repository_path]) construct_repo(goal_script, goal_repository_path) construct_repo(active_script, active_repository_path) @@ -77,11 +77,18 @@ func load_level(id): active_repository.path = active_repository_path 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" + game.write_file(script_path, content) + var shell = Shell.new() shell.run("mkdir " + path) shell.cd(path) shell.run("git init") - print(shell.run("source "+script)) + print(shell.run("source "+script_path)) func _process(delta): if server.is_connection_available(): diff --git a/shell.gd b/shell.gd index 0485b76..2bba1bf 100644 --- a/shell.gd +++ b/shell.gd @@ -12,7 +12,7 @@ func cd(dir): # Run a shell command given as a string. Run this if you're interested in the # output of the command. func run(command): - var debug = true + var debug = false if debug: print("$ %s" % command)