mlpcardgame/Scenes/Components/Stack.gd

50 lines
No EOL
856 B
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
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):
# 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