mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-20 16:20:18 +01:00
Refactor Level class so that we don't need to copy shell scripts
This commit is contained in:
parent
3291f0a78b
commit
c178a5c63e
6 changed files with 14 additions and 26 deletions
22
level.gd
22
level.gd
|
@ -28,32 +28,20 @@ func load(path):
|
||||||
win_commands = helpers.read_file(path+"/win", "exit 1\n")
|
win_commands = helpers.read_file(path+"/win", "exit 1\n")
|
||||||
|
|
||||||
func construct():
|
func construct():
|
||||||
# We're actually destroying stuff here.
|
|
||||||
# Make sure that active_repository is in a temporary directory.
|
|
||||||
helpers.careful_delete(_active_repository_path)
|
|
||||||
helpers.careful_delete(_goal_repository_path)
|
|
||||||
|
|
||||||
_construct_repo(start_commands +"\n"+ goal_commands, _goal_repository_path)
|
_construct_repo(start_commands +"\n"+ goal_commands, _goal_repository_path)
|
||||||
_construct_repo(start_commands, _active_repository_path)
|
_construct_repo(start_commands, _active_repository_path)
|
||||||
|
|
||||||
var win_script_target = game.tmp_prefix_outside+"/win"
|
|
||||||
helpers.write_file(win_script_target, win_commands)
|
|
||||||
|
|
||||||
func _construct_repo(script_content, path):
|
func _construct_repo(script_content, path):
|
||||||
# Becase in an exported game, all assets are in a .pck file, we need to put
|
# We're actually destroying stuff here.
|
||||||
# the script somewhere in the filesystem.
|
# Make sure that active_repository is in a temporary directory.
|
||||||
|
helpers.careful_delete(path)
|
||||||
var script_path_outside = game.tmp_prefix_outside+"/git-hydra-script"
|
|
||||||
var script_path_inside = game.tmp_prefix_inside+"/git-hydra-script"
|
|
||||||
helpers.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("git symbolic-ref HEAD refs/heads/main")
|
||||||
# Read stdin from /dev/null so that interactive commands don't block.
|
game.global_shell.run(script_content)
|
||||||
game.global_shell.run("bash "+script_path_inside+" </dev/null")
|
|
||||||
|
|
||||||
func check_win():
|
func check_win():
|
||||||
game.global_shell.cd(_active_repository_path)
|
game.global_shell.cd(_active_repository_path)
|
||||||
return game.global_shell.run("bash %s/win 2>/dev/null >/dev/null && echo yes || echo no" % game.tmp_prefix_inside) == "yes\n"
|
return game.global_shell.run("function win { %s }; win 2>/dev/null >/dev/null && echo yes || echo no" % win_commands) == "yes\n"
|
||||||
|
|
|
@ -3,8 +3,8 @@ COMMITS=$(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-o
|
||||||
for COMMIT in $COMMITS; do
|
for COMMIT in $COMMITS; do
|
||||||
echo a commit named $COMMIT
|
echo a commit named $COMMIT
|
||||||
if [ $(git rev-list $COMMIT | wc -l) -ge 3 ]; then
|
if [ $(git rev-list $COMMIT | wc -l) -ge 3 ]; then
|
||||||
exit 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
exit 1
|
return 1
|
||||||
|
|
|
@ -3,8 +3,8 @@ COMMITS=$(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-o
|
||||||
for COMMIT in $COMMITS; do
|
for COMMIT in $COMMITS; do
|
||||||
# My first parent's parents has to be the same as my second parent's parent.
|
# My first parent's parents has to be the same as my second parent's parent.
|
||||||
if [ "$(git rev-parse --verify -q $COMMIT^1^)" = "$(git rev-parse --verify -q $COMMIT^2^)" ]; then
|
if [ "$(git rev-parse --verify -q $COMMIT^1^)" = "$(git rev-parse --verify -q $COMMIT^2^)" ]; then
|
||||||
exit 0
|
return 0
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
exit 1
|
return 1
|
||||||
|
|
|
@ -8,11 +8,11 @@ for TREE in $TREES; do
|
||||||
if [ "$(git cat-file -p $TREE2 | wc -l)" -eq 1 ]; then
|
if [ "$(git cat-file -p $TREE2 | wc -l)" -eq 1 ]; then
|
||||||
if [ "$(git cat-file -p $TREE2 | cut -f1 | grep tree | wc -l)" -eq 1 ]; then
|
if [ "$(git cat-file -p $TREE2 | cut -f1 | grep tree | wc -l)" -eq 1 ]; then
|
||||||
# Same for its child! \o/
|
# Same for its child! \o/
|
||||||
exit 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
exit 1
|
return 1
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
git symbolic-ref refs/fries && exit 1
|
git symbolic-ref refs/fries && return 1
|
||||||
test "$(git show-ref -s refs/fries)" = "035e2968dafeea08e46e8fe6743cb8123e8b9aa6"
|
test "$(git show-ref -s refs/fries)" = "035e2968dafeea08e46e8fe6743cb8123e8b9aa6"
|
||||||
|
|
|
@ -8,9 +8,9 @@ for OUTER_TREE in $TREES; do
|
||||||
TREE_CHILD=$(git cat-file -p $OUTER_TREE | cut -f1 | grep tree | cut -d" " -f3)
|
TREE_CHILD=$(git cat-file -p $OUTER_TREE | cut -f1 | grep tree | cut -d" " -f3)
|
||||||
NUMBER_OF_BLOB_CHILDREN_OF_TREE_CHILD=$(git cat-file -p $TREE_CHILD | cut -f2 -d" " | grep blob | wc -l)
|
NUMBER_OF_BLOB_CHILDREN_OF_TREE_CHILD=$(git cat-file -p $TREE_CHILD | cut -f2 -d" " | grep blob | wc -l)
|
||||||
if [ $NUMBER_OF_BLOB_CHILDREN_OF_TREE_CHILD -eq 2 ]; then
|
if [ $NUMBER_OF_BLOB_CHILDREN_OF_TREE_CHILD -eq 2 ]; then
|
||||||
exit 0
|
return 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
exit 1
|
return 1
|
||||||
|
|
Loading…
Reference in a new issue