50 lines
927 B
GDScript
50 lines
927 B
GDScript
extends Node2D
|
|
|
|
var _card_class = preload("res://card.gd")
|
|
|
|
# Library cards are represented as an array of card IDs.
|
|
var lib_cards: Array[String] = []
|
|
var num_cards: int = 0
|
|
|
|
|
|
func _load_card_callback(card) -> void:
|
|
card.load_card()
|
|
|
|
|
|
func _init(card_ids: Array) -> void:
|
|
lib_cards = Array()
|
|
var temp_card
|
|
for id in card_ids:
|
|
temp_card = _card_class.new()
|
|
temp_card.cache_done.connect(_load_card_callback.bind(temp_card))
|
|
lib_cards.push_back(temp_card)
|
|
num_cards += 1
|
|
|
|
|
|
func init(card_ids: Array[String]) -> void:
|
|
for id in card_ids:
|
|
pass
|
|
|
|
|
|
func add_cards(cards: Array, top: bool) -> void:
|
|
for card in cards:
|
|
add_card(card, top)
|
|
|
|
|
|
func add_card(card, top: bool) -> void:
|
|
if top:
|
|
lib_cards.push_front(card)
|
|
else:
|
|
lib_cards.push_back(card)
|
|
|
|
|
|
func shuffle() -> void:
|
|
lib_cards.shuffle()
|
|
|
|
|
|
func draw_cards(num) -> Array:
|
|
var ret = Array()
|
|
for i in num:
|
|
ret.push_back(lib_cards.pop_front())
|
|
return ret
|