close groups belonging to deck when closing deck

This commit is contained in:
Lera Elvoé 2023-12-12 19:36:58 +03:00
parent 7a95121330
commit 0027ca5d1a
No known key found for this signature in database
2 changed files with 22 additions and 0 deletions

View file

@ -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 := {

View file

@ -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)