diff --git a/classes/deck/deck.gd b/classes/deck/deck.gd index f57299f..cfac86e 100644 --- a/classes/deck/deck.gd +++ b/classes/deck/deck.gd @@ -357,15 +357,14 @@ func copy_nodes(nodes_to_copy: Array[String]) -> Dictionary: if to_node not in nodes_to_copy: (d.nodes[node].outgoing_connections[from_port] as Dictionary).erase(to_node) - var outgoing_is_empty: bool = true + var keys_to_erase := [] for from_port: int in d.nodes[node].outgoing_connections: - if not (d.nodes[node].outgoing_connections[from_port] as Dictionary).is_empty(): - outgoing_is_empty = false - break - - if outgoing_is_empty: - d.nodes[node].outgoing_connections = {} - + if (d.nodes[node].outgoing_connections[from_port] as Dictionary).is_empty(): + keys_to_erase.append(from_port) + + for key in keys_to_erase: + (d.nodes[node].outgoing_connections as Dictionary).erase(key) + var incoming_connections: Dictionary = d.nodes[node].incoming_connections.duplicate(true) for to_port: int in incoming_connections: @@ -373,14 +372,14 @@ func copy_nodes(nodes_to_copy: Array[String]) -> Dictionary: if from_node not in nodes_to_copy: (d.nodes[node].incoming_connections[to_port] as Dictionary).erase(from_node) - var incoming_is_empty: bool = true + keys_to_erase.clear() for to_port: int in d.nodes[node].incoming_connections: - if not (d.nodes[node].incoming_connections[to_port] as Dictionary).is_empty(): - incoming_is_empty = false - break - - if incoming_is_empty: - d.nodes[node].incoming_connections = {} + if (d.nodes[node].incoming_connections[to_port] as Dictionary).is_empty(): + keys_to_erase.append(to_port) + + for key in keys_to_erase: + (d.nodes[node].incoming_connections as Dictionary).erase(key) + keys_to_erase.clear() for node: Dictionary in d.nodes.values().slice(1): node.position.x = node.position.x - d.nodes.values()[0].position.x diff --git a/classes/deck/deck_node.gd b/classes/deck/deck_node.gd index f6a0615..e6e661b 100644 --- a/classes/deck/deck_node.gd +++ b/classes/deck/deck_node.gd @@ -14,7 +14,7 @@ var name: String ## [code]Dictionary[int -> output port, Dictionary[String -> DeckNode#_id, Array[int -> input port]]][/code] var outgoing_connections: Dictionary ## A map of incoming connections to this node, in the format[br] -## [code]Dictionary[int -> input port, [Dictionary[String -> DeckNode#_id, int -> output port]][/code] +## [code]Dictionary[int -> input port, Dictionary[String -> DeckNode#_id, int -> output port][/code] var incoming_connections: Dictionary ## A list of [Port]s on this node.