mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-12-22 20:32:38 +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
5
game.gd
5
game.gd
|
@ -7,7 +7,7 @@ func _ready():
|
||||||
|
|
||||||
# Run a simple command with arguments, blocking, using OS.execute.
|
# Run a simple command with arguments, blocking, using OS.execute.
|
||||||
func exec(command, args=[], remote_trailing_newline=false):
|
func exec(command, args=[], remote_trailing_newline=false):
|
||||||
var debug = false
|
var debug = true
|
||||||
if debug:
|
if debug:
|
||||||
print("game.exec: %s [%s]" % [command, PoolStringArray(args).join(", ")])
|
print("game.exec: %s [%s]" % [command, PoolStringArray(args).join(", ")])
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ func exec(command, args=[], remote_trailing_newline=false):
|
||||||
return output
|
return output
|
||||||
|
|
||||||
func read_file(path):
|
func read_file(path):
|
||||||
print("read "+path)
|
print ("reading " + path)
|
||||||
var file = File.new()
|
var file = File.new()
|
||||||
file.open(path, File.READ)
|
file.open(path, File.READ)
|
||||||
var content = file.get_as_text()
|
var content = file.get_as_text()
|
||||||
|
@ -32,6 +32,7 @@ func read_file(path):
|
||||||
return content
|
return content
|
||||||
|
|
||||||
func write_file(path, content):
|
func write_file(path, content):
|
||||||
|
print ("writing " + path)
|
||||||
var file = File.new()
|
var file = File.new()
|
||||||
file.open(path, File.WRITE)
|
file.open(path, File.WRITE)
|
||||||
file.store_string(content)
|
file.store_string(content)
|
||||||
|
|
17
main.gd
17
main.gd
|
@ -28,7 +28,7 @@ func _ready():
|
||||||
func list_levels():
|
func list_levels():
|
||||||
var levels = []
|
var levels = []
|
||||||
var dir = Directory.new()
|
var dir = Directory.new()
|
||||||
dir.open("levels")
|
dir.open("res://levels")
|
||||||
dir.list_dir_begin()
|
dir.list_dir_begin()
|
||||||
|
|
||||||
while true:
|
while true:
|
||||||
|
@ -47,7 +47,7 @@ func load_level(id):
|
||||||
|
|
||||||
var level = levels[id]
|
var level = levels[id]
|
||||||
var tmp_prefix = "/tmp/"
|
var tmp_prefix = "/tmp/"
|
||||||
var level_prefix = game.cwd + "/levels/"
|
var level_prefix = "res://levels/"
|
||||||
|
|
||||||
var goal_repository_path = tmp_prefix+"goal/"
|
var goal_repository_path = tmp_prefix+"goal/"
|
||||||
var active_repository_path = tmp_prefix+"active/"
|
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)
|
push_error("Refusing to delete a directory that does not start with %s" % expected_prefix)
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
|
|
||||||
game.exec("rm", ["-r", active_repository_path])
|
game.exec("rm", ["-rf", active_repository_path])
|
||||||
game.exec("rm", ["-r", goal_repository_path])
|
game.exec("rm", ["-rf", goal_repository_path])
|
||||||
|
|
||||||
construct_repo(goal_script, goal_repository_path)
|
construct_repo(goal_script, goal_repository_path)
|
||||||
construct_repo(active_script, active_repository_path)
|
construct_repo(active_script, active_repository_path)
|
||||||
|
@ -77,11 +77,18 @@ func load_level(id):
|
||||||
active_repository.path = active_repository_path
|
active_repository.path = active_repository_path
|
||||||
|
|
||||||
func construct_repo(script, 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()
|
var shell = Shell.new()
|
||||||
shell.run("mkdir " + path)
|
shell.run("mkdir " + path)
|
||||||
shell.cd(path)
|
shell.cd(path)
|
||||||
shell.run("git init")
|
shell.run("git init")
|
||||||
print(shell.run("source "+script))
|
print(shell.run("source "+script_path))
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
if server.is_connection_available():
|
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
|
# Run a shell command given as a string. Run this if you're interested in the
|
||||||
# output of the command.
|
# output of the command.
|
||||||
func run(command):
|
func run(command):
|
||||||
var debug = true
|
var debug = false
|
||||||
|
|
||||||
if debug:
|
if debug:
|
||||||
print("$ %s" % command)
|
print("$ %s" % command)
|
||||||
|
|
Loading…
Reference in a new issue