fix node connections not being empty on copy/paste (#142)

Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/142
Co-authored-by: Lera Elvoé <yagich@poto.cafe>
Co-committed-by: Lera Elvoé <yagich@poto.cafe>
This commit is contained in:
Lera Elvoé 2024-04-11 06:53:51 +00:00 committed by yagich
parent 82edd774a0
commit 2ac9db8350
2 changed files with 15 additions and 16 deletions

View file

@ -357,14 +357,13 @@ func copy_nodes(nodes_to_copy: Array[String]) -> Dictionary:
if to_node not in nodes_to_copy: if to_node not in nodes_to_copy:
(d.nodes[node].outgoing_connections[from_port] as Dictionary).erase(to_node) (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: for from_port: int in d.nodes[node].outgoing_connections:
if not (d.nodes[node].outgoing_connections[from_port] as Dictionary).is_empty(): if (d.nodes[node].outgoing_connections[from_port] as Dictionary).is_empty():
outgoing_is_empty = false keys_to_erase.append(from_port)
break
if outgoing_is_empty: for key in keys_to_erase:
d.nodes[node].outgoing_connections = {} (d.nodes[node].outgoing_connections as Dictionary).erase(key)
var incoming_connections: Dictionary = d.nodes[node].incoming_connections.duplicate(true) var incoming_connections: Dictionary = d.nodes[node].incoming_connections.duplicate(true)
@ -373,14 +372,14 @@ func copy_nodes(nodes_to_copy: Array[String]) -> Dictionary:
if from_node not in nodes_to_copy: if from_node not in nodes_to_copy:
(d.nodes[node].incoming_connections[to_port] as Dictionary).erase(from_node) (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: for to_port: int in d.nodes[node].incoming_connections:
if not (d.nodes[node].incoming_connections[to_port] as Dictionary).is_empty(): if (d.nodes[node].incoming_connections[to_port] as Dictionary).is_empty():
incoming_is_empty = false keys_to_erase.append(to_port)
break
if incoming_is_empty: for key in keys_to_erase:
d.nodes[node].incoming_connections = {} (d.nodes[node].incoming_connections as Dictionary).erase(key)
keys_to_erase.clear()
for node: Dictionary in d.nodes.values().slice(1): for node: Dictionary in d.nodes.values().slice(1):
node.position.x = node.position.x - d.nodes.values()[0].position.x node.position.x = node.position.x - d.nodes.values()[0].position.x

View file

@ -14,7 +14,7 @@ var name: String
## [code]Dictionary[int -> output port, Dictionary[String -> DeckNode#_id, Array[int -> input port]]][/code] ## [code]Dictionary[int -> output port, Dictionary[String -> DeckNode#_id, Array[int -> input port]]][/code]
var outgoing_connections: Dictionary var outgoing_connections: Dictionary
## A map of incoming connections to this node, in the format[br] ## 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 var incoming_connections: Dictionary
## A list of [Port]s on this node. ## A list of [Port]s on this node.