2023-12-15 22:44:25 +01:00
|
|
|
# (c) 2023-present Eroax
|
|
|
|
# (c) 2023-present Yagich
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2023-11-22 05:26:11 +01:00
|
|
|
extends DeckNode
|
|
|
|
|
|
|
|
var group_id: String
|
2023-12-15 22:44:25 +01:00
|
|
|
var group_instance_id: String
|
2023-11-22 05:26:11 +01:00
|
|
|
var input_node: DeckNode
|
|
|
|
var output_node: DeckNode
|
|
|
|
|
2024-05-08 09:43:45 +02:00
|
|
|
var is_library: bool
|
|
|
|
|
2023-12-15 22:44:25 +01:00
|
|
|
var input_node_id: String
|
|
|
|
var output_node_id: String
|
|
|
|
|
2023-11-22 05:26:11 +01:00
|
|
|
var extra_ports: Array
|
2024-05-20 10:54:19 +02:00
|
|
|
var extra_port_values: Array:
|
|
|
|
get:
|
|
|
|
if extra_port_values.is_empty():
|
|
|
|
return get_all_ports().map(func(x: Port): return x.value)
|
|
|
|
else:
|
|
|
|
return extra_port_values
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _init() -> void:
|
|
|
|
name = "Group"
|
|
|
|
node_type = "group_node"
|
2024-05-20 10:54:19 +02:00
|
|
|
props_to_serialize = [
|
|
|
|
&"group_id",
|
|
|
|
&"group_instance_id",
|
|
|
|
&"extra_ports",
|
|
|
|
&"input_node_id",
|
|
|
|
&"output_node_id",
|
|
|
|
&"is_library",
|
|
|
|
&"extra_port_values",
|
|
|
|
]
|
2023-11-23 07:38:10 +01:00
|
|
|
appears_in_search = false
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
|
2024-05-20 06:32:12 +02:00
|
|
|
#func _pre_port_load() -> void:
|
|
|
|
#for port_type: PortType in extra_ports:
|
|
|
|
#match port_type:
|
|
|
|
#PortType.OUTPUT:
|
|
|
|
#add_output_port(DeckType.Types.ANY, "Output %s" % get_output_ports().size())
|
|
|
|
#PortType.INPUT:
|
|
|
|
#add_input_port(DeckType.Types.ANY, "Input %s" % get_input_ports().size())
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
func init_io() -> void:
|
2023-12-15 22:44:25 +01:00
|
|
|
#var group: Deck = _belonging_to.groups.get(group_id) as Deck
|
|
|
|
var group := DeckHolder.get_group_instance(group_id, group_instance_id)
|
2024-02-21 07:11:29 +01:00
|
|
|
if not group:
|
2023-11-22 05:26:11 +01:00
|
|
|
return
|
|
|
|
|
2024-02-21 07:11:29 +01:00
|
|
|
if input_node and input_node.ports_updated.is_connected(recalculate_ports):
|
2023-12-15 22:44:25 +01:00
|
|
|
input_node.ports_updated.disconnect(recalculate_ports)
|
2024-02-21 07:11:29 +01:00
|
|
|
if output_node and output_node.ports_updated.is_connected(recalculate_ports):
|
2023-12-15 22:44:25 +01:00
|
|
|
output_node.ports_updated.disconnect(recalculate_ports)
|
|
|
|
|
2024-05-08 09:43:45 +02:00
|
|
|
input_node = group.get_node(input_node_id)
|
|
|
|
output_node = group.get_node(output_node_id)
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
recalculate_ports()
|
|
|
|
setup_connections()
|
|
|
|
|
|
|
|
|
2024-04-11 16:56:33 +02:00
|
|
|
func make_unique() -> Deck:
|
|
|
|
return DeckHolder.make_group_instance_unique(group_id, group_instance_id, _belonging_to.id, _id)
|
|
|
|
|
|
|
|
|
2023-11-22 05:26:11 +01:00
|
|
|
func setup_connections() -> void:
|
|
|
|
input_node.ports_updated.connect(recalculate_ports)
|
|
|
|
output_node.ports_updated.connect(recalculate_ports)
|
|
|
|
|
|
|
|
|
|
|
|
func recalculate_ports() -> void:
|
2024-05-20 10:54:19 +02:00
|
|
|
var _values := extra_port_values.duplicate()
|
2023-11-22 05:26:11 +01:00
|
|
|
ports.clear()
|
|
|
|
|
|
|
|
for output_port: Port in output_node.get_input_ports():
|
2024-05-20 10:54:19 +02:00
|
|
|
var port := add_output_port(
|
2024-05-20 06:32:12 +02:00
|
|
|
output_port.type,
|
|
|
|
output_port.label,
|
|
|
|
output_port.descriptor,
|
|
|
|
output_port.usage_type,
|
2023-11-22 05:26:11 +01:00
|
|
|
)
|
2024-05-20 10:54:19 +02:00
|
|
|
if _values.size() - 1 < port.index:
|
|
|
|
continue
|
|
|
|
|
|
|
|
port.set_value(_values[port.index])
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
for input_port: Port in input_node.get_output_ports():
|
2024-05-20 10:54:19 +02:00
|
|
|
var port := add_input_port(
|
2024-05-20 06:32:12 +02:00
|
|
|
input_port.type,
|
|
|
|
input_port.label,
|
|
|
|
input_port.descriptor,
|
|
|
|
input_port.usage_type,
|
2023-11-22 05:26:11 +01:00
|
|
|
)
|
2024-05-20 10:54:19 +02:00
|
|
|
if _values.size() - 1 < port.index:
|
|
|
|
continue
|
|
|
|
|
|
|
|
port.set_value(_values[port.index])
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
extra_ports.clear()
|
2024-05-20 10:54:19 +02:00
|
|
|
extra_port_values.clear()
|
2023-11-22 05:26:11 +01:00
|
|
|
for port in ports:
|
|
|
|
extra_ports.append(port.port_type)
|
|
|
|
|
|
|
|
|
2024-02-22 08:23:25 +01:00
|
|
|
func _receive(to_input_port: int, data: Variant):
|
2024-05-08 09:43:45 +02:00
|
|
|
# var i = DeckHolder.get_group_instance(group_id, group_instance_id).get_node(input_node_id)
|
2024-04-11 16:56:33 +02:00
|
|
|
#i.send(get_input_ports()[to_input_port].index_of_type, data)
|
2024-02-22 08:23:25 +01:00
|
|
|
input_node.send(get_input_ports()[to_input_port].index_of_type, data)
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
func _value_request(from_port: int) -> Variant:
|
2024-01-25 08:20:41 +01:00
|
|
|
return await output_node.request_value_async(from_port)
|