Stacks are kinda working now

This commit is contained in:
Hamcha 2019-05-11 21:36:44 +02:00
parent df81649b53
commit 6b996285a3
Signed by: hamcha
GPG key ID: A40413D21021EAEE
6 changed files with 90 additions and 38 deletions

View file

@ -38,6 +38,7 @@ material/0 = null
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.30889, 0, 3.52858 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -4.30889, 0, 3.52858 )
title = "Deck" title = "Deck"
zoneName = "player1.deck" zoneName = "player1.deck"
faceDown = true
[node name="Graveyard" parent="Cards" instance=ExtResource( 5 )] [node name="Graveyard" parent="Cards" instance=ExtResource( 5 )]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.23371, 0, 3.52858 ) 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 ) transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, -5.23371, 0, 2.40401 )
title = "Banished" title = "Banished"
zoneName = "player1.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" ]]

View file

@ -19,7 +19,7 @@ var inHand := false
var inZone := false var inZone := false
var zoneName = "" var zoneName = ""
onready var animation := $Border/AnimationPlayer onready var animation := $CardModel/Border/AnimationPlayer
func _mouse_hover(): func _mouse_hover():
emit_signal("card_selected") emit_signal("card_selected")
@ -44,6 +44,12 @@ func _input_event(camera, event, click_position, click_normal, shape_idx):
elif inZone: elif inZone:
translation = Vector3.ZERO translation = Vector3.ZERO
rotation = 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: else:
var denom := Vector3.UP.dot(direction) var denom := Vector3.UP.dot(direction)
var t: float = (-camera.transform.origin).dot(Vector3.UP) / denom; 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 exhausted = true
func reset_transform(): func reset_transform():
$Border.translation = Vector3.ZERO $CardModel.translation = Vector3.ZERO
$CardModel.rotation = Vector3.ZERO
func _menu_action(id: int): func _menu_action(id: int):
match id: match id:
@ -100,4 +107,10 @@ func tween_rotate(targetRot: Vector3, duration: float = 0.1):
Tween.TRANS_CUBIC, Tween.EASE_IN_OUT) Tween.TRANS_CUBIC, Tween.EASE_IN_OUT)
func tween(): func tween():
$Tween.start() $Tween.start()
func disableInput():
$CollisionShape.disabled = true
func enableInput():
$CollisionShape.disabled = false

View file

@ -14,7 +14,7 @@ resource_name = "blur"
length = 0.1 length = 0.1
step = 0.01 step = 0.01
tracks/0/type = "bezier" tracks/0/type = "bezier"
tracks/0/path = NodePath(".:translation:z") tracks/0/path = NodePath("..:translation:z")
tracks/0/interp = 1 tracks/0/interp = 1
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/imported = false tracks/0/imported = false
@ -29,7 +29,7 @@ resource_name = "drop"
length = 0.1 length = 0.1
step = 0.05 step = 0.05
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/path = NodePath(".:translation") tracks/0/path = NodePath("..:translation")
tracks/0/interp = 2 tracks/0/interp = 2
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/imported = false tracks/0/imported = false
@ -74,7 +74,7 @@ tracks/1/keys = {
length = 0.1 length = 0.1
step = 0.01 step = 0.01
tracks/0/type = "bezier" tracks/0/type = "bezier"
tracks/0/path = NodePath(".:translation:z") tracks/0/path = NodePath("..:translation:z")
tracks/0/interp = 1 tracks/0/interp = 1
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/imported = false tracks/0/imported = false
@ -88,7 +88,7 @@ tracks/0/keys = {
length = 0.3 length = 0.3
step = 0.05 step = 0.05
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/path = NodePath(".:translation") tracks/0/path = NodePath("..:translation")
tracks/0/interp = 2 tracks/0/interp = 2
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/imported = false tracks/0/imported = false
@ -99,25 +99,13 @@ tracks/0/keys = {
"update": 0, "update": 0,
"values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0.15, 0 ) ] "values": [ Vector3( 0, 0, 0 ), Vector3( 0, 0.15, 0 ) ]
} }
tracks/1/type = "value" tracks/1/type = "bezier"
tracks/1/path = NodePath(".:rotation_degrees") tracks/1/path = NodePath("..:rotation_degrees:z")
tracks/1/interp = 2 tracks/1/interp = 1
tracks/1/loop_wrap = true tracks/1/loop_wrap = true
tracks/1/imported = false tracks/1/imported = false
tracks/1/enabled = false tracks/1/enabled = true
tracks/1/keys = { 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 ), "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 ) "times": PoolRealArray( 0, 0.112663, 0.3 )
} }
@ -125,7 +113,7 @@ tracks/2/keys = {
[sub_resource type="Animation" id=7] [sub_resource type="Animation" id=7]
length = 0.3 length = 0.3
tracks/0/type = "value" tracks/0/type = "value"
tracks/0/path = NodePath(".:rotation_degrees") tracks/0/path = NodePath("..:rotation_degrees")
tracks/0/interp = 2 tracks/0/interp = 2
tracks/0/loop_wrap = true tracks/0/loop_wrap = true
tracks/0/imported = false 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 ) transform = Transform( 1, 0, 0, 0, 1.17955, 0, 0, 0, 1, 0, 0.000197917, 0 )
shape = SubResource( 1 ) 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 ) mesh = ExtResource( 2 )
material/0 = ExtResource( 3 ) material/0 = ExtResource( 3 )
[node name="AnimationPlayer" type="AnimationPlayer" parent="Border"] [node name="AnimationPlayer" type="AnimationPlayer" parent="CardModel/Border"]
anims/blur = SubResource( 2 ) anims/blur = SubResource( 2 )
anims/drop = SubResource( 3 ) anims/drop = SubResource( 3 )
anims/flip = SubResource( 4 ) anims/flip = SubResource( 4 )
@ -165,8 +155,8 @@ anims/focus = SubResource( 5 )
anims/lift = SubResource( 6 ) anims/lift = SubResource( 6 )
anims/tap = SubResource( 7 ) anims/tap = SubResource( 7 )
[node name="CardImage" type="MeshInstance" parent="Border"] [node name="CardImage" type="MeshInstance" parent="CardModel/Border"]
transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.007, 0 ) transform = Transform( 0.318962, 0, 0, 0, 1, 0, 0, 0, 0.450381, 0, 0.009, 0 )
mesh = SubResource( 8 ) mesh = SubResource( 8 )
material/0 = SubResource( 9 ) material/0 = SubResource( 9 )
@ -174,4 +164,4 @@ material/0 = SubResource( 9 )
[connection signal="input_event" from="." to="." method="_input_event"] [connection signal="input_event" from="." to="." method="_input_event"]
[connection signal="mouse_entered" from="." to="." method="_mouse_hover"] [connection signal="mouse_entered" from="." to="." method="_mouse_hover"]
[connection signal="mouse_exited" from="." to="." method="_mouse_blur"] [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"]

View file

@ -4,9 +4,14 @@ class_name Stack
signal hover() signal hover()
signal blur() signal blur()
signal card_picked(card)
export var title: String export var title: String
export var zoneName: String export var zoneName: String
export var faceDown: bool
var clicked: bool = false
var cards: Array = []
func _ready(): func _ready():
set_title(title) set_title(title)
@ -19,3 +24,27 @@ func _mouse_entered():
func _mouse_exited(): func _mouse_exited():
emit_signal("blur") 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

View file

@ -2,18 +2,18 @@
[ext_resource path="res://Scenes/Components/Stack.gd" type="Script" id=1] [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 ) 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" font_path = "res://UIAssets/Fonts/Catamaran-Bold.ttf"
[sub_resource type="DynamicFont" id=2] [sub_resource type="DynamicFont" id=3]
outline_size = 2 outline_size = 2
outline_color = Color( 0, 0, 0, 0.54902 ) 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") viewport_path = NodePath("LabelViewport")
[node name="Stack" type="Area"] [node name="Stack" type="Area"]
@ -21,7 +21,7 @@ script = ExtResource( 1 )
[node name="CollisionShape" type="CollisionShape" parent="."] [node name="CollisionShape" type="CollisionShape" parent="."]
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, -0.0239744, 0 ) 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="."] [node name="CSGBox" type="CSGBox" parent="."]
transform = Transform( 0.85598, 0, 0, 0, 1, 0, 0, 0, 0.871019, 0, 0, 0 ) 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"] [node name="Label" type="Label" parent="LabelViewport"]
anchor_right = 1.0 anchor_right = 1.0
anchor_bottom = 1.0 anchor_bottom = 1.0
custom_fonts/font = SubResource( 2 ) custom_fonts/font = SubResource( 3 )
align = 1 align = 1
valign = 1 valign = 1
[node name="LabelSprite" type="Sprite3D" parent="."] [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 ) 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 ) region_rect = Rect2( 0, 0, 30, 30 )
[connection signal="mouse_entered" from="." to="." method="_mouse_entered"] [connection signal="mouse_entered" from="." to="." method="_mouse_entered"]
[connection signal="mouse_exited" from="." to="." method="_mouse_exited"] [connection signal="mouse_exited" from="." to="." method="_mouse_exited"]

View file

@ -26,6 +26,10 @@ onready var zones: Dictionary = {
func _ready(): func _ready():
add_card("ff36", 0, false) 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() reorder_hand()
func _input(event: InputEvent): func _input(event: InputEvent):
@ -68,9 +72,11 @@ func _process(delta: float):
# Move from old zone to new # Move from old zone to new
call_deferred("reparent", holdingCard, zones[holdingCard.zoneName], currentZone) call_deferred("reparent", holdingCard, zones[holdingCard.zoneName], currentZone)
holdingCard.zoneName = currentZone.zoneName holdingCard.zoneName = currentZone.zoneName
holdingCard.flipped = currentZone.faceDown
else: else:
holdingCard.inZone = true holdingCard.inZone = true
holdingCard.zoneName = currentZone.zoneName holdingCard.zoneName = currentZone.zoneName
holdingCard.flipped = currentZone.faceDown
if holdingCard.inHand: if holdingCard.inHand:
call_deferred("reparent", holdingCard, hand, currentZone) call_deferred("reparent", holdingCard, hand, currentZone)
else: else:
@ -83,6 +89,7 @@ func _process(delta: float):
call_deferred("reparent", holdingCard, zones[holdingCard.zoneName], cards) call_deferred("reparent", holdingCard, zones[holdingCard.zoneName], cards)
holdingCard.inZone = false holdingCard.inZone = false
holdingCard.zoneName = "" holdingCard.zoneName = ""
holdingCard.flipped = false
func _physics_process(delta): func _physics_process(delta):
# Do some raycast magic that normal Godot events cannot get (like ignoring items) # Do some raycast magic that normal Godot events cannot get (like ignoring items)
@ -98,6 +105,9 @@ func _physics_process(delta):
currentZone = null currentZone = null
func _card_picked(card: Card): func _card_picked(card: Card):
# Call pop if applicable
if card.inZone:
zones[card.zoneName].pop_card()
holdingCard = card holdingCard = card
holdingCard.animation.play("lift") holdingCard.animation.play("lift")
@ -106,6 +116,9 @@ func _card_dropped(card: Card):
card.animation.play("drop") card.animation.play("drop")
else: else:
card.animation.play_backwards("lift") card.animation.play_backwards("lift")
if currentZone != null:
card.inZone = true
currentZone.push_card(card)
holdingCard = null holdingCard = null
func _card_selected(card: Card): func _card_selected(card: Card):
@ -186,4 +199,7 @@ class TransformSorter:
static func sort(a, b): static func sort(a, b):
if a.transform.origin.x < b.transform.origin.x: if a.transform.origin.x < b.transform.origin.x:
return true return true
return false return false
func _card_picked_zone(card, zone):
_card_picked(card)