From 802749704f0460df0a9f80c3873145a8fd1d461b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lera=20Elvo=C3=A9?= Date: Fri, 8 Dec 2023 11:22:02 +0300 Subject: [PATCH] sync node renames and position in group instances --- classes/deck/deck.gd | 16 +++++++- classes/deck/deck_holder.gd | 38 ++++++++++++++++--- classes/deck/deck_node.gd | 7 ++++ .../deck_node_renderer_graph_node.gd | 8 +++- .../deck_renderer_graph_edit.gd | 2 +- 5 files changed, 62 insertions(+), 9 deletions(-) diff --git a/classes/deck/deck.gd b/classes/deck/deck.gd index 5f19b37..05c000f 100644 --- a/classes/deck/deck.gd +++ b/classes/deck/deck.gd @@ -45,6 +45,8 @@ signal node_removed_from_group(node_id: String, remove_connections: bool, deck: signal nodes_connected_in_group(from_node_id: String, to_node_id: String, from_output_port: int, to_input_port: int, deck: Deck) signal nodes_disconnected_in_group(from_node_id: String, to_node_id: String, from_output_port: int, to_input_port: int, deck: Deck) signal node_port_value_updated(node_id: String, port_idx: int, new_value: Variant, deck: Deck) +signal node_renamed(node_id: String, new_name: String, deck: Deck) +signal node_moved(node_id: String, new_position: Dictionary, deck: Deck) #endregion ## Instantiate a node by its' [member DeckNode.node_type] and add it to this deck.[br] @@ -80,7 +82,19 @@ func add_node_inst(node: DeckNode, assign_id: String = "", assign_to_self: bool func(port_idx: int, new_value: Variant): if is_group && emit_group_signals: node_port_value_updated.emit(node._id, port_idx, new_value, self) - ) + ) + + node.renamed.connect( + func(new_name: String): + if is_group && emit_group_signals: + node_renamed.emit(node._id, new_name, self) + ) + + node.position_updated.connect( + func(new_position: Dictionary): + if is_group && emit_group_signals: + node_moved.emit(node._id, new_position, self) + ) return node diff --git a/classes/deck/deck_holder.gd b/classes/deck/deck_holder.gd index b5ef9fb..b0b1688 100644 --- a/classes/deck/deck_holder.gd +++ b/classes/deck/deck_holder.gd @@ -41,11 +41,7 @@ static func add_group_from_dict(data: Dictionary, deck_id: String, instance_id: var instances: Dictionary = decks.get(deck_id, {}) instances[instance_id] = group decks[deck_id] = instances - group.node_added_to_group.connect(DeckHolder._on_node_added_to_group) - group.node_removed_from_group.connect(DeckHolder._on_node_removed_from_group) - group.nodes_connected_in_group.connect(DeckHolder._on_nodes_connected_in_group) - group.nodes_disconnected_in_group.connect(DeckHolder._on_nodes_disconnected_in_group) - group.node_port_value_updated.connect(DeckHolder._on_node_port_value_updated) + connect_group_signals(group) return group @@ -61,12 +57,18 @@ static func add_empty_group() -> Deck: group.id = UUID.v4() group.instance_id = UUID.v4() decks[group.id] = {group.instance_id: group} + connect_group_signals(group) + return group + + +static func connect_group_signals(group: Deck) -> void: group.node_added_to_group.connect(DeckHolder._on_node_added_to_group) group.node_removed_from_group.connect(DeckHolder._on_node_removed_from_group) group.nodes_connected_in_group.connect(DeckHolder._on_nodes_connected_in_group) group.nodes_disconnected_in_group.connect(DeckHolder._on_nodes_disconnected_in_group) group.node_port_value_updated.connect(DeckHolder._on_node_port_value_updated) - return group + group.node_renamed.connect(DeckHolder._on_node_renamed) + group.node_moved.connect(DeckHolder._on_node_moved) static func get_deck(id: String) -> Deck: @@ -172,4 +174,28 @@ static func _on_node_port_value_updated(node_id: String, port_idx: int, new_valu instance.get_node(node_id).get_all_ports()[port_idx].set_value_no_signal(new_value) instance.emit_group_signals = true + +static func _on_node_renamed(node_id: String, new_name: String, deck: Deck) -> void: + var group_id := deck.id + for instance_id: String in decks[group_id]: + if instance_id == deck.instance_id: + continue + + var instance: Deck = get_group_instance(group_id, instance_id) + instance.emit_group_signals = false + instance.get_node(node_id).name = new_name + instance.emit_group_signals = true + + +static func _on_node_moved(node_id: String, new_position: Dictionary, deck: Deck) -> void: + var group_id := deck.id + for instance_id: String in decks[group_id]: + if instance_id == deck.instance_id: + continue + + var instance: Deck = get_group_instance(group_id, instance_id) + instance.emit_group_signals = false + instance.get_node(node_id).position = new_position.duplicate() + instance.emit_group_signals = true + #endregion diff --git a/classes/deck/deck_node.gd b/classes/deck/deck_node.gd index 74ae61b..16aad1a 100644 --- a/classes/deck/deck_node.gd +++ b/classes/deck/deck_node.gd @@ -66,6 +66,8 @@ signal incoming_connection_removed(from_port: int) signal port_value_updated(port_idx: int, new_value: Variant) +signal renamed(new_name: String) + ## Add an input port to this node. Usually only used at initialization. func add_input_port(type: DeckType.Types, label: String, descriptor: String = "") -> void: @@ -193,6 +195,11 @@ func remove_incoming_connection(to_port: int) -> void: incoming_connection_removed.emit(to_port) +func rename(new_name: String) -> void: + name = new_name + renamed.emit(new_name) + + @warning_ignore("unused_parameter") func _event_received(event_name: StringName, event_data: Dictionary = {}) -> void: pass diff --git a/graph_node_renderer/deck_node_renderer_graph_node.gd b/graph_node_renderer/deck_node_renderer_graph_node.gd index 0d690bc..a79f2d0 100644 --- a/graph_node_renderer/deck_node_renderer_graph_node.gd +++ b/graph_node_renderer/deck_node_renderer_graph_node.gd @@ -18,12 +18,14 @@ func _ready() -> void: for port in node.get_all_ports(): update_port(port) position_offset_changed.connect(_on_position_offset_changed) + node.renamed.connect(_on_node_renamed) ## Connected to [signal GraphElement.position_offset_updated] and updates the ## [member node]s properties func _on_position_offset_changed() -> void: node.position.x = position_offset.x node.position.y = position_offset.y + node.position_updated.emit(node.position) ## Connected to [member node]s [signal position_updated] to keep parity with the ## data position. @@ -32,7 +34,7 @@ func _on_node_position_updated(new_position: Dictionary) -> void: position_offset.x = new_position.x position_offset.y = new_position.y position_offset_changed.connect(_on_position_offset_changed) - print("PO: ", position_offset) + ## Connected to [member node]s [signal port_added] handles setting up the specified ## [member Port.descriptor] with it's required nodes/signals etc. + adding the port @@ -68,6 +70,10 @@ func _on_node_ports_updated() -> void: update_port(port) +func _on_node_renamed(new_name: String) -> void: + title = new_name + + func update_port(port: Port) -> void: var descriptor_split := port.descriptor.split(":") match descriptor_split[0]: diff --git a/graph_node_renderer/deck_renderer_graph_edit.gd b/graph_node_renderer/deck_renderer_graph_edit.gd index 113e9b9..fa75e69 100644 --- a/graph_node_renderer/deck_renderer_graph_edit.gd +++ b/graph_node_renderer/deck_renderer_graph_edit.gd @@ -211,7 +211,7 @@ func _input(event: InputEvent) -> void: func _on_rename_popup_rename_confirmed(new_name: String) -> void: var node: DeckNodeRendererGraphNode = get_selected_nodes()[0] node.title = new_name - node.node.name = new_name + node.node.rename(new_name) func _on_rename_popup_closed() -> void: