diff options
author | RĂ©mi Verschelde <rverschelde@gmail.com> | 2017-03-18 10:45:29 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-18 10:45:29 +0100 |
commit | e55b7fa7d0dc1e980a27a8d900a34c2b253789a8 (patch) | |
tree | e7786498d6cff78dc3b9f0e84b5e40e8ca1df8c4 | |
parent | 3cf4103a89bf15af81bf6fd6fa1626423b718f5e (diff) | |
parent | 3b36df37302b40a399e6db2a9616cbf3ca17a705 (diff) |
Merge pull request #8030 from RandomShaper/fix-redundant-connections
Fix redundant connections saved in sub-inheritance
-rw-r--r-- | scene/resources/packed_scene.cpp | 47 | ||||
-rw-r--r-- | scene/resources/packed_scene.h | 2 |
2 files changed, 28 insertions, 21 deletions
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index e46d9db7bc..76c6543a2f 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -1516,34 +1516,41 @@ Array SceneState::get_connection_binds(int p_idx) const { return binds; } -bool SceneState::has_connection(const NodePath &p_node_from, const StringName &p_signal, const NodePath &p_node_to, const StringName &p_method) const { +bool SceneState::has_connection(const NodePath &p_node_from, const StringName &p_signal, const NodePath &p_node_to, const StringName &p_method) { - for (int i = 0; i < connections.size(); i++) { - const ConnectionData &c = connections[i]; + // this method cannot be const because of this + Ref<SceneState> ss = this; - NodePath np_from; + do { + for (int i = 0; i < ss->connections.size(); i++) { + const ConnectionData &c = ss->connections[i]; - if (c.from & FLAG_ID_IS_PATH) { - np_from = node_paths[c.from & FLAG_MASK]; - } else { - np_from = get_node_path(c.from); - } + NodePath np_from; - NodePath np_to; + if (c.from & FLAG_ID_IS_PATH) { + np_from = ss->node_paths[c.from & FLAG_MASK]; + } else { + np_from = ss->get_node_path(c.from); + } - if (c.to & FLAG_ID_IS_PATH) { - np_to = node_paths[c.to & FLAG_MASK]; - } else { - np_to = get_node_path(c.to); - } + NodePath np_to; - StringName sn_signal = names[c.signal]; - StringName sn_method = names[c.method]; + if (c.to & FLAG_ID_IS_PATH) { + np_to = ss->node_paths[c.to & FLAG_MASK]; + } else { + np_to = ss->get_node_path(c.to); + } - if (np_from == p_node_from && sn_signal == p_signal && np_to == p_node_to && sn_method == p_method) { - return true; + StringName sn_signal = ss->names[c.signal]; + StringName sn_method = ss->names[c.method]; + + if (np_from == p_node_from && sn_signal == p_signal && np_to == p_node_to && sn_method == p_method) { + return true; + } } - } + + ss = ss->_get_base_scene_state(); + } while (ss.is_valid()); return false; } diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h index b0e89205cb..fe451884f5 100644 --- a/scene/resources/packed_scene.h +++ b/scene/resources/packed_scene.h @@ -163,7 +163,7 @@ public: int get_connection_flags(int p_idx) const; Array get_connection_binds(int p_idx) const; - bool has_connection(const NodePath &p_node_from, const StringName &p_signal, const NodePath &p_node_to, const StringName &p_method) const; + bool has_connection(const NodePath &p_node_from, const StringName &p_signal, const NodePath &p_node_to, const StringName &p_method); Vector<NodePath> get_editable_instances() const; |