22 lines
612 B
GDScript
22 lines
612 B
GDScript
class_name CardStack
|
|
extends Node3D
|
|
|
|
var _card_height: float = 0.02
|
|
|
|
@export var playing_card_scene: PackedScene
|
|
|
|
func add_card(card: PlayingCard) -> void:
|
|
var height = self.get_child_count() * _card_height
|
|
self.add_child(card)
|
|
card.rotate(Vector3.FORWARD, randf_range(-0.3, 0.3))
|
|
card.translate(Vector3.BACK * height)
|
|
|
|
func add_card_by_id(card_id: int) -> void:
|
|
var playing_card: PlayingCard = playing_card_scene.instantiate()
|
|
playing_card.setup_card_details(card_id)
|
|
add_card(playing_card)
|
|
|
|
func purge_cards() -> void:
|
|
while get_child_count() > 0:
|
|
remove_child(get_children()[get_child_count() - 1])
|