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
|
|
|
|
|
|
|
|
|
|
|
|
func _init() -> void:
|
|
|
|
name = "Group"
|
|
|
|
node_type = "group_node"
|
2024-05-08 09:43:45 +02:00
|
|
|
props_to_serialize = [&"group_id", &"group_instance_id", &"extra_ports", &"input_node_id", &"output_node_id", &"is_library"]
|
2023-11-23 07:38:10 +01:00
|
|
|
appears_in_search = false
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
|
2024-04-17 02:24:55 +02:00
|
|
|
func _pre_port_load() -> void:
|
2023-11-22 05:26:11 +01:00
|
|
|
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:
|
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:
|
|
|
|
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)
|
|
|
|
|
|
|
|
|
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)
|