Arrange Cards in Hand

This commit is contained in:
bleeptrack 2020-10-13 18:58:30 +02:00
parent af90678d45
commit 306e852e73
3 changed files with 27 additions and 30 deletions

View file

@ -13,9 +13,9 @@ script = ExtResource( 1 )
[node name="ColorRect" type="ColorRect" parent="."] [node name="ColorRect" type="ColorRect" parent="."]
margin_left = -103.0 margin_left = -103.0
margin_top = -145.0 margin_top = -290.336
margin_right = 103.0 margin_right = 103.0
margin_bottom = 144.0 margin_bottom = -1.33582
mouse_filter = 2 mouse_filter = 2
color = Color( 0.105882, 0.67451, 0.847059, 1 ) color = Color( 0.105882, 0.67451, 0.847059, 1 )
__meta__ = { __meta__ = {
@ -23,7 +23,7 @@ __meta__ = {
} }
[node name="Area2D" type="Area2D" parent="."] [node name="Area2D" type="Area2D" parent="."]
position = Vector2( 0, 6.10352e-05 ) position = Vector2( 0, -145.336 )
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"] [node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
position = Vector2( -6.10352e-05, 0.00012207 ) position = Vector2( -6.10352e-05, 0.00012207 )
@ -31,9 +31,9 @@ shape = SubResource( 1 )
[node name="Label" type="Label" parent="."] [node name="Label" type="Label" parent="."]
margin_left = -89.0 margin_left = -89.0
margin_top = -131.0 margin_top = -276.336
margin_right = 85.0 margin_right = 85.0
margin_bottom = -29.0 margin_bottom = -174.336
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"

View file

@ -12,6 +12,7 @@ var cards = [
{"command": 'git reflog expire --expire=now --all; git prune', "arg_number": 0}, {"command": 'git reflog expire --expire=now --all; git prune', "arg_number": 0},
{"command": 'git rebase', "arg_number": 1} {"command": 'git rebase', "arg_number": 1}
] ]
var total_angle = 45
func _ready(): func _ready():
@ -26,9 +27,11 @@ func _ready():
$Repository.path = path $Repository.path = path
$Terminal.repository = $Repository $Terminal.repository = $Repository
redraw_all_cards() redraw_all_cards()
arrange_cards()
func _update_repo(): func _update_repo():
$Repository.update_everything() $Repository.update_everything()
@ -38,12 +41,26 @@ func draw_rand_card():
var card = cards[randi() % cards.size()] var card = cards[randi() % cards.size()]
new_card.command = card.command new_card.command = card.command
new_card.arg_number = card.arg_number new_card.arg_number = card.arg_number
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)
arrange_cards()
func arrange_cards():
var amount_cards = get_tree().get_nodes_in_group("cards").size()
var angle_between_cards = 0
if amount_cards > 1:
angle_between_cards = total_angle / (amount_cards-1)
var current_angle = -total_angle/2
for card in get_tree().get_nodes_in_group("cards"):
card.position = Vector2(get_viewport_rect().size.x/2, get_viewport_rect().size.y + 1500)
card.rotation_degrees = current_angle
var translation_vec = Vector2(0,-1500).rotated(current_angle/180.0*PI)
card.position += translation_vec
print(current_angle)
current_angle += angle_between_cards
func redraw_all_cards(): func redraw_all_cards():
for card in get_tree().get_nodes_in_group("cards"): for card in get_tree().get_nodes_in_group("cards"):
card.queue_free() card.queue_free()
for i in range(10): for i in range(7):
draw_rand_card() draw_rand_card()

View file

@ -1,6 +1,5 @@
[gd_scene load_steps=6 format=2] [gd_scene load_steps=5 format=2]
[ext_resource path="res://card.tscn" type="PackedScene" id=1]
[ext_resource path="res://drop_area.tscn" type="PackedScene" id=2] [ext_resource path="res://drop_area.tscn" type="PackedScene" id=2]
[ext_resource path="res://repository.tscn" type="PackedScene" id=3] [ext_resource path="res://repository.tscn" type="PackedScene" id=3]
[ext_resource path="res://cardgame.gd" type="Script" id=4] [ext_resource path="res://cardgame.gd" type="Script" id=4]
@ -12,30 +11,11 @@ script = ExtResource( 4 )
[node name="Repository" parent="." instance=ExtResource( 3 )] [node name="Repository" parent="." instance=ExtResource( 3 )]
margin_right = 1481.0 margin_right = 1481.0
margin_bottom = 592.0 margin_bottom = 592.0
file_browser_active = false
simplified_view = true
[node name="DropArea" parent="." instance=ExtResource( 2 )] [node name="DropArea" parent="." instance=ExtResource( 2 )]
[node name="Card2" parent="." instance=ExtResource( 1 )]
visible = false
position = Vector2( 948.833, 814.382 )
command = "git commit --allow-empty -m \"$RANDOM\""
[node name="Card4" parent="." instance=ExtResource( 1 )]
visible = false
position = Vector2( 1651.83, 834.382 )
command = "touch \"file$RANDOM\""
[node name="Card3" parent="." instance=ExtResource( 1 )]
visible = false
position = Vector2( 1348, 830.017 )
command = "git add ."
[node name="Card" parent="." instance=ExtResource( 1 )]
visible = false
position = Vector2( 558.857, 824.539 )
arg_number = 1
command = "git checkout"
[node name="Terminal" parent="." instance=ExtResource( 5 )] [node name="Terminal" parent="." instance=ExtResource( 5 )]
margin_left = 1488.0 margin_left = 1488.0
margin_top = 5.0 margin_top = 5.0