From 7c82381e8dd10522922f71c0294fa6f022bafb3b Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Fri, 11 Sep 2020 12:23:26 +0200 Subject: [PATCH] Write win scripts for all levels (with a short, fun trip to quote hell) --- levels/01-blob/win | 6 +----- levels/02-tree/win | 1 + levels/03-commit/win | 3 +++ levels/04-parents/win | 10 ++++++++++ main.gd | 2 +- repository.tscn | 2 -- shell.gd | 16 ++++++++++++++++ terminal.gd | 4 ++-- terminal.tscn | 24 ++++++++++++++++-------- 9 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 levels/02-tree/win create mode 100644 levels/03-commit/win create mode 100644 levels/04-parents/win diff --git a/levels/01-blob/win b/levels/01-blob/win index 337555a..1232d11 100644 --- a/levels/01-blob/win +++ b/levels/01-blob/win @@ -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 diff --git a/levels/02-tree/win b/levels/02-tree/win new file mode 100644 index 0000000..40bc605 --- /dev/null +++ b/levels/02-tree/win @@ -0,0 +1 @@ +git cat-file -p c099013035060f20e8d8f5db69e158213fbec519 diff --git a/levels/03-commit/win b/levels/03-commit/win new file mode 100644 index 0000000..4bd1a81 --- /dev/null +++ b/levels/03-commit/win @@ -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 diff --git a/levels/04-parents/win b/levels/04-parents/win new file mode 100644 index 0000000..ce20826 --- /dev/null +++ b/levels/04-parents/win @@ -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 diff --git a/main.gd b/main.gd index e74486d..b69685f 100644 --- a/main.gd +++ b/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): diff --git a/repository.tscn b/repository.tscn index cdc849d..5cf7bb7 100644 --- a/repository.tscn +++ b/repository.tscn @@ -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 diff --git a/shell.gd b/shell.gd index 0e2cd9b..cb636d2 100644 --- a/shell.gd +++ b/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: diff --git a/terminal.gd b/terminal.gd index 7e0ad18..6229f47 100644 --- a/terminal.gd +++ b/terminal.gd @@ -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() diff --git a/terminal.tscn b/terminal.tscn index b8a03b1..bbfde72 100644 --- a/terminal.tscn +++ b/terminal.tscn @@ -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__ = {