diff --git a/classes/deck/deck.gd b/classes/deck/deck.gd index 2ebbb8b..743f9a8 100644 --- a/classes/deck/deck.gd +++ b/classes/deck/deck.gd @@ -89,10 +89,9 @@ func connect_nodes(from_node_id: String, to_node_id: String, from_output_port: i ## Remove a connection from two nodes. func disconnect_nodes(from_node_id: String, to_node_id: String, from_output_port: int, to_input_port: int) -> void: - var hash := {to_node_id: to_input_port}.hash() var from_node := get_node(from_node_id) var to_node := get_node(to_node_id) - from_node.remove_outgoing_connection(from_output_port, hash) + from_node.remove_outgoing_connection(from_output_port, to_node_id, to_input_port) to_node.remove_incoming_connection(to_input_port) @@ -252,10 +251,13 @@ static func from_dict(data: Dictionary, path: String = "") -> Deck: node._pre_connection() for from_port: String in nodes_data[node_id].outgoing_connections: - var connection_data = nodes_data[node_id].outgoing_connections[from_port] - for connection in connection_data: - connection_data[connection] = int(connection_data[connection]) - node.outgoing_connections[int(from_port)] = connection_data + var connection_data: Dictionary = nodes_data[node_id].outgoing_connections[from_port] + node.outgoing_connections[int(from_port)] = {} + for to_node: String in connection_data: + var input_ports: Array = connection_data[to_node] + node.outgoing_connections[int(from_port)][to_node] = [] + for to_input_port in input_ports: + node.outgoing_connections[int(from_port)][to_node].append(int(to_input_port)) for to_port: String in nodes_data[node_id].incoming_connections: var connection_data = nodes_data[node_id].incoming_connections[to_port] diff --git a/classes/deck/deck_node.gd b/classes/deck/deck_node.gd index b503474..cbfcbf6 100644 --- a/classes/deck/deck_node.gd +++ b/classes/deck/deck_node.gd @@ -8,7 +8,7 @@ class_name DeckNode var name: String ## A map of outgoing connections from this node, in the format[br] -## [code]Dictionary[int -> output port, Dictionary[String -> DeckNode#_id, int -> input port]][/code] +## [code]Dictionary[int -> output port, Dictionary[String -> DeckNode#_id, Array[int -> input port]]][/code] var outgoing_connections: Dictionary ## 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] @@ -102,7 +102,8 @@ func send(from_output_port: int, data: Variant, extra_data: Array = []) -> void: return for node: String in outgoing_connections[from_output_port]: - get_node(node)._receive(outgoing_connections[from_output_port][node], data, extra_data) + for input_port: int in outgoing_connections[from_output_port][node]: + get_node(node)._receive(input_port, data, extra_data) ## Virtual function that's called when this node receives data from another node's [method send] call. @@ -113,11 +114,13 @@ func _receive(to_input_port: int, data: Variant, extra_data: Array = []) -> void ## Add a connection from the output port at [param from_port] to [param to_node]'s input port ## at [param to_port]. func add_outgoing_connection(from_port: int, to_node: String, to_port: int) -> void: - var connection := {to_node: to_port} var inner: Dictionary = outgoing_connections.get(from_port, {}) as Dictionary - inner.merge(connection) + var ports: Array = inner.get(to_node, []) as Array + ports.append(to_port) + inner[to_node] = ports outgoing_connections[from_port] = inner get_node(to_node).add_incoming_connection(to_port, _id, from_port) + outgoing_connection_added.emit(from_port) ## Add an incoming connection from [param from_node]'s output port at [param from_port] to this node's @@ -148,15 +151,16 @@ func _value_request(from_port: int) -> Variant: ## Remove an outgoing connection from this node. ## Does [b]not[/b] remove the other node's incoming connection equivalent. -func remove_outgoing_connection(from_port: int, connection_hash: int) -> void: - var connections: Dictionary = outgoing_connections.duplicate(true).get(from_port, {}) as Dictionary +func remove_outgoing_connection(from_port: int, to_node: String, to_port: int) -> void: + var connections: Dictionary = outgoing_connections.get(from_port, {}) as Dictionary if connections.is_empty(): return - for to_node: String in connections: - if {to_node: connections[to_node]}.hash() == connection_hash: - (outgoing_connections[from_port] as Dictionary).erase(to_node) - break + var ports: Array = connections.get(to_node, []) as Array + if ports.is_empty(): + return + + ports.erase(to_port) outgoing_connection_removed.emit(from_port) diff --git a/graph_node_renderer/deck_renderer_graph_edit.gd b/graph_node_renderer/deck_renderer_graph_edit.gd index 628a692..f5fd5d7 100644 --- a/graph_node_renderer/deck_renderer_graph_edit.gd +++ b/graph_node_renderer/deck_renderer_graph_edit.gd @@ -119,7 +119,6 @@ func initialize_from_deck() -> void: ## Loops through all [DeckNode]s in [member Deck.nodes] and calls ## [method GraphEdit.connect_node] for all the connections that exist in each func refresh_connections() -> void: - print(deck.nodes.size()) for node_id in deck.nodes: var node: DeckNode = deck.nodes[node_id] var from_node: DeckNodeRendererGraphNode = get_children().filter( @@ -129,17 +128,18 @@ func refresh_connections() -> void: for from_port in node.outgoing_connections: for to_node_id: String in node.outgoing_connections[from_port]: - var to_node_port = node.outgoing_connections[from_port][to_node_id] + var to_node_ports = node.outgoing_connections[from_port][to_node_id] var to_node: DeckNodeRendererGraphNode = get_children().filter( func(c: DeckNodeRendererGraphNode): return c.node._id == to_node_id )[0] - connect_node( - from_node.name, - from_port, - to_node.name, - to_node_port - ) + for to_node_port: int in to_node_ports: + connect_node( + from_node.name, + from_port, + to_node.name, + to_node_port + ) ## Connected to [signal Deck.node_added], used to instance the required ## [DeckNodeRendererGraphNode] and set it's [member DeckNodeRenderGraphNode.position_offset]