fix connections being copied incorrectly (#42)

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é <yagich@poto.cafe>
Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
Lera Elvoé 2024-01-17 08:15:02 +00:00 committed by yagich
parent 5a214c16f8
commit 0ebe17399d

View file

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