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 output_count: int:
|
|
|
|
get:
|
2024-05-08 09:43:45 +02:00
|
|
|
if output_count == 0:
|
|
|
|
return get_all_ports().size()
|
|
|
|
else:
|
|
|
|
return output_count
|
2023-11-22 05:26:11 +01:00
|
|
|
|
2023-12-15 22:44:25 +01:00
|
|
|
var group_node: DeckNode
|
|
|
|
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
func _init() -> void:
|
|
|
|
name = "Group input"
|
|
|
|
node_type = "group_input"
|
|
|
|
props_to_serialize = [&"output_count"]
|
2024-05-08 09:43:45 +02:00
|
|
|
# appears_in_search = false
|
|
|
|
# user_can_delete = false
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
add_output_port(
|
2023-11-26 23:07:15 +01:00
|
|
|
DeckType.Types.ANY,
|
2023-11-22 05:26:11 +01:00
|
|
|
"Input 0"
|
|
|
|
)
|
|
|
|
outgoing_connection_added.connect(_on_outgoing_connection_added)
|
|
|
|
outgoing_connection_removed.connect(_on_outgoing_connection_removed)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_outgoing_connection_added(port_idx: int) -> void:
|
|
|
|
if port_idx + 1 < get_all_ports().size():
|
|
|
|
return
|
|
|
|
|
|
|
|
add_output_port(
|
2023-11-26 23:07:15 +01:00
|
|
|
DeckType.Types.ANY,
|
2023-11-22 05:26:11 +01:00
|
|
|
"Input %s" % (get_all_ports().size())
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func _on_outgoing_connection_removed(port_idx: int) -> void:
|
|
|
|
var last_connected_port := 0
|
2024-04-17 02:24:55 +02:00
|
|
|
var outgoing_connections = _belonging_to.connections.get_all_outgoing_connections(_id)
|
|
|
|
for port: int in outgoing_connections:
|
|
|
|
if not (outgoing_connections[port] as Array).is_empty():
|
2023-11-22 05:26:11 +01:00
|
|
|
last_connected_port = port
|
2023-12-15 22:44:25 +01:00
|
|
|
#prints("l:", last_connected_port, "p:", port_idx)
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
if port_idx < last_connected_port:
|
|
|
|
return
|
|
|
|
|
|
|
|
var s := get_all_ports().slice(0, last_connected_port + 2)
|
|
|
|
ports.assign(s)
|
|
|
|
ports_updated.emit()
|
|
|
|
|
|
|
|
|
2024-04-17 02:24:55 +02:00
|
|
|
func _pre_port_load() -> void:
|
2024-05-20 06:32:12 +02:00
|
|
|
ports.clear()
|
2024-05-08 09:43:45 +02:00
|
|
|
for i in output_count:
|
2023-11-22 05:26:11 +01:00
|
|
|
add_output_port(
|
2023-11-26 23:07:15 +01:00
|
|
|
DeckType.Types.ANY,
|
2024-05-20 06:32:12 +02:00
|
|
|
"Input %s" % i
|
2023-11-22 05:26:11 +01:00
|
|
|
)
|
2024-05-08 09:43:45 +02:00
|
|
|
output_count = 0
|
2023-11-22 05:26:11 +01:00
|
|
|
|
|
|
|
|
2024-04-17 04:06:48 +02:00
|
|
|
func _post_load(connections: Deck.NodeConnections) -> void:
|
2023-11-22 05:26:11 +01:00
|
|
|
# ensure we have enough ports after connections
|
2024-05-20 06:32:12 +02:00
|
|
|
var last_connected_port := -1
|
2024-04-17 04:06:48 +02:00
|
|
|
var outgoing_connections = connections.get_all_outgoing_connections(_id)
|
2023-11-22 05:26:11 +01:00
|
|
|
for port: int in outgoing_connections:
|
|
|
|
last_connected_port = port if outgoing_connections.has(port) else last_connected_port
|
|
|
|
|
2024-05-20 06:32:12 +02:00
|
|
|
if last_connected_port == -1:
|
|
|
|
return
|
|
|
|
|
2023-11-22 05:26:11 +01:00
|
|
|
if ports.size() <= last_connected_port:
|
|
|
|
for i in last_connected_port:
|
|
|
|
add_output_port(
|
2023-11-26 23:07:15 +01:00
|
|
|
DeckType.Types.ANY,
|
2023-11-22 05:26:11 +01:00
|
|
|
"Input %s" % get_output_ports().size()
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-05-20 06:32:12 +02:00
|
|
|
func _post_deck_load() -> void:
|
|
|
|
for port in get_output_ports():
|
|
|
|
var gp := _belonging_to.group_descriptors.get_input_port(port.index_of_type)
|
|
|
|
if gp.is_empty():
|
|
|
|
continue
|
2024-05-20 10:54:19 +02:00
|
|
|
port.label = gp.label if not gp.label.is_empty() else "Input %s" % port.index
|
2024-05-20 06:32:12 +02:00
|
|
|
port.descriptor = gp.descriptor
|
|
|
|
port.type = gp.type
|
|
|
|
port.usage_type = gp.usage_type
|
|
|
|
|
|
|
|
|
2023-11-22 05:26:11 +01:00
|
|
|
func _value_request(from_port: int) -> Variant:
|
2024-05-08 09:43:45 +02:00
|
|
|
if group_node:
|
2024-05-20 07:25:34 +02:00
|
|
|
return await group_node.resolve_input_port_value_async(group_node.get_input_ports()[from_port].index_of_type)
|
|
|
|
#return await group_node.request_value_async(group_node.get_input_ports()[from_port].index_of_type)
|
2024-05-08 09:43:45 +02:00
|
|
|
else:
|
|
|
|
return null
|