From b92bc43a6bd5fb5c366e15fb4537ee6544470c39 Mon Sep 17 00:00:00 2001 From: Chris Cranford Date: Sat, 3 Aug 2024 13:25:31 -0400 Subject: [PATCH] GH-647 Store/Cache/Sync knots correctly on pin disconnects --- src/editor/graph/graph_edit.cpp | 10 ++++++++++ src/editor/graph/graph_edit.h | 4 ++++ src/script/graph.cpp | 5 +++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/editor/graph/graph_edit.cpp b/src/editor/graph/graph_edit.cpp index d8989787..7d450f70 100644 --- a/src/editor/graph/graph_edit.cpp +++ b/src/editor/graph/graph_edit.cpp @@ -218,6 +218,7 @@ void OrchestratorGraphEdit::_notification(int p_what) _script_graph->connect("node_added", callable_mp(this, &OrchestratorGraphEdit::_on_graph_node_added)); _script_graph->connect("node_removed", callable_mp(this, &OrchestratorGraphEdit::_on_graph_node_removed)); _script_graph->connect("knots_updated", callable_mp(this, &OrchestratorGraphEdit::_synchronize_graph_knots)); + _script_graph->connect("connection_knots_removed", callable_mp(this, &OrchestratorGraphEdit::_remove_connection_knots)); // Wire up action menu _action_menu->connect("canceled", callable_mp(this, &OrchestratorGraphEdit::_on_action_menu_cancelled)); @@ -1120,6 +1121,15 @@ void OrchestratorGraphEdit::_synchronize_graph_knots() } } +void OrchestratorGraphEdit::_remove_connection_knots(uint64_t p_connection_id) +{ + if (_knots.erase(p_connection_id)) + { + _store_connection_knots(); + _synchronize_graph_knots(); + } +} + void OrchestratorGraphEdit::_synchronize_graph_node(Ref p_node) { if (!p_node.is_valid()) diff --git a/src/editor/graph/graph_edit.h b/src/editor/graph/graph_edit.h index 1ffc4b5e..7b8be7b9 100644 --- a/src/editor/graph/graph_edit.h +++ b/src/editor/graph/graph_edit.h @@ -329,6 +329,10 @@ class OrchestratorGraphEdit : public GraphEdit /// Synchronizes the graph knots void _synchronize_graph_knots(); + /// Remove all knots related to the specific connection id + /// @param p_connection_id + void _remove_connection_knots(uint64_t p_connection_id); + /// Updates only the specific graph node /// @param p_node the node to update. void _synchronize_graph_node(Ref p_node); diff --git a/src/script/graph.cpp b/src/script/graph.cpp index 1eaedf39..cec97ec0 100644 --- a/src/script/graph.cpp +++ b/src/script/graph.cpp @@ -64,6 +64,7 @@ void OScriptGraph::_bind_methods() ADD_SIGNAL(MethodInfo("node_added", PropertyInfo(Variant::INT, "node_id"))); ADD_SIGNAL(MethodInfo("node_removed", PropertyInfo(Variant::INT, "node_id"))); ADD_SIGNAL(MethodInfo("knots_updated")); + ADD_SIGNAL(MethodInfo("connection_knots_removed", PropertyInfo(Variant::INT, "connection_id"))); } TypedArray OScriptGraph::_get_nodes() const @@ -426,8 +427,8 @@ void OScriptGraph::set_knots(const HashMap& p_knot void OScriptGraph::remove_connection_knot(uint64_t p_connection_id) { - _knots.erase(p_connection_id); - emit_signal("knots_updated"); + if (_knots.erase(p_connection_id)) + emit_signal("connection_knots_removed", p_connection_id); } Ref OScriptGraph::create_node(const StringName& p_type, const OScriptNodeInitContext& p_context, const Vector2& p_position)