miggor-StreamGraph/classes/deck/nodes/group_node.gd

69 lines
1.6 KiB
GDScript3
Raw Normal View History

extends DeckNode
var group_id: String
var input_node: DeckNode
var output_node: DeckNode
var extra_ports: Array
func _init() -> void:
name = "Group"
node_type = "group_node"
props_to_serialize = [&"group_id", &"extra_ports"]
func _pre_connection() -> void:
for port_type: PortType in extra_ports:
var index_of_type: int
match port_type:
PortType.OUTPUT:
add_output_port(Deck.Types.STRING, "Output %s" % get_output_ports().size())
PortType.INPUT:
add_input_port(Deck.Types.STRING, "Input %s" % get_input_ports().size())
func init_io() -> void:
var group: Deck = _belonging_to.groups.get(group_id) as Deck
if !group:
return
input_node = group.get_node(group.group_input_node)
output_node = group.get_node(group.group_output_node)
recalculate_ports()
setup_connections()
func setup_connections() -> void:
input_node.ports_updated.connect(recalculate_ports)
output_node.ports_updated.connect(recalculate_ports)
func recalculate_ports() -> void:
ports.clear()
for output_port: Port in output_node.get_input_ports():
add_output_port(
Deck.Types.STRING,
"Output %s" % output_port.index
)
for input_port: Port in input_node.get_output_ports():
add_input_port(
Deck.Types.STRING,
"Input %s" % input_port.index
)
extra_ports.clear()
for port in ports:
extra_ports.append(port.port_type)
func _receive(to_input_port: int, data: DeckType, extra_data: Array = []):
input_node.send(get_input_ports()[to_input_port].index_of_type, data, extra_data)
func _value_request(from_port: int) -> Variant:
return output_node.request_value(from_port)