From b1d2536bccdacb522d32847a65f6c4be9ac95bfb Mon Sep 17 00:00:00 2001 From: Sebastian Morr Date: Mon, 14 Sep 2020 15:35:30 +0200 Subject: [PATCH] Clear button, show arrow target if there's no node, add some goals --- arrow.gd | 4 ++++ arrow.tscn | 13 +++++++++++++ levels/05-ref/goal | 11 +++++++++++ levels/06-symref/description | 2 +- levels/06-symref/goal | 5 +++++ main.gd | 3 +++ repository.gd | 9 +++++---- repository.tscn | 3 ++- terminal.gd | 4 ++++ terminal.tscn | 16 +++++++++++++--- 10 files changed, 61 insertions(+), 9 deletions(-) create mode 100644 levels/05-ref/goal create mode 100644 levels/06-symref/goal diff --git a/arrow.gd b/arrow.gd index 92c93c4..ce919b2 100644 --- a/arrow.gd +++ b/arrow.gd @@ -12,6 +12,10 @@ func _process(_delta): if repository and repository.objects.has(target): var t = repository.objects[target] end = t.global_position + $Target.hide() + else: + $Target.text = target + $Target.show() $Line.points[1] = end - global_position $Label.position = ($Line.points[0] + $Line.points[1])/2 $Tip.position = ($Line.points[0] + $Line.points[1])/2 diff --git a/arrow.tscn b/arrow.tscn index 503ef88..31cd3f2 100644 --- a/arrow.tscn +++ b/arrow.tscn @@ -38,3 +38,16 @@ align = 1 __meta__ = { "_edit_use_anchors_": false } + +[node name="Target" type="Label" parent="."] +margin_left = -229.024 +margin_top = 63.3118 +margin_right = 232.976 +margin_bottom = 89.3118 +custom_fonts/font = ExtResource( 2 ) +custom_colors/font_color = Color( 0.356863, 0.356863, 0.356863, 1 ) +text = "label" +align = 1 +__meta__ = { +"_edit_use_anchors_": false +} diff --git a/levels/05-ref/goal b/levels/05-ref/goal new file mode 100644 index 0000000..1c1690e --- /dev/null +++ b/levels/05-ref/goal @@ -0,0 +1,11 @@ +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 +git update-ref refs/d $COMMIT diff --git a/levels/06-symref/description b/levels/06-symref/description index 41eedd3..836a7b7 100644 --- a/levels/06-symref/description +++ b/levels/06-symref/description @@ -4,6 +4,6 @@ When that happens, they are called "symbolic refs". You can create or update a s git symbolic-ref -Usually, you will only encounter a special symbolic ref called "HEAD". This ref is special in that it doesn't start with "refs/"! +Usually, you will only encounter a special symbolic ref called "HEAD". This ref is special in that it doesn't start with "refs/"! You might already have seen it in the other levels - it's the only thing that's always there! Try pointing HEAD to the refs in this repository! diff --git a/levels/06-symref/goal b/levels/06-symref/goal new file mode 100644 index 0000000..24b0c6f --- /dev/null +++ b/levels/06-symref/goal @@ -0,0 +1,5 @@ +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 8eb5804..0ecaabb 100644 --- a/main.gd +++ b/main.gd @@ -6,6 +6,7 @@ var server var client_connection var current_level = 0 +onready var terminal = $Terminal onready var input = $Terminal/Control/Input onready var output = $Terminal/Control/Output onready var goal_repository = $Repositories/GoalRepository @@ -84,6 +85,8 @@ func load_level(id): var win_script_target = game.tmp_prefix+"/win" var dir = Directory.new() dir.copy(win_script, win_script_target) + + terminal.clear() func reload_level(): load_level(current_level) diff --git a/repository.gd b/repository.gd index b850b5d..a204e32 100644 --- a/repository.gd +++ b/repository.gd @@ -37,7 +37,7 @@ func set_label(new_label): $Label.text = new_label func update_index(): - $Index.text = git("ls-files") + $Index.text = git("ls-files -s --abbrev=8").replace("\t", " ") func random_position(): return Vector2(rand_range(0, rect_size.x), rand_range(0, rect_size.y)) @@ -66,7 +66,6 @@ func update_objects(): c[p] = "" n.children = c "tag": - print("tag") n.children = tag_target(o) n.position = find_position(n) @@ -112,7 +111,6 @@ func find_position(n): position += objects[child].position count += 1 if count > 0: - print(count) position /= count n.position = position + Vector2(0, -150) else: @@ -200,5 +198,8 @@ func ref_target(ref): var ret = git("symbolic-ref -q "+ref+" || true") # If it's not, it's probably a regular ref. if ret == "": - ret = git("show-ref "+ref).split(" ")[0] + if ref == "HEAD": + ret = git("show-ref --head "+ref).split(" ")[0] + else: + ret = git("show-ref "+ref).split(" ")[0] return ret diff --git a/repository.tscn b/repository.tscn index 5cf7bb7..2a36ef0 100644 --- a/repository.tscn +++ b/repository.tscn @@ -18,7 +18,7 @@ __meta__ = { } [node name="Index" type="Label" parent="."] -margin_left = 32.0 +margin_left = 24.0 margin_top = 80.0 margin_right = 375.079 margin_bottom = 1044.0 @@ -30,6 +30,7 @@ __meta__ = { } [node name="IndexLabel" type="Label" parent="."] +visible = false margin_left = 21.0 margin_top = 65.0 margin_right = 377.0 diff --git a/terminal.gd b/terminal.gd index 41df938..065f7a7 100644 --- a/terminal.gd +++ b/terminal.gd @@ -55,6 +55,10 @@ func run_command_in_a_thread(command): func receive_output(text): output.text += text + +func clear(): + input.text = "" + output.text = "" func check_win_condition(): if repo.shell.run("bash /tmp/win 2>&1 >/dev/null && echo yes || echo no") == "yes\n": diff --git a/terminal.tscn b/terminal.tscn index bbfde72..5702956 100644 --- a/terminal.tscn +++ b/terminal.tscn @@ -66,6 +66,7 @@ text = "echo $RANDOM | git hash-object -w --stdin" align = 0 [node name="Button6" parent="Control" instance=ExtResource( 4 )] +visible = false margin_left = 0.0 margin_top = 1019.0 margin_right = 1920.0 @@ -74,11 +75,10 @@ text = "git update-index --add noises; git write-tree" align = 0 [node name="Button2" parent="Control" instance=ExtResource( 4 )] -visible = false margin_left = 0.0 -margin_top = 979.0 +margin_top = 1019.0 margin_right = 1920.0 -margin_bottom = 999.0 +margin_bottom = 1039.0 text = "git switch -c $RANDOM" align = 0 @@ -111,4 +111,14 @@ caret_blink = true __meta__ = { "_edit_use_anchors_": false } + +[node name="ClearButton" type="Button" parent="."] +anchor_left = 0.9 +anchor_right = 1.0 +margin_left = -10.0 +margin_top = 10.0 +margin_right = -10.0 +custom_fonts/font = ExtResource( 1 ) +text = "Clear" [connection signal="text_entered" from="Control/Input" to="." method="send_command"] +[connection signal="pressed" from="ClearButton" to="." method="clear"]