sync node renames and position in group instances

This commit is contained in:
Lera Elvoé 2023-12-08 11:22:02 +03:00
parent b2d96a471e
commit 802749704f
No known key found for this signature in database
5 changed files with 62 additions and 9 deletions

View file

@ -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_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 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_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 #endregion
## Instantiate a node by its' [member DeckNode.node_type] and add it to this deck.[br] ## 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): func(port_idx: int, new_value: Variant):
if is_group && emit_group_signals: if is_group && emit_group_signals:
node_port_value_updated.emit(node._id, port_idx, new_value, self) 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 return node

View file

@ -41,11 +41,7 @@ static func add_group_from_dict(data: Dictionary, deck_id: String, instance_id:
var instances: Dictionary = decks.get(deck_id, {}) var instances: Dictionary = decks.get(deck_id, {})
instances[instance_id] = group instances[instance_id] = group
decks[deck_id] = instances decks[deck_id] = instances
group.node_added_to_group.connect(DeckHolder._on_node_added_to_group) connect_group_signals(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 return group
@ -61,12 +57,18 @@ static func add_empty_group() -> Deck:
group.id = UUID.v4() group.id = UUID.v4()
group.instance_id = UUID.v4() group.instance_id = UUID.v4()
decks[group.id] = {group.instance_id: group} 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_added_to_group.connect(DeckHolder._on_node_added_to_group)
group.node_removed_from_group.connect(DeckHolder._on_node_removed_from_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_connected_in_group.connect(DeckHolder._on_nodes_connected_in_group)
group.nodes_disconnected_in_group.connect(DeckHolder._on_nodes_disconnected_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) 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: 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.get_node(node_id).get_all_ports()[port_idx].set_value_no_signal(new_value)
instance.emit_group_signals = true 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 #endregion

View file

@ -66,6 +66,8 @@ signal incoming_connection_removed(from_port: int)
signal port_value_updated(port_idx: int, new_value: Variant) 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. ## Add an input port to this node. Usually only used at initialization.
func add_input_port(type: DeckType.Types, label: String, descriptor: String = "") -> void: 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) incoming_connection_removed.emit(to_port)
func rename(new_name: String) -> void:
name = new_name
renamed.emit(new_name)
@warning_ignore("unused_parameter") @warning_ignore("unused_parameter")
func _event_received(event_name: StringName, event_data: Dictionary = {}) -> void: func _event_received(event_name: StringName, event_data: Dictionary = {}) -> void:
pass pass

View file

@ -18,12 +18,14 @@ func _ready() -> void:
for port in node.get_all_ports(): for port in node.get_all_ports():
update_port(port) update_port(port)
position_offset_changed.connect(_on_position_offset_changed) position_offset_changed.connect(_on_position_offset_changed)
node.renamed.connect(_on_node_renamed)
## Connected to [signal GraphElement.position_offset_updated] and updates the ## Connected to [signal GraphElement.position_offset_updated] and updates the
## [member node]s properties ## [member node]s properties
func _on_position_offset_changed() -> void: func _on_position_offset_changed() -> void:
node.position.x = position_offset.x node.position.x = position_offset.x
node.position.y = position_offset.y 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 ## Connected to [member node]s [signal position_updated] to keep parity with the
## data position. ## data position.
@ -32,7 +34,7 @@ func _on_node_position_updated(new_position: Dictionary) -> void:
position_offset.x = new_position.x position_offset.x = new_position.x
position_offset.y = new_position.y position_offset.y = new_position.y
position_offset_changed.connect(_on_position_offset_changed) 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 ## 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 ## [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) update_port(port)
func _on_node_renamed(new_name: String) -> void:
title = new_name
func update_port(port: Port) -> void: func update_port(port: Port) -> void:
var descriptor_split := port.descriptor.split(":") var descriptor_split := port.descriptor.split(":")
match descriptor_split[0]: match descriptor_split[0]:

View file

@ -211,7 +211,7 @@ func _input(event: InputEvent) -> void:
func _on_rename_popup_rename_confirmed(new_name: String) -> void: func _on_rename_popup_rename_confirmed(new_name: String) -> void:
var node: DeckNodeRendererGraphNode = get_selected_nodes()[0] var node: DeckNodeRendererGraphNode = get_selected_nodes()[0]
node.title = new_name node.title = new_name
node.node.name = new_name node.node.rename(new_name)
func _on_rename_popup_closed() -> void: func _on_rename_popup_closed() -> void: