From af90678d45d8aeb63b4a33b7da311875d7fe9916 Mon Sep 17 00:00:00 2001 From: bleeptrack Date: Tue, 13 Oct 2020 18:13:42 +0200 Subject: [PATCH] New Cards and Redraw Button --- card.gd | 7 +++++-- card.tscn | 13 ++++++++----- cardgame.gd | 15 ++++++++++++--- cardgame.tscn | 11 +++++++++++ 4 files changed, 36 insertions(+), 10 deletions(-) diff --git a/card.gd b/card.gd index 0152c05..4ffd834 100644 --- a/card.gd +++ b/card.gd @@ -62,8 +62,11 @@ func dropped_on(other): #print("I have been dropped on "+str(other.id)) var full_command = "" match arg_number: - 1: - full_command = $Label.text + " " + other.id + 1: + var argument = other.id + if ($Label.text.begins_with("git checkout") or $Label.text.begins_with("git rebase")) and other.id.begins_with("refs/heads"): + argument = Array(other.id.split("/")).pop_back() + full_command = $Label.text + " " + argument $"../Terminal".send_command(full_command) buuurn() 2: diff --git a/card.tscn b/card.tscn index 7c91f87..319f9ef 100644 --- a/card.tscn +++ b/card.tscn @@ -6,7 +6,9 @@ [sub_resource type="RectangleShape2D" id=1] extents = Vector2( 105.74, 143.46 ) -[node name="Card" type="Node2D"] +[node name="Card" type="Node2D" groups=[ +"cards", +]] script = ExtResource( 1 ) [node name="ColorRect" type="ColorRect" parent="."] @@ -28,13 +30,14 @@ position = Vector2( -6.10352e-05, 0.00012207 ) shape = SubResource( 1 ) [node name="Label" type="Label" parent="."] -margin_left = -89.1555 -margin_top = -131.488 -margin_right = -38.1555 -margin_bottom = -117.488 +margin_left = -89.0 +margin_top = -131.0 +margin_right = 85.0 +margin_bottom = -29.0 custom_fonts/font = ExtResource( 2 ) custom_colors/font_color = Color( 0, 0, 0, 1 ) text = "git checkout" +autowrap = true __meta__ = { "_edit_use_anchors_": false } diff --git a/cardgame.gd b/cardgame.gd index cc65749..b27993f 100644 --- a/cardgame.gd +++ b/cardgame.gd @@ -6,7 +6,11 @@ var cards = [ {"command": 'touch "file$RANDOM"', "arg_number": 0}, {"command": 'git commit --allow-empty -m "$RANDOM"', "arg_number": 0}, {"command": 'git checkout -b "$RANDOM"', "arg_number": 0}, - {"command": 'git merge', "arg_number": 1} + {"command": 'git merge', "arg_number": 1}, + {"command": 'git symbolic-ref HEAD', "arg_number": 1}, + {"command": 'git update-ref -d', "arg_number": 1}, + {"command": 'git reflog expire --expire=now --all; git prune', "arg_number": 0}, + {"command": 'git rebase', "arg_number": 1} ] func _ready(): @@ -24,8 +28,7 @@ func _ready(): $Terminal.repository = $Repository - for i in range(4): - draw_rand_card() + redraw_all_cards() func _update_repo(): $Repository.update_everything() @@ -38,3 +41,9 @@ func draw_rand_card(): new_card.position = Vector2(rand_range(200, get_viewport().size.x - 200), get_viewport().size.y*3/4 + rand_range(-200,200)) add_child(new_card) +func redraw_all_cards(): + for card in get_tree().get_nodes_in_group("cards"): + card.queue_free() + for i in range(10): + draw_rand_card() + diff --git a/cardgame.tscn b/cardgame.tscn index a1fcc59..66dba23 100644 --- a/cardgame.tscn +++ b/cardgame.tscn @@ -41,4 +41,15 @@ margin_left = 1488.0 margin_top = 5.0 margin_right = 1914.0 margin_bottom = 586.0 + +[node name="Button" type="Button" parent="."] +margin_left = 1726.67 +margin_top = 1021.41 +margin_right = 1899.67 +margin_bottom = 1063.41 +text = "redraw cards" +__meta__ = { +"_edit_use_anchors_": false +} [connection signal="command_done" from="Terminal" to="." method="_update_repo"] +[connection signal="pressed" from="Button" to="." method="redraw_all_cards"]