2019-05-07 18:56:26 +00:00
|
|
|
extends Area
|
|
|
|
|
|
|
|
class_name Stack
|
|
|
|
|
|
|
|
signal hover()
|
|
|
|
signal blur()
|
2019-05-11 19:36:44 +00:00
|
|
|
signal card_picked(card)
|
2019-05-06 23:25:08 +00:00
|
|
|
|
|
|
|
export var title: String
|
2019-05-07 18:56:26 +00:00
|
|
|
export var zoneName: String
|
2019-05-11 19:36:44 +00:00
|
|
|
export var faceDown: bool
|
2019-05-16 22:03:05 +00:00
|
|
|
export var editable: bool
|
|
|
|
export var offset: float
|
2019-05-11 19:36:44 +00:00
|
|
|
|
|
|
|
var clicked: bool = false
|
|
|
|
var cards: Array = []
|
2019-05-06 23:25:08 +00:00
|
|
|
|
|
|
|
func _ready():
|
|
|
|
set_title(title)
|
|
|
|
|
|
|
|
func set_title(title: String):
|
2019-05-07 18:56:26 +00:00
|
|
|
$LabelViewport/Label.text = title
|
|
|
|
|
|
|
|
func _mouse_entered():
|
|
|
|
emit_signal("hover")
|
|
|
|
|
|
|
|
func _mouse_exited():
|
|
|
|
emit_signal("blur")
|
2019-05-11 19:36:44 +00:00
|
|
|
|
|
|
|
func push_card(card):
|
2019-05-16 22:55:46 +00:00
|
|
|
# Flip card is stack has face-down cards
|
|
|
|
if faceDown:
|
|
|
|
card.flipped = true
|
|
|
|
card.animation.queue("flip-fast")
|
2019-05-11 19:36:44 +00:00
|
|
|
# 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
|
2019-05-16 22:55:46 +00:00
|
|
|
var card := cards.pop_front() as Card
|
2019-05-11 19:36:44 +00:00
|
|
|
reorder_cards()
|
|
|
|
if cards.size() > 0:
|
|
|
|
cards[0].enableInput()
|
2019-05-16 22:55:46 +00:00
|
|
|
if faceDown:
|
|
|
|
card.flipped = false
|
2019-05-11 19:36:44 +00:00
|
|
|
return card
|
|
|
|
|
2019-05-16 22:55:46 +00:00
|
|
|
const CARD_DISTANCE = 0.005
|
2019-05-11 19:36:44 +00:00
|
|
|
|
|
|
|
func reorder_cards():
|
|
|
|
var i := 0
|
2019-05-16 21:41:09 +00:00
|
|
|
var count := cards.size()
|
2019-05-11 19:36:44 +00:00
|
|
|
for card in cards:
|
2019-05-16 22:03:05 +00:00
|
|
|
card.translation.y = offset+(count-i)*CARD_DISTANCE
|
2019-05-11 19:36:44 +00:00
|
|
|
i += 1
|