44 lines
787 B
GDScript
44 lines
787 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(_decklist: Dictionary) -> void:
|
|
lib_cards = Array()
|
|
for card in _decklist:
|
|
var _num = _decklist[card]
|
|
num_cards += _num
|
|
for i in _num:
|
|
lib_cards.push_back(card)
|
|
|
|
|
|
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
|