diff --git a/classes/deck/deck.gd b/classes/deck/deck.gd index 5d603f5..d142835 100644 --- a/classes/deck/deck.gd +++ b/classes/deck/deck.gd @@ -349,6 +349,19 @@ func send_event(event_name: StringName, event_data: Dictionary = {}) -> void: node._event_received(event_name, event_data) +func get_referenced_groups() -> Array[String]: + # this is expensive + # recursively returns a list of all groups referenced by this deck + var res: Array[String] = [] + for node_id: String in nodes: + var node := get_node(node_id) + if node.node_type != "group_node": + continue + res.append(node.group_id) + res.append_array(DeckHolder.get_deck(node.group_id).get_referenced_groups()) + return res + + ## Returns a [Dictionary] representation of this deck. func to_dict(with_meta: bool = true, group_ids: Array = []) -> Dictionary: var inner := { diff --git a/classes/deck/deck_holder.gd b/classes/deck/deck_holder.gd index b0b1688..132d3eb 100644 --- a/classes/deck/deck_holder.gd +++ b/classes/deck/deck_holder.gd @@ -98,9 +98,18 @@ static func close_group_instance(group_id: String, instance_id: String) -> void: decks.erase(group_id) +static func close_all_group_instances(group_id: String) -> void: + if decks.get(group_id) is Dictionary: + decks.erase(group_id) + + ## Unloads a deck. static func close_deck(deck_id: String) -> void: if decks.get(deck_id) is Deck: + var deck: Deck = decks[deck_id] as Deck + var groups := deck.get_referenced_groups() + for group in groups: + close_all_group_instances(group) decks.erase(deck_id)