mlpcardgame/Scenes/Board/Stack.gd

67 lines
1.3 KiB
GDScript3
Raw Normal View History

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
export var editable: bool
export var offset: float
2019-05-26 22:00:15 +00:00
export var showCounter: bool
2019-05-11 19:36:44 +00:00
var clicked: bool = false
var cards: Array = []
2019-05-06 23:25:08 +00:00
2019-05-26 22:00:15 +00:00
onready var stackCountLabel := $StackCount
2019-05-06 23:25:08 +00:00
func _ready():
set_title(title)
func set_title(title: String):
2019-05-26 22:00:15 +00:00
$StackNameViewport/Label.text = title
2019-05-07 18:56:26 +00:00
func _mouse_entered():
emit_signal("hover")
func _mouse_exited():
emit_signal("blur")
2019-05-11 19:36:44 +00:00
func push_card(card):
# 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
var card := cards.pop_front() as Card
2019-05-11 19:36:44 +00:00
reorder_cards()
if cards.size() > 0:
cards[0].enableInput()
if faceDown:
card.flipped = false
2019-05-11 19:36:44 +00:00
return card
const CARD_DISTANCE = 0.005
2019-05-11 19:36:44 +00:00
func reorder_cards():
var i := 0
var count := cards.size()
2019-05-11 19:36:44 +00:00
for card in cards:
card.translation.y = offset+(count-i)*CARD_DISTANCE
2019-05-26 22:00:15 +00:00
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