mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-22 16:20:19 +01:00
Restructuring of goal/start scripts
This commit is contained in:
parent
34b24344d4
commit
b84bb48004
11 changed files with 35 additions and 41 deletions
11
game.gd
11
game.gd
|
@ -11,18 +11,23 @@ func _ready():
|
||||||
# Copy fake-editor to tmp directory (because the original might be in a .pck file).
|
# Copy fake-editor to tmp directory (because the original might be in a .pck file).
|
||||||
var fake_editor_outside = tmp_prefix + "fake-editor"
|
var fake_editor_outside = tmp_prefix + "fake-editor"
|
||||||
fake_editor = "/tmp/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)
|
write_file(fake_editor_outside, content)
|
||||||
global_shell.run("chmod u+x " + fake_editor)
|
global_shell.run("chmod u+x " + fake_editor)
|
||||||
|
|
||||||
func read_file(path):
|
func read_file(path, fallback_string):
|
||||||
if debug_file_io:
|
if debug_file_io:
|
||||||
print("reading " + path)
|
print("reading " + path)
|
||||||
var file = File.new()
|
var file = File.new()
|
||||||
file.open(path, File.READ)
|
var open_status = file.open(path, File.READ)
|
||||||
|
if open_status == OK:
|
||||||
var content = file.get_as_text()
|
var content = file.get_as_text()
|
||||||
file.close()
|
file.close()
|
||||||
return content
|
return content
|
||||||
|
else:
|
||||||
|
return fallback_string
|
||||||
|
|
||||||
func write_file(path, content):
|
func write_file(path, content):
|
||||||
if debug_file_io:
|
if debug_file_io:
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
echo 'meow' > noises
|
|
||||||
git update-index --add noises
|
git update-index --add noises
|
||||||
git write-tree
|
git write-tree
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1 @@
|
||||||
touch empty_file
|
|
||||||
git add .
|
|
||||||
git write-tree
|
|
||||||
git commit-tree 3185 -m 'Clever commit message'
|
git commit-tree 3185 -m 'Clever commit message'
|
||||||
|
|
||||||
rm empty_file
|
|
||||||
git update-index --remove empty_file
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
git write-tree
|
|
||||||
FIRST_COMMIT=$(git commit-tree 4b82 -m 'First commit :O')
|
FIRST_COMMIT=$(git commit-tree 4b82 -m 'First commit :O')
|
||||||
SECOND_COMMIT=$(git commit-tree 4b82 -p $FIRST_COMMIT -m 'Second commit :D')
|
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/')
|
THIRD_COMMIT=$(git commit-tree 4b82 -p $SECOND_COMMIT -m 'Third commit \o/')
|
||||||
|
|
|
@ -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/a $BLOB1
|
||||||
git update-ref refs/b $BLOB2
|
git update-ref refs/b $BLOB2
|
||||||
git update-ref refs/c $TREE
|
git update-ref refs/c $TREE
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
echo hello > hello
|
echo hello > hello
|
||||||
echo world > world
|
echo world > world
|
||||||
|
BLOB1=$(git hash-object -w hello)
|
||||||
|
BLOB2=$(git hash-object -w world)
|
||||||
git add .
|
git add .
|
||||||
TREE=$(git write-tree)
|
TREE=$(git write-tree)
|
||||||
git commit-tree $TREE -m "Initial commit"
|
COMMIT=$(git commit-tree $TREE -m "Initial commit")
|
||||||
|
|
|
@ -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
|
git symbolic-ref HEAD refs/best_commit
|
||||||
|
|
28
main.gd
28
main.gd
|
@ -60,7 +60,8 @@ func load_level(id):
|
||||||
var goal_script = level_prefix+level+"/goal"
|
var goal_script = level_prefix+level+"/goal"
|
||||||
var active_script = level_prefix+level+"/start"
|
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
|
$LevelDescription.bbcode_text = description
|
||||||
$LevelName.text = level
|
$LevelName.text = level
|
||||||
|
|
||||||
|
@ -78,16 +79,18 @@ func load_level(id):
|
||||||
game.global_shell.run("rm -rf '%s'" % active_repository_path)
|
game.global_shell.run("rm -rf '%s'" % active_repository_path)
|
||||||
game.global_shell.run("rm -rf '%s'" % goal_repository_path)
|
game.global_shell.run("rm -rf '%s'" % goal_repository_path)
|
||||||
|
|
||||||
construct_repo(goal_script, goal_repository_path)
|
var goal_script_content = game.read_file(goal_script, "")
|
||||||
construct_repo(active_script, active_repository_path)
|
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
|
goal_repository.path = goal_repository_path
|
||||||
active_repository.path = active_repository_path
|
active_repository.path = active_repository_path
|
||||||
|
|
||||||
var win_script = level_prefix+level+"/win"
|
var win_script = level_prefix+level+"/win"
|
||||||
var win_script_target = game.tmp_prefix+"/win"
|
var win_script_target = game.tmp_prefix+"/win"
|
||||||
var dir = Directory.new()
|
var win_script_content = game.read_file(win_script, "exit 1\n")
|
||||||
dir.copy(win_script, win_script_target)
|
game.write_file(win_script_target, win_script_content)
|
||||||
|
|
||||||
terminal.clear()
|
terminal.clear()
|
||||||
|
|
||||||
|
@ -98,19 +101,18 @@ func load_next_level():
|
||||||
current_level = (current_level + 1) % list_levels().size()
|
current_level = (current_level + 1) % list_levels().size()
|
||||||
load_level(current_level)
|
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
|
# Becase in an exported game, all assets are in a .pck file, we need to put
|
||||||
# the script somewhere in the filesystem.
|
# 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_outside = game.tmp_prefix+"/git-hydra-script"
|
||||||
var script_path = "/tmp/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.run("mkdir " + path)
|
||||||
game.global_shell.cd(path)
|
game.global_shell.cd(path)
|
||||||
game.global_shell.run("git init")
|
game.global_shell.run("git init")
|
||||||
|
game.global_shell.run("git symbolic-ref HEAD refs/heads/main")
|
||||||
game.global_shell.run("sh "+script_path)
|
game.global_shell.run("sh "+script_path)
|
||||||
|
|
||||||
func _process(_delta):
|
func _process(_delta):
|
||||||
|
@ -127,7 +129,11 @@ func read_message(filename):
|
||||||
$TextEditor.show()
|
$TextEditor.show()
|
||||||
input.editable = false
|
input.editable = false
|
||||||
var fixme_path = game.tmp_prefix+"/active/"
|
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.path = filename
|
||||||
$TextEditor.grab_focus()
|
$TextEditor.grab_focus()
|
||||||
|
|
||||||
|
|
2
shell.gd
2
shell.gd
|
@ -3,7 +3,7 @@ class_name Shell
|
||||||
|
|
||||||
var _cwd
|
var _cwd
|
||||||
|
|
||||||
signal output(text)
|
#signal output(text)
|
||||||
|
|
||||||
func _init():
|
func _init():
|
||||||
_cwd = "/tmp"
|
_cwd = "/tmp"
|
||||||
|
|
|
@ -14,7 +14,7 @@ func _ready():
|
||||||
func start():
|
func start():
|
||||||
_s.listen(port)
|
_s.listen(port)
|
||||||
|
|
||||||
func _process(delta):
|
func _process(_delta):
|
||||||
if _s.is_connection_available():
|
if _s.is_connection_available():
|
||||||
if _connected:
|
if _connected:
|
||||||
push_error("Dropping active connection")
|
push_error("Dropping active connection")
|
||||||
|
|
|
@ -19,7 +19,7 @@ var premade_commands = [
|
||||||
]
|
]
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
repo.shell.connect("output", self, "receive_output")
|
#repo.shell.connect("output", self, "receive_output")
|
||||||
|
|
||||||
for command in premade_commands:
|
for command in premade_commands:
|
||||||
command_dropdown.get_popup().add_item(command)
|
command_dropdown.get_popup().add_item(command)
|
||||||
|
|
Loading…
Reference in a new issue