2023-06-10 19:13:16 +02:00
|
|
|
class_name DeckNode
|
|
|
|
|
|
|
|
var name: String
|
|
|
|
var input_ports: Array[Port]
|
|
|
|
var output_ports: Array[Port]
|
|
|
|
var outgoing_connections: Dictionary
|
|
|
|
|
|
|
|
var _belonging_to: Deck
|
|
|
|
var _id: String
|
|
|
|
|
|
|
|
|
|
|
|
func add_input_port(type: Deck.Types, label: String, descriptor: String = "") -> void:
|
|
|
|
var port := Port.new(type, label, descriptor)
|
|
|
|
input_ports.append(port)
|
|
|
|
|
|
|
|
|
|
|
|
func add_output_port(type: Deck.Types, label: String, descriptor: String = "") -> void:
|
|
|
|
var port := Port.new(type, label, descriptor)
|
|
|
|
output_ports.append(port)
|
|
|
|
|
|
|
|
|
|
|
|
func send(from_port: int, data: DeckType, extra_data: Array = []) -> void:
|
2023-06-11 17:39:11 +02:00
|
|
|
if outgoing_connections.get(from_port) == null:
|
2023-06-10 19:13:16 +02:00
|
|
|
return
|
|
|
|
|
|
|
|
for connection in outgoing_connections[from_port]:
|
|
|
|
connection = connection as Dictionary
|
|
|
|
# key is node uuid
|
|
|
|
# value is input port on destination node
|
|
|
|
for node in connection:
|
|
|
|
_belonging_to.get_node(node)._receive(connection[node], data, extra_data)
|
|
|
|
|
|
|
|
|
|
|
|
func _receive(to_port: int, data: DeckType, extra_data: Array = []) -> void:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
func add_outgoing_connection(from_port: int, to_node: String, to_port: int) -> void:
|
|
|
|
var port_connections: Array = outgoing_connections.get(from_port, [])
|
|
|
|
port_connections.append({to_node: to_port})
|
|
|
|
outgoing_connections[from_port] = port_connections
|
2023-06-11 18:26:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
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
|