59 lines
No EOL
1.1 KiB
GDScript
59 lines
No EOL
1.1 KiB
GDScript
extends Area
|
|
|
|
class_name Stack
|
|
|
|
signal hover()
|
|
signal blur()
|
|
signal card_picked(card)
|
|
|
|
export var title: String
|
|
export var zoneName: String
|
|
export var faceDown: bool
|
|
export var editable: bool
|
|
export var offset: float
|
|
|
|
var clicked: bool = false
|
|
var cards: Array = []
|
|
|
|
func _ready():
|
|
set_title(title)
|
|
|
|
func set_title(title: String):
|
|
$LabelViewport/Label.text = title
|
|
|
|
func _mouse_entered():
|
|
emit_signal("hover")
|
|
|
|
func _mouse_exited():
|
|
emit_signal("blur")
|
|
|
|
func push_card(card):
|
|
# Flip card is stack has face-down cards
|
|
if faceDown:
|
|
card.flipped = true
|
|
card.animation.queue("flip-fast")
|
|
# 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 := cards.pop_front() as Card
|
|
reorder_cards()
|
|
if cards.size() > 0:
|
|
cards[0].enableInput()
|
|
if faceDown:
|
|
card.flipped = false
|
|
return card
|
|
|
|
const CARD_DISTANCE = 0.005
|
|
|
|
func reorder_cards():
|
|
var i := 0
|
|
var count := cards.size()
|
|
for card in cards:
|
|
card.translation.y = offset+(count-i)*CARD_DISTANCE
|
|
i += 1 |