From 2ac9db8350e30989d82d2620a86de62246032cf9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Thu, 11 Apr 2024 06:53:51 +0000 Subject: [PATCH] fix node connections not being empty on copy/paste (#142) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/142 Co-authored-by: Lera ElvoƩ Co-committed-by: Lera ElvoƩ --- classes/deck/deck.gd | 29 ++++++++++++++--------------- classes/deck/deck_node.gd | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) 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.