mirror of
https://codeberg.org/StreamGraph/StreamGraph.git
synced 2024-11-13 19:49:55 +01:00
a518e46b0f
closes #97 when copying group nodes across decks (including in and out of groups), they become unique and completely independent copies of the original. this is done recursively, so in the case of copying: - group X - contained in Deck A - has another group Z into Deck B, group X will become group Y, group Z will become group W. there is a rare bug that will sometimes cause the deck to save with no groups at all, which i haven't been able to hunt down and don't know how to replicate at the moment. Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/143 Co-authored-by: Lera Elvoé <yagich@poto.cafe> Co-committed-by: Lera Elvoé <yagich@poto.cafe>
87 lines
2.4 KiB
GDScript
87 lines
2.4 KiB
GDScript
# (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)
|
|
extends DeckNode
|
|
|
|
var group_id: String
|
|
var group_instance_id: String
|
|
var input_node: DeckNode
|
|
var output_node: DeckNode
|
|
|
|
var input_node_id: String
|
|
var output_node_id: String
|
|
|
|
var extra_ports: Array
|
|
|
|
|
|
func _init() -> void:
|
|
name = "Group"
|
|
node_type = "group_node"
|
|
props_to_serialize = [&"group_id", &"group_instance_id", &"extra_ports", &"input_node_id", &"output_node_id"]
|
|
appears_in_search = false
|
|
|
|
|
|
func _pre_connection() -> 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())
|
|
|
|
|
|
func init_io() -> void:
|
|
#var group: Deck = _belonging_to.groups.get(group_id) as Deck
|
|
var group := DeckHolder.get_group_instance(group_id, group_instance_id)
|
|
if not group:
|
|
return
|
|
|
|
if input_node and input_node.ports_updated.is_connected(recalculate_ports):
|
|
input_node.ports_updated.disconnect(recalculate_ports)
|
|
if output_node and output_node.ports_updated.is_connected(recalculate_ports):
|
|
output_node.ports_updated.disconnect(recalculate_ports)
|
|
|
|
input_node = group.get_node(group.group_input_node)
|
|
output_node = group.get_node(group.group_output_node)
|
|
|
|
recalculate_ports()
|
|
setup_connections()
|
|
|
|
|
|
func make_unique() -> Deck:
|
|
return DeckHolder.make_group_instance_unique(group_id, group_instance_id, _belonging_to.id, _id)
|
|
|
|
|
|
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(
|
|
DeckType.Types.ANY,
|
|
"Output %s" % output_port.index
|
|
)
|
|
|
|
for input_port: Port in input_node.get_output_ports():
|
|
add_input_port(
|
|
DeckType.Types.ANY,
|
|
"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: Variant):
|
|
var i = DeckHolder.get_group_instance(group_id, group_instance_id).get_node(input_node_id)
|
|
#i.send(get_input_ports()[to_input_port].index_of_type, data)
|
|
input_node.send(get_input_ports()[to_input_port].index_of_type, data)
|
|
|
|
|
|
func _value_request(from_port: int) -> Variant:
|
|
return await output_node.request_value_async(from_port)
|