diff --git a/game.gd b/game.gd index 273021a..c05047b 100644 --- a/game.gd +++ b/game.gd @@ -11,18 +11,23 @@ func _ready(): # Copy fake-editor to tmp directory (because the original might be in a .pck file). var fake_editor_outside = tmp_prefix + "fake-editor" fake_editor = "/tmp/fake-editor" - var content = game.read_file("res://scripts/fake-editor") + var content = game.read_file("res://scripts/fake-editor", "") + if content.empty(): + push_error("fake-editor could not be read.") write_file(fake_editor_outside, content) global_shell.run("chmod u+x " + fake_editor) -func read_file(path): +func read_file(path, fallback_string): if debug_file_io: print("reading " + path) var file = File.new() - file.open(path, File.READ) - var content = file.get_as_text() - file.close() - return content + var open_status = file.open(path, File.READ) + if open_status == OK: + var content = file.get_as_text() + file.close() + return content + else: + return fallback_string func write_file(path, content): if debug_file_io: diff --git a/levels/02-tree/goal b/levels/02-tree/goal index f436171..99b538d 100644 --- a/levels/02-tree/goal +++ b/levels/02-tree/goal @@ -1,4 +1,3 @@ -echo 'meow' > noises git update-index --add noises git write-tree diff --git a/levels/03-commit/goal b/levels/03-commit/goal index 792c523..bcb010d 100644 --- a/levels/03-commit/goal +++ b/levels/03-commit/goal @@ -1,7 +1 @@ -touch empty_file -git add . -git write-tree git commit-tree 3185 -m 'Clever commit message' - -rm empty_file -git update-index --remove empty_file diff --git a/levels/04-parents/goal b/levels/04-parents/goal index 28249f9..d80163a 100644 --- a/levels/04-parents/goal +++ b/levels/04-parents/goal @@ -1,4 +1,3 @@ -git write-tree FIRST_COMMIT=$(git commit-tree 4b82 -m 'First commit :O') SECOND_COMMIT=$(git commit-tree 4b82 -p $FIRST_COMMIT -m 'Second commit :D') THIRD_COMMIT=$(git commit-tree 4b82 -p $SECOND_COMMIT -m 'Third commit \o/') diff --git a/levels/05-ref/goal b/levels/05-ref/goal index 1c1690e..01cbb43 100644 --- a/levels/05-ref/goal +++ b/levels/05-ref/goal @@ -1,10 +1,3 @@ -echo hello > hello -echo world > world -BLOB1=$(git hash-object -w hello) -BLOB2=$(git hash-object -w world) -git add . -TREE=$(git write-tree) -COMMIT=$(git commit-tree $TREE -m "Initial commit") git update-ref refs/a $BLOB1 git update-ref refs/b $BLOB2 git update-ref refs/c $TREE diff --git a/levels/05-ref/start b/levels/05-ref/start index 1c9caca..3d3857e 100644 --- a/levels/05-ref/start +++ b/levels/05-ref/start @@ -1,5 +1,7 @@ echo hello > hello echo world > world +BLOB1=$(git hash-object -w hello) +BLOB2=$(git hash-object -w world) git add . TREE=$(git write-tree) -git commit-tree $TREE -m "Initial commit" +COMMIT=$(git commit-tree $TREE -m "Initial commit") diff --git a/levels/06-symref/goal b/levels/06-symref/goal index 24b0c6f..e137603 100644 --- a/levels/06-symref/goal +++ b/levels/06-symref/goal @@ -1,5 +1 @@ -TREE=$(git write-tree) -COMMIT=$(git commit-tree $TREE -m "Initial commit") -git update-ref refs/best_commit $COMMIT -git update-ref refs/worst_commit $COMMIT git symbolic-ref HEAD refs/best_commit diff --git a/main.gd b/main.gd index 3cc23ff..27084d6 100644 --- a/main.gd +++ b/main.gd @@ -60,7 +60,8 @@ func load_level(id): var goal_script = level_prefix+level+"/goal" var active_script = level_prefix+level+"/start" - var description = game.read_file(level_prefix+level+"/description") + var description_file = level_prefix+level+"/description" + var description = game.read_file(description_file, "no description") $LevelDescription.bbcode_text = description $LevelName.text = level @@ -77,17 +78,19 @@ func load_level(id): # Danger zone! game.global_shell.run("rm -rf '%s'" % active_repository_path) game.global_shell.run("rm -rf '%s'" % goal_repository_path) - - construct_repo(goal_script, goal_repository_path) - construct_repo(active_script, active_repository_path) + + var goal_script_content = game.read_file(goal_script, "") + var active_script_content = game.read_file(active_script, "") + construct_repo(active_script_content +"\n"+ goal_script_content, goal_repository_path) + construct_repo(active_script_content, active_repository_path) goal_repository.path = goal_repository_path active_repository.path = active_repository_path var win_script = level_prefix+level+"/win" var win_script_target = game.tmp_prefix+"/win" - var dir = Directory.new() - dir.copy(win_script, win_script_target) + var win_script_content = game.read_file(win_script, "exit 1\n") + game.write_file(win_script_target, win_script_content) terminal.clear() @@ -98,19 +101,18 @@ func load_next_level(): current_level = (current_level + 1) % list_levels().size() load_level(current_level) -func construct_repo(script, path): +func construct_repo(script_content, 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 = "" - #if ResourceLoader.exists(script): - content = game.read_file(script) + var script_path_outside = game.tmp_prefix+"/git-hydra-script" var script_path = "/tmp/git-hydra-script" - game.write_file(script_path_outside, content) + game.write_file(script_path_outside, script_content) game.global_shell.run("mkdir " + path) game.global_shell.cd(path) game.global_shell.run("git init") + game.global_shell.run("git symbolic-ref HEAD refs/heads/main") game.global_shell.run("sh "+script_path) func _process(_delta): @@ -127,7 +129,11 @@ func read_message(filename): $TextEditor.show() input.editable = false var fixme_path = game.tmp_prefix+"/active/" - $TextEditor.text = game.read_file(fixme_path+filename) + var content = game.read_file(fixme_path+filename, "[ERROR_FAKE_EDITOR]") + if content == "[ERROR_FAKE_EDITOR]": + push_error("file specified by fake-editor could not be read.") + get_tree().quit() + $TextEditor.text = content $TextEditor.path = filename $TextEditor.grab_focus() diff --git a/shell.gd b/shell.gd index 6a8eba1..731ff1d 100644 --- a/shell.gd +++ b/shell.gd @@ -3,7 +3,7 @@ class_name Shell var _cwd -signal output(text) +#signal output(text) func _init(): _cwd = "/tmp" diff --git a/tcp_server.gd b/tcp_server.gd index d25517e..98bfb25 100644 --- a/tcp_server.gd +++ b/tcp_server.gd @@ -14,7 +14,7 @@ func _ready(): func start(): _s.listen(port) -func _process(delta): +func _process(_delta): if _s.is_connection_available(): if _connected: push_error("Dropping active connection") diff --git a/terminal.gd b/terminal.gd index 551bee3..a7fb065 100644 --- a/terminal.gd +++ b/terminal.gd @@ -19,7 +19,7 @@ var premade_commands = [ ] func _ready(): - repo.shell.connect("output", self, "receive_output") + #repo.shell.connect("output", self, "receive_output") for command in premade_commands: command_dropdown.get_popup().add_item(command)