New Cards and Redraw Button

This commit is contained in:
bleeptrack 2020-10-13 18:13:42 +02:00
parent 0d5c78d2a4
commit af90678d45
4 changed files with 36 additions and 10 deletions

View file

@ -62,8 +62,11 @@ func dropped_on(other):
#print("I have been dropped on "+str(other.id)) #print("I have been dropped on "+str(other.id))
var full_command = "" var full_command = ""
match arg_number: match arg_number:
1: 1:
full_command = $Label.text + " " + other.id 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) $"../Terminal".send_command(full_command)
buuurn() buuurn()
2: 2:

View file

@ -6,7 +6,9 @@
[sub_resource type="RectangleShape2D" id=1] [sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 105.74, 143.46 ) extents = Vector2( 105.74, 143.46 )
[node name="Card" type="Node2D"] [node name="Card" type="Node2D" groups=[
"cards",
]]
script = ExtResource( 1 ) script = ExtResource( 1 )
[node name="ColorRect" type="ColorRect" parent="."] [node name="ColorRect" type="ColorRect" parent="."]
@ -28,13 +30,14 @@ position = Vector2( -6.10352e-05, 0.00012207 )
shape = SubResource( 1 ) shape = SubResource( 1 )
[node name="Label" type="Label" parent="."] [node name="Label" type="Label" parent="."]
margin_left = -89.1555 margin_left = -89.0
margin_top = -131.488 margin_top = -131.0
margin_right = -38.1555 margin_right = 85.0
margin_bottom = -117.488 margin_bottom = -29.0
custom_fonts/font = ExtResource( 2 ) custom_fonts/font = ExtResource( 2 )
custom_colors/font_color = Color( 0, 0, 0, 1 ) custom_colors/font_color = Color( 0, 0, 0, 1 )
text = "git checkout" text = "git checkout"
autowrap = true
__meta__ = { __meta__ = {
"_edit_use_anchors_": false "_edit_use_anchors_": false
} }

View file

@ -6,7 +6,11 @@ var cards = [
{"command": 'touch "file$RANDOM"', "arg_number": 0}, {"command": 'touch "file$RANDOM"', "arg_number": 0},
{"command": 'git commit --allow-empty -m "$RANDOM"', "arg_number": 0}, {"command": 'git commit --allow-empty -m "$RANDOM"', "arg_number": 0},
{"command": 'git checkout -b "$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(): func _ready():
@ -24,8 +28,7 @@ func _ready():
$Terminal.repository = $Repository $Terminal.repository = $Repository
for i in range(4): redraw_all_cards()
draw_rand_card()
func _update_repo(): func _update_repo():
$Repository.update_everything() $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)) 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) 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()

View file

@ -41,4 +41,15 @@ margin_left = 1488.0
margin_top = 5.0 margin_top = 5.0
margin_right = 1914.0 margin_right = 1914.0
margin_bottom = 586.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="command_done" from="Terminal" to="." method="_update_repo"]
[connection signal="pressed" from="Button" to="." method="redraw_all_cards"]