mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-12-22 20:32:38 +01:00
Copy fake-editor to /tmp when starting (the original might be in a .pck file)
This commit is contained in:
parent
4fff68253c
commit
5a8c377160
3 changed files with 21 additions and 14 deletions
14
game.gd
14
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
|
||||
|
||||
|
|
11
main.gd
11
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()
|
||||
|
|
10
shell.gd
10
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:
|
||||
|
|
Loading…
Reference in a new issue