From c2b04e816b9f53fc6d251d44b3657fb48b9018ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Sun, 11 Jun 2023 19:26:12 +0300 Subject: [PATCH] remove connection method in deck node, disconnect nodes method in deck --- classes/deck/deck.gd | 5 +++++ classes/deck/deck_node.gd | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/classes/deck/deck.gd b/classes/deck/deck.gd index b2bd3f9..09887f8 100644 --- a/classes/deck/deck.gd +++ b/classes/deck/deck.gd @@ -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) diff --git a/classes/deck/deck_node.gd b/classes/deck/deck_node.gd index 73b97bf..108d210 100644 --- a/classes/deck/deck_node.gd +++ b/classes/deck/deck_node.gd @@ -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