From 6b996285a3cd4d9c68f0b1902cd693e43baa6995 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Sat, 11 May 2019 21:36:44 +0200 Subject: [PATCH] Stacks are kinda working now --- Scenes/Board.tscn | 4 ++++ Scenes/Components/Card.gd | 19 +++++++++++++--- Scenes/Components/Card.tscn | 42 ++++++++++++++---------------------- Scenes/Components/Stack.gd | 29 +++++++++++++++++++++++++ Scenes/Components/Stack.tscn | 16 +++++++------- Scenes/Scripts/Board.gd | 18 +++++++++++++++- 6 files changed, 90 insertions(+), 38 deletions(-) diff --git a/Scenes/Board.tscn b/Scenes/Board.tscn index 23d4ac6..9145d93 100644 --- a/Scenes/Board.tscn +++ b/Scenes/Board.tscn @@ -38,6 +38,7 @@ material/0 = null transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.30889, 0, 3.52858 ) title = "Deck" zoneName = "player1.deck" +faceDown = true [node name="Graveyard" parent="Cards" instance=ExtResource( 5 )] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.23371, 0, 3.52858 ) @@ -48,3 +49,6 @@ zoneName = "player1.graveyard" transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.23371, 0, 2.40401 ) title = "Banished" zoneName = "player1.banished" +[connection signal="card_picked" from="Cards/Deck" to="." method="_card_picked_zone" binds= [ "player1.deck" ]] +[connection signal="card_picked" from="Cards/Graveyard" to="." method="_card_picked_zone" binds= [ "player1.graveyard" ]] +[connection signal="card_picked" from="Cards/Banished" to="." method="_card_picked_zone" binds= [ "player1.banished" ]] diff --git a/Scenes/Components/Card.gd b/Scenes/Components/Card.gd index 30867e3..9a3f912 100644 --- a/Scenes/Components/Card.gd +++ b/Scenes/Components/Card.gd @@ -19,7 +19,7 @@ var inHand := false var inZone := false var zoneName = "" -onready var animation := $Border/AnimationPlayer +onready var animation := $CardModel/Border/AnimationPlayer func _mouse_hover(): emit_signal("card_selected") @@ -44,6 +44,12 @@ func _input_event(camera, event, click_position, click_normal, shape_idx): elif inZone: translation = Vector3.ZERO rotation = Vector3.ZERO + if flipped: + $CardModel/Border.translation = Vector3(0, 0.01, 0) + $CardModel/Border.rotation = Vector3(0, 0, PI) + else: + $CardModel/Border.translation = Vector3.ZERO + $CardModel/Border.rotation = Vector3.ZERO else: var denom := Vector3.UP.dot(direction) var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom; @@ -73,7 +79,8 @@ func _input_event(camera, event, click_position, click_normal, shape_idx): exhausted = true func reset_transform(): - $Border.translation = Vector3.ZERO + $CardModel.translation = Vector3.ZERO + $CardModel.rotation = Vector3.ZERO func _menu_action(id: int): match id: @@ -100,4 +107,10 @@ func tween_rotate(targetRot: Vector3, duration: float = 0.1): Tween.TRANS_CUBIC, Tween.EASE_IN_OUT) func tween(): - $Tween.start() \ No newline at end of file + $Tween.start() + +func disableInput(): + $CollisionShape.disabled = true + +func enableInput(): + $CollisionShape.disabled = false \ No newline at end of file diff --git a/Scenes/Components/Card.tscn b/Scenes/Components/Card.tscn index 43e14ef..e73323f 100644 --- a/Scenes/Components/Card.tscn +++ b/Scenes/Components/Card.tscn @@ -14,7 +14,7 @@ resource_name = "blur" length = 0.1 step = 0.01 tracks/0/type = "bezier" -tracks/0/path = NodePath(".:translation:z") +tracks/0/path = NodePath("..:translation:z") tracks/0/interp = 1 tracks/0/loop_wrap = true tracks/0/imported = false @@ -29,7 +29,7 @@ resource_name = "drop" length = 0.1 step = 0.05 tracks/0/type = "value" -tracks/0/path = NodePath(".:translation") +tracks/0/path = NodePath("..:translation") tracks/0/interp = 2 tracks/0/loop_wrap = true tracks/0/imported = false @@ -74,7 +74,7 @@ tracks/1/keys = { length = 0.1 step = 0.01 tracks/0/type = "bezier" -tracks/0/path = NodePath(".:translation:z") +tracks/0/path = NodePath("..:translation:z") tracks/0/interp = 1 tracks/0/loop_wrap = true tracks/0/imported = false @@ -88,7 +88,7 @@ tracks/0/keys = { length = 0.3 step = 0.05 tracks/0/type = "value" -tracks/0/path = NodePath(".:translation") +tracks/0/path = NodePath("..:translation") tracks/0/interp = 2 tracks/0/loop_wrap = true tracks/0/imported = false @@ -99,25 +99,13 @@ tracks/0/keys = { "update": 0, "values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0.15, 0 ) ] } -tracks/1/type = "value" -tracks/1/path = NodePath(".:rotation_degrees") -tracks/1/interp = 2 +tracks/1/type = "bezier" +tracks/1/path = NodePath("..:rotation_degrees:z") +tracks/1/interp = 1 tracks/1/loop_wrap = true tracks/1/imported = false -tracks/1/enabled = false +tracks/1/enabled = true tracks/1/keys = { -"times": PoolRealArray( 0, 0.05, 0.15, 0.3 ), -"transitions": PoolRealArray( 0.392292, 0.392292, 1, 0.329877 ), -"update": 0, -"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0, 0 ), Vector3( 0, 0, 9.73853 ), Vector3( 0, 0, 0 ) ] -} -tracks/2/type = "bezier" -tracks/2/path = NodePath(".:rotation_degrees:z") -tracks/2/interp = 1 -tracks/2/loop_wrap = true -tracks/2/imported = false -tracks/2/enabled = true -tracks/2/keys = { "points": PoolRealArray( 0, -0.0279863, -0.888281, 0.0279863, 0.888281, -6.53051, -0.0617135, -2.00939, 0.0466494, 1.5189, 0, -0.173703, -0.837245, 0.134235, 0.64701 ), "times": PoolRealArray( 0, 0.112663, 0.3 ) } @@ -125,7 +113,7 @@ tracks/2/keys = { [sub_resource type="Animation" id=7] length = 0.3 tracks/0/type = "value" -tracks/0/path = NodePath(".:rotation_degrees") +tracks/0/path = NodePath("..:rotation_degrees") tracks/0/interp = 2 tracks/0/loop_wrap = true tracks/0/imported = false @@ -153,11 +141,13 @@ script = ExtResource( 1 ) transform = Transform( 1, 0, 0, 0, 1.17955, 0, 0, 0, 1, 0, 0.000197917, 0 ) shape = SubResource( 1 ) -[node name="Border" type="MeshInstance" parent="."] +[node name="CardModel" type="Spatial" parent="."] + +[node name="Border" type="MeshInstance" parent="CardModel"] mesh = ExtResource( 2 ) material/0 = ExtResource( 3 ) -[node name="AnimationPlayer" type="AnimationPlayer" parent="Border"] +[node name="AnimationPlayer" type="AnimationPlayer" parent="CardModel/Border"] anims/blur = SubResource( 2 ) anims/drop = SubResource( 3 ) anims/flip = SubResource( 4 ) @@ -165,8 +155,8 @@ anims/focus = SubResource( 5 ) anims/lift = SubResource( 6 ) anims/tap = SubResource( 7 ) -[node name="CardImage" type="MeshInstance" parent="Border"] -transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.007, 0 ) +[node name="CardImage" type="MeshInstance" parent="CardModel/Border"] +transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.009, 0 ) mesh = SubResource( 8 ) material/0 = SubResource( 9 ) @@ -174,4 +164,4 @@ material/0 = SubResource( 9 ) [connection signal="input_event" from="." to="." method="_input_event"] [connection signal="mouse_entered" from="." to="." method="_mouse_hover"] [connection signal="mouse_exited" from="." to="." method="_mouse_blur"] -[connection signal="animation_finished" from="Border/AnimationPlayer" to="." method="_check_drop_anim"] +[connection signal="animation_finished" from="CardModel/Border/AnimationPlayer" to="." method="_check_drop_anim"] diff --git a/Scenes/Components/Stack.gd b/Scenes/Components/Stack.gd index 3c99c4c..ac45c5f 100644 --- a/Scenes/Components/Stack.gd +++ b/Scenes/Components/Stack.gd @@ -4,9 +4,14 @@ class_name Stack signal hover() signal blur() +signal card_picked(card) export var title: String export var zoneName: String +export var faceDown: bool + +var clicked: bool = false +var cards: Array = [] func _ready(): set_title(title) @@ -19,3 +24,27 @@ func _mouse_entered(): func _mouse_exited(): emit_signal("blur") + +func push_card(card): + # Disable collider for top card + if cards.size() > 0: + cards[0].disableInput() + cards.push_front(card) + reorder_cards() + +func pop_card() -> Card: + if cards.size() < 1: + return null + var card: Card = cards.pop_front() + reorder_cards() + if cards.size() > 0: + cards[0].enableInput() + return card + +const CARD_DISTANCE = 0.01 + +func reorder_cards(): + var i := 0 + for card in cards: + card.translation.y = i*CARD_DISTANCE + i += 1 \ No newline at end of file diff --git a/Scenes/Components/Stack.tscn b/Scenes/Components/Stack.tscn index 0e1af26..9307c27 100644 --- a/Scenes/Components/Stack.tscn +++ b/Scenes/Components/Stack.tscn @@ -2,18 +2,18 @@ [ext_resource path="res://Scenes/Components/Stack.gd" type="Script" id=1] -[sub_resource type="BoxShape" id=4] +[sub_resource type="BoxShape" id=1] extents = Vector3( 0.424389, 0.024053, 0.546632 ) -[sub_resource type="DynamicFontData" id=1] +[sub_resource type="DynamicFontData" id=2] font_path = "res://UIAssets/Fonts/Catamaran-Bold.ttf" -[sub_resource type="DynamicFont" id=2] +[sub_resource type="DynamicFont" id=3] outline_size = 2 outline_color = Color( 0, 0, 0, 0.54902 ) -font_data = SubResource( 1 ) +font_data = SubResource( 2 ) -[sub_resource type="ViewportTexture" id=3] +[sub_resource type="ViewportTexture" id=4] viewport_path = NodePath("LabelViewport") [node name="Stack" type="Area"] @@ -21,7 +21,7 @@ script = ExtResource( 1 ) [node name="CollisionShape" type="CollisionShape" parent="."] transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0239744, 0 ) -shape = SubResource( 4 ) +shape = SubResource( 1 ) [node name="CSGBox" type="CSGBox" parent="."] transform = Transform( 0.85598, 0, 0, 0, 1, 0, 0, 0, 0.871019, 0, 0, 0 ) @@ -57,13 +57,13 @@ usage = 0 [node name="Label" type="Label" parent="LabelViewport"] anchor_right = 1.0 anchor_bottom = 1.0 -custom_fonts/font = SubResource( 2 ) +custom_fonts/font = SubResource( 3 ) align = 1 valign = 1 [node name="LabelSprite" type="Sprite3D" parent="."] transform = Transform( 0.5853, 0.810817, -3.54419e-008, 0, -4.37114e-008, -1, -0.810817, 0.5853, -2.55843e-008, 1.05839e-009, 0.0298628, 7.64017e-010 ) -texture = SubResource( 3 ) +texture = SubResource( 4 ) region_rect = Rect2( 0, 0, 30, 30 ) [connection signal="mouse_entered" from="." to="." method="_mouse_entered"] [connection signal="mouse_exited" from="." to="." method="_mouse_exited"] diff --git a/Scenes/Scripts/Board.gd b/Scenes/Scripts/Board.gd index c632d73..9c4ace6 100644 --- a/Scenes/Scripts/Board.gd +++ b/Scenes/Scripts/Board.gd @@ -26,6 +26,10 @@ onready var zones: Dictionary = { func _ready(): add_card("ff36", 0, false) + add_card("ff36", 0, true) + add_card("ff36", 0, true) + add_card("ff36", 0, true) + add_card("ff36", 0, true) reorder_hand() func _input(event: InputEvent): @@ -68,9 +72,11 @@ func _process(delta: float): # Move from old zone to new call_deferred("reparent", holdingCard, zones[holdingCard.zoneName], currentZone) holdingCard.zoneName = currentZone.zoneName + holdingCard.flipped = currentZone.faceDown else: holdingCard.inZone = true holdingCard.zoneName = currentZone.zoneName + holdingCard.flipped = currentZone.faceDown if holdingCard.inHand: call_deferred("reparent", holdingCard, hand, currentZone) else: @@ -83,6 +89,7 @@ func _process(delta: float): call_deferred("reparent", holdingCard, zones[holdingCard.zoneName], cards) holdingCard.inZone = false holdingCard.zoneName = "" + holdingCard.flipped = false func _physics_process(delta): # Do some raycast magic that normal Godot events cannot get (like ignoring items) @@ -98,6 +105,9 @@ func _physics_process(delta): currentZone = null func _card_picked(card: Card): + # Call pop if applicable + if card.inZone: + zones[card.zoneName].pop_card() holdingCard = card holdingCard.animation.play("lift") @@ -106,6 +116,9 @@ func _card_dropped(card: Card): card.animation.play("drop") else: card.animation.play_backwards("lift") + if currentZone != null: + card.inZone = true + currentZone.push_card(card) holdingCard = null func _card_selected(card: Card): @@ -186,4 +199,7 @@ class TransformSorter: static func sort(a, b): if a.transform.origin.x < b.transform.origin.x: return true - return false \ No newline at end of file + return false + +func _card_picked_zone(card, zone): + _card_picked(card)