mirror of
https://github.com/git-learning-game/oh-my-git.git
synced 2024-11-13 19:04:54 +01:00
Write win scripts for all levels (with a short, fun trip to quote hell)
This commit is contained in:
parent
2aefdf8391
commit
7c82381e8d
9 changed files with 50 additions and 18 deletions
|
@ -1,7 +1,3 @@
|
|||
BLOB_COUNT=$(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep blob | wc -l)
|
||||
|
||||
if [ "$BLOB_COUNT" -gt 2 ]; then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
test "$BLOB_COUNT" -gt 2
|
||||
|
|
1
levels/02-tree/win
Normal file
1
levels/02-tree/win
Normal file
|
@ -0,0 +1 @@
|
|||
git cat-file -p c099013035060f20e8d8f5db69e158213fbec519
|
3
levels/03-commit/win
Normal file
3
levels/03-commit/win
Normal file
|
@ -0,0 +1,3 @@
|
|||
COMMIT_COUNT=$(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep commit | wc -l)
|
||||
|
||||
test "$COMMIT_COUNT" -gt 0
|
10
levels/04-parents/win
Normal file
10
levels/04-parents/win
Normal file
|
@ -0,0 +1,10 @@
|
|||
COMMITS=$(git cat-file --batch-check='%(objectname) %(objecttype)' --batch-all-objects | grep commit | cut -f1 -d" ")
|
||||
|
||||
for COMMIT in $COMMITS; do
|
||||
echo a commit named $COMMIT
|
||||
if [ $(git rev-list $COMMIT | wc -l) -ge 3 ]; then
|
||||
exit 0
|
||||
fi
|
||||
done
|
||||
|
||||
exit 1
|
2
main.gd
2
main.gd
|
@ -85,7 +85,7 @@ func load_level(id):
|
|||
dir.copy(win_script, win_script_target)
|
||||
|
||||
func load_next_level():
|
||||
current_level += 1
|
||||
current_level = (current_level + 1) % list_levels().size()
|
||||
load_level(current_level)
|
||||
|
||||
func construct_repo(script, path):
|
||||
|
|
|
@ -18,7 +18,6 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="Index" type="Label" parent="."]
|
||||
visible = false
|
||||
margin_left = 32.0
|
||||
margin_top = 80.0
|
||||
margin_right = 375.079
|
||||
|
@ -31,7 +30,6 @@ __meta__ = {
|
|||
}
|
||||
|
||||
[node name="IndexLabel" type="Label" parent="."]
|
||||
visible = false
|
||||
margin_left = 21.0
|
||||
margin_top = 65.0
|
||||
margin_right = 377.0
|
||||
|
|
16
shell.gd
16
shell.gd
|
@ -32,6 +32,22 @@ func run(command):
|
|||
hacky_command += "cd '%s';" % _cwd
|
||||
hacky_command += command
|
||||
|
||||
# Godot's OS.execute wraps each argument in double quotes before executing.
|
||||
# Because we want to be in a single-quote context, where nothing is evaluated,
|
||||
# we end those double quotes and start a single quoted string. For each single
|
||||
# quote appearing in our string, we close the single quoted string, and add
|
||||
# a double quoted string containing the single quote. Ooooof!
|
||||
#
|
||||
# Example: The string
|
||||
#
|
||||
# test 'fu' "bla" blubb
|
||||
#
|
||||
# becomes
|
||||
#
|
||||
# "'test '"'"'fu'"'"' "bla" blubb
|
||||
#
|
||||
hacky_command = '"\''+hacky_command.replace("'", "'\"'\"'")+'\'"'
|
||||
|
||||
var output = game.exec(_shell_binary(), ["-c", hacky_command])
|
||||
|
||||
if debug:
|
||||
|
|
|
@ -49,7 +49,7 @@ func run_command_in_a_thread(command):
|
|||
check_win_condition()
|
||||
|
||||
input.text = ""
|
||||
input.editable = true
|
||||
input.editable = true
|
||||
output.text = output.text + "$ " + command + "\n" + o
|
||||
repo.update_everything()
|
||||
|
||||
|
@ -57,5 +57,5 @@ func receive_output(text):
|
|||
output.text += text
|
||||
|
||||
func check_win_condition():
|
||||
if repo.shell.run("bash /tmp/win && echo yes || echo no") == "yes\n":
|
||||
if repo.shell.run("bash /tmp/win &>/dev/null && echo yes || echo no") == "yes\n":
|
||||
main.load_next_level()
|
||||
|
|
|
@ -11,14 +11,14 @@ content_margin_top = 10.0
|
|||
content_margin_bottom = 10.0
|
||||
bg_color = Color( 0, 0, 0, 1 )
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=3]
|
||||
[sub_resource type="StyleBoxFlat" id=2]
|
||||
content_margin_left = 10.0
|
||||
content_margin_right = 10.0
|
||||
content_margin_top = 10.0
|
||||
content_margin_bottom = 5.0
|
||||
bg_color = Color( 0.0862745, 0.0862745, 0.0862745, 1 )
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id=2]
|
||||
[sub_resource type="StyleBoxFlat" id=3]
|
||||
content_margin_left = 10.0
|
||||
content_margin_right = 10.0
|
||||
content_margin_top = 10.0
|
||||
|
@ -43,7 +43,7 @@ __meta__ = {
|
|||
|
||||
[node name="Output" type="RichTextLabel" parent="Control"]
|
||||
margin_right = 1920.0
|
||||
margin_bottom = 999.0
|
||||
margin_bottom = 979.0
|
||||
size_flags_vertical = 3
|
||||
custom_styles/normal = SubResource( 1 )
|
||||
custom_fonts/normal_font = ExtResource( 1 )
|
||||
|
@ -51,18 +51,26 @@ scroll_following = true
|
|||
|
||||
[node name="Button" parent="Control" instance=ExtResource( 4 )]
|
||||
margin_left = 0.0
|
||||
margin_top = 999.0
|
||||
margin_top = 979.0
|
||||
margin_right = 1920.0
|
||||
margin_bottom = 1019.0
|
||||
margin_bottom = 999.0
|
||||
text = "git commit --allow-empty"
|
||||
align = 0
|
||||
|
||||
[node name="Button5" parent="Control" instance=ExtResource( 4 )]
|
||||
margin_left = 0.0
|
||||
margin_top = 999.0
|
||||
margin_right = 1920.0
|
||||
margin_bottom = 1019.0
|
||||
text = "echo $RANDOM | git hash-object -w --stdin"
|
||||
align = 0
|
||||
|
||||
[node name="Button6" parent="Control" instance=ExtResource( 4 )]
|
||||
margin_left = 0.0
|
||||
margin_top = 1019.0
|
||||
margin_right = 1920.0
|
||||
margin_bottom = 1039.0
|
||||
text = "echo $RANDOM | git hash-object -w --stdin"
|
||||
text = "git update-index --add noises; git write-tree"
|
||||
align = 0
|
||||
|
||||
[node name="Button2" parent="Control" instance=ExtResource( 4 )]
|
||||
|
@ -96,8 +104,8 @@ align = 0
|
|||
margin_top = 1039.0
|
||||
margin_right = 1920.0
|
||||
margin_bottom = 1080.0
|
||||
custom_styles/read_only = SubResource( 3 )
|
||||
custom_styles/normal = SubResource( 2 )
|
||||
custom_styles/read_only = SubResource( 2 )
|
||||
custom_styles/normal = SubResource( 3 )
|
||||
custom_fonts/font = ExtResource( 1 )
|
||||
caret_blink = true
|
||||
__meta__ = {
|
||||
|
|
Loading…
Reference in a new issue