From 0ebe17399d28ca8acdbeb589d68fa1facacd8eb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Wed, 17 Jan 2024 08:15:02 +0000 Subject: [PATCH] fix connections being copied incorrectly (#42) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit when copying nodes, incoming and outgoing connections could be copied in such a way that they had (empty) entries in the outgoing/incoming connections dictionaries despite not being connected to anything Reviewed-on: https://codeberg.org/Eroax/StreamGraph/pulls/42 Co-authored-by: Lera ElvoƩ Co-committed-by: Lera ElvoƩ --- classes/deck/deck.gd | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/classes/deck/deck.gd b/classes/deck/deck.gd index 703b718..94b9e02 100644 --- a/classes/deck/deck.gd +++ b/classes/deck/deck.gd @@ -307,12 +307,30 @@ func copy_nodes(nodes_to_copy: Array[String]) -> Dictionary: if !(to_node in nodes_to_copy): (d.nodes[node].outgoing_connections[from_port] as Dictionary).erase(to_node) + var outgoing_is_empty: bool = true + for from_port: int in d.nodes[node].outgoing_connections: + if !(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 = {} + var incoming_connections: Dictionary = d.nodes[node].incoming_connections.duplicate(true) for to_port: int in incoming_connections: for from_node: String in incoming_connections[to_port]: if !(from_node in nodes_to_copy): (d.nodes[node].incoming_connections[to_port] as Dictionary).erase(from_node) + + var incoming_is_empty: bool = true + for to_port: int in d.nodes[node].incoming_connections: + if !(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 = {} for node: Dictionary in d.nodes.values().slice(1): node.position.x = node.position.x - d.nodes.values()[0].position.x