remove connection method in deck node, disconnect nodes method in deck

This commit is contained in:
Lera Elvoé 2023-06-11 19:26:12 +03:00
parent 2c4a937a76
commit c2b04e816b
No known key found for this signature in database
2 changed files with 22 additions and 0 deletions

View file

@ -54,3 +54,8 @@ func connect_nodes(from_node: DeckNode, to_node: DeckNode, from_port: int, to_po
from_node.add_outgoing_connection(from_port, to_node._id, to_port)
return true
func disconnect_nodes(from_node: DeckNode, to_node: DeckNode, from_port: int, to_port: int) -> void:
var hash = {to_node._id: to_port}.hash()
from_node.remove_outgoing_connection(from_port, hash)

View file

@ -39,3 +39,20 @@ func add_outgoing_connection(from_port: int, to_node: String, to_port: int) -> v
var port_connections: Array = outgoing_connections.get(from_port, [])
port_connections.append({to_node: to_port})
outgoing_connections[from_port] = port_connections
func remove_outgoing_connection(from_port: int, connection_hash: int) -> void:
var port_connections: Array = (outgoing_connections.get(from_port, []) as Array).duplicate(true)
if port_connections.is_empty():
return
var to_remove: int = -1
for i in port_connections.size():
if port_connections[i].hash() == connection_hash:
to_remove = i
if to_remove == -1:
return
port_connections.remove_at(to_remove)
outgoing_connections[from_port] = port_connections