From 3bff8e27e652e237a9396ae7ce8e839be31a0805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Tue, 2 Jul 2024 09:29:06 +0000 Subject: [PATCH] make group io nodes 'optional' (#167) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://codeberg.org/StreamGraph/StreamGraph/pulls/167 Co-authored-by: Lera ElvoƩ Co-committed-by: Lera ElvoƩ --- classes/deck/deck.gd | 29 ++++++++++++++----- classes/deck/nodes/group/group_node.gd | 11 +++++++ .../deck_renderer_graph_edit.gd | 3 ++ 3 files changed, 36 insertions(+), 7 deletions(-) diff --git a/classes/deck/deck.gd b/classes/deck/deck.gd index 468c856..f9675c2 100644 --- a/classes/deck/deck.gd +++ b/classes/deck/deck.gd @@ -50,10 +50,6 @@ var _belonging_to: String = "" # for groups var group_input_node: String ## The ID of this group's input node. Used only if [member is_group] is [code]true[/code]. var group_output_node: String -## The ID of the group node this group is represented by, contained in this deck's parent deck. -## Used only if [member is_group] is [code]true[/code]. -## @experimental -#var group_node: String var emit_group_signals: bool = true var emit_node_added_signal: bool = true @@ -97,8 +93,17 @@ func add_node_type(type: String, assign_id: String = "", assign_to_self: bool = ## If [param assign_id] is empty, the node will get its' ID (re-)assigned. ## Otherwise, it will be assigned to be that value.[br] ## If [param assign_to_self] is [code]true[/code], the node's -## [member DeckNode._belonging_to] property will be set to [code]self[/code]. +## [member DeckNode._belonging_to] property will be set to [code]self[/code].[br] +## Returns [code]null[/code] if the node cannot be insantiated. func add_node_inst(node: DeckNode, assign_id: String = "", assign_to_self: bool = true) -> DeckNode: + if node.node_type == "group_input" and not group_input_node.is_empty(): + DeckHolder.logger.toast_error("Cannot add group input node, one already exists!") + node.free() + return null + if node.node_type == "group_output" and not group_output_node.is_empty(): + DeckHolder.logger.toast_error("Cannot add group output node, one already exists!") + node.free() + return null if assign_to_self: node._belonging_to = self #node._belonging_to_instance = instance_id @@ -113,9 +118,17 @@ func add_node_inst(node: DeckNode, assign_id: String = "", assign_to_self: bool if node.node_type == "group_input": group_input_node = node._id + node.about_to_free.connect( + func(): + group_input_node = "" + ) if node.node_type == "group_output": group_output_node = node._id + node.about_to_free.connect( + func(): + group_output_node = "" + ) if emit_node_added_signal: node_added.emit(node) @@ -702,8 +715,10 @@ static func from_dict(data: Dictionary, path: String = "") -> Deck: node.group_instance_id ) - group.get_node(node.input_node_id).group_node = node - group.get_node(node.output_node_id).group_node = node + if not node.input_node_id.is_empty(): + group.get_node(node.input_node_id).group_node = node + if not node.output_node_id.is_empty(): + group.get_node(node.output_node_id).group_node = node node.init_io() return deck diff --git a/classes/deck/nodes/group/group_node.gd b/classes/deck/nodes/group/group_node.gd index 2c02ad6..fe16f30 100644 --- a/classes/deck/nodes/group/group_node.gd +++ b/classes/deck/nodes/group/group_node.gd @@ -60,6 +60,17 @@ func init_io() -> void: input_node = group.get_node(input_node_id) output_node = group.get_node(output_node_id) + if input_node: + input_node.about_to_free.connect( + func(): + input_node_id = "" + ) + if output_node: + output_node.about_to_free.connect( + func(): + output_node_id = "" + ) + recalculate_ports() setup_connections() diff --git a/graph_node_renderer/deck_renderer_graph_edit.gd b/graph_node_renderer/deck_renderer_graph_edit.gd index 5197116..dda2e6f 100644 --- a/graph_node_renderer/deck_renderer_graph_edit.gd +++ b/graph_node_renderer/deck_renderer_graph_edit.gd @@ -344,6 +344,9 @@ func _on_add_node_menu_node_selected(type: String) -> void: # var node := NodeDB.instance_node(type) as DeckNode # deck.add_node_inst(node) var node := deck.add_node_type(type) + + if node == null: + return get_node_renderer(node).position_offset = node_pos else: