mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-15 19:04:57 +01:00
Allow exported Linux builds to run
When referring to local game files, we always need to use "res://".
This commit is contained in:
parent
579f18736a
commit
4fff68253c
3 changed files with 17 additions and 9 deletions
7
game.gd
7
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)
|
||||
|
|
17
main.gd
17
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():
|
||||
|
|
2
shell.gd
2
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)
|
||||
|
|
Loading…
Reference in a new issue