From 69e0f4ce752f17fc98e72d092aaeed313ab00a44 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Tue, 7 May 2019 00:18:10 +0200 Subject: [PATCH] WIP decks --- Scenes/Board.tscn | 7 +++++-- Scenes/Components/Card.gd | 4 ++-- Scenes/Components/Stack.tscn | 3 +++ Scenes/Scripts/Board.gd | 6 +++++- 4 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 Scenes/Components/Stack.tscn diff --git a/Scenes/Board.tscn b/Scenes/Board.tscn index f6412bb..cfe1dce 100644 --- a/Scenes/Board.tscn +++ b/Scenes/Board.tscn @@ -1,9 +1,10 @@ -[gd_scene load_steps=7 format=2] +[gd_scene load_steps=8 format=2] [ext_resource path="res://Scenes/Scripts/Board.gd" type="Script" id=1] [ext_resource path="res://Scenes/Scripts/Camera.gd" type="Script" id=2] [ext_resource path="res://MLPAssets/Background/boardbg.jpg" type="Texture" id=3] [ext_resource path="res://Scenes/BoardUI.tscn" type="PackedScene" id=4] +[ext_resource path="res://Scenes/Components/Stack.tscn" type="PackedScene" id=5] [sub_resource type="SpatialMaterial" id=1] flags_unshaded = true @@ -17,7 +18,7 @@ size = Vector2( 16, 9 ) script = ExtResource( 1 ) [node name="Camera" type="Camera" parent="."] -transform = Transform( 1, 0, 0, 0, 0.367808, 0.929902, 0, -0.929902, 0.367808, -0.232958, 4.94606, 3.11883 ) +transform = Transform( 1, 0, 0, 0, 0.367808, 0.929902, 0, -0.929902, 0.367808, 0, 5.05934, 3.29185 ) script = ExtResource( 2 ) [node name="Hand" type="Spatial" parent="Camera"] @@ -31,3 +32,5 @@ material/0 = null [node name="BoardUI" parent="." instance=ExtResource( 4 )] [node name="Cards" type="Spatial" parent="."] + +[node name="Deck" parent="Cards" instance=ExtResource( 5 )] diff --git a/Scenes/Components/Card.gd b/Scenes/Components/Card.gd index 5b04639..6e80a7f 100644 --- a/Scenes/Components/Card.gd +++ b/Scenes/Components/Card.gd @@ -49,12 +49,12 @@ func _input_event(camera, event, click_position, click_normal, shape_idx): if event is InputEventMouseButton and event.button_index == BUTTON_LEFT: # Update click status clicked = event.pressed - + # Check for card dropped if not clicked and lifted: emit_signal("card_dropped") lifted = false - + # Check double click if event.doubleclick and not inHand and not lifted and not animation.is_playing(): if exhausted: diff --git a/Scenes/Components/Stack.tscn b/Scenes/Components/Stack.tscn new file mode 100644 index 0000000..89906fc --- /dev/null +++ b/Scenes/Components/Stack.tscn @@ -0,0 +1,3 @@ +[gd_scene format=2] + +[node name="Stack" type="Spatial"] diff --git a/Scenes/Scripts/Board.gd b/Scenes/Scripts/Board.gd index 3f2f0f2..eb5daf6 100644 --- a/Scenes/Scripts/Board.gd +++ b/Scenes/Scripts/Board.gd @@ -123,6 +123,10 @@ func reorder_hand(): cardsInHand.sort_custom(TransformSorter, "sort") var size := cardsInHand.size() + # Check if we have nothing to order + if size < 1: + return + # Calculate total width of the player's hand and other things # This is done in two ways, for small hands, MAX_CARD_DISTANCE is usually used # as constant distance between cards, however, as the hand gets larger we don't @@ -132,7 +136,7 @@ func reorder_hand(): var distance := min(distancePerc, MAX_CARD_DISTANCE) var totalWidth := distance * (size-1) var minX := -totalWidth/2 - + # Iterate over all items, keep track of the index var i := 0 for child in cardsInHand: