miggor-StreamGraph/classes/deck/deck_node.gd

58 lines
1.7 KiB
GDScript

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:
if outgoing_connections.get(from_port) == null:
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
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