Skip to content

Commit

Permalink
GH-647 Store/Cache/Sync knots correctly on pin disconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Aug 3, 2024
1 parent fd0a66d commit b92bc43
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/editor/graph/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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<OScriptNode> p_node)
{
if (!p_node.is_valid())
Expand Down
4 changes: 4 additions & 0 deletions src/editor/graph/graph_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<OScriptNode> p_node);
Expand Down
5 changes: 3 additions & 2 deletions src/script/graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> OScriptGraph::_get_nodes() const
Expand Down Expand Up @@ -426,8 +427,8 @@ void OScriptGraph::set_knots(const HashMap<uint64_t, PackedVector2Array>& 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<OScriptNode> OScriptGraph::create_node(const StringName& p_type, const OScriptNodeInitContext& p_context, const Vector2& p_position)
Expand Down

0 comments on commit b92bc43

Please sign in to comment.