mlpcardgame/Scenes/Board/Stack.gd

67 lines
No EOL
1.3 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
export var showCounter: bool
var clicked: bool = false
var cards: Array = []
onready var stackCountLabel := $StackCount
func _ready():
set_title(title)
func set_title(title: String):
$StackNameViewport/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
$StackCountViewport/Label.text = str(count)
if showCounter and count > 1:
stackCountLabel.translation.y = offset+0.11+count*CARD_DISTANCE
else:
stackCountLabel.translation.y = -1