2023-11-22 05:26:11 +01:00
|
|
|
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"]
|
2023-11-23 07:38:10 +01:00
|
|
|
appears_in_search = false
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _pre_connection() -> void:
|
|
|
|
for port_type: PortType in extra_ports:
|
|
|
|
match port_type:
|
|
|
|
PortType.OUTPUT:
|
2023-11-26 23:07:15 +01:00
|
|
|
add_output_port(DeckType.Types.ANY, "Output %s" % get_output_ports().size())
|
2023-11-22 05:26:11 +01:00
|
|
|
PortType.INPUT:
|
2023-11-26 23:07:15 +01:00
|
|
|
add_input_port(DeckType.Types.ANY, "Input %s" % get_input_ports().size())
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
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(
|
2023-11-26 23:07:15 +01:00
|
|
|
DeckType.Types.ANY,
|
2023-11-22 05:26:11 +01:00
|
|
|
"Output %s" % output_port.index
|
|
|
|
)
|
|
|
|
|
|
|
|
for input_port: Port in input_node.get_output_ports():
|
|
|
|
add_input_port(
|
2023-11-26 23:07:15 +01:00
|
|
|
DeckType.Types.ANY,
|
2023-11-22 05:26:11 +01:00
|
|
|
"Input %s" % input_port.index
|
|
|
|
)
|
|
|
|
|
|
|
|
extra_ports.clear()
|
|
|
|
for port in ports:
|
|
|
|
extra_ports.append(port.port_type)
|
|
|
|
|
|
|
|
|
2023-11-26 23:07:15 +01:00
|
|
|
func _receive(to_input_port: int, data: Variant, extra_data: Array = []):
|
2023-11-22 05:26:11 +01:00
|
|
|
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)
|