extends Panel const BattleHelper = preload("res://helpers/battle.gd") export(PackedScene) var deck_attack export(PackedScene) var deck_defend onready var deck_attack_cards = deck_attack.instance() onready var deck_defend_cards = deck_defend.instance() var hero_attack var hero_defend func _ready(): hero_attack = create_hero_unit("tomahawk", "attack_start") hero_defend = create_hero_unit("rhino", "defend_start") fill_hand($hand_attack, deck_attack_cards, hero_attack) fill_hand($hand_defend, deck_defend_cards, hero_defend) func find_free_anchor(anchor_type: String): for anchor in get_tree().get_nodes_in_group("anchors"): if anchor.anchor_type == anchor_type and anchor.is_empty(): return anchor return null func create_hero_unit(name: String, anchor_type: String): var anchor = find_free_anchor(anchor_type) if anchor: return BattleHelper.spawn_unit("heroes/" + name, anchor) else: return null func fill_hand(hand: Node, deck: Node, hero: Node, limit=4): while hand.get_child_count() < 4: var count = deck.get_child_count() var index = floor(rand_range(0, count)) var card = deck.get_child(index).duplicate() card.set_hero(hero) hand.add_child(card) reorganize_hand(hand) func reorganize_hand(hand: Node): var i = 0 for card in hand.get_children(): card.set_hand_location(Vector2(i * 210, 0)) i += 1