diff options
Diffstat (limited to 'core/node_path.cpp')
-rw-r--r-- | core/node_path.cpp | 81 |
1 files changed, 49 insertions, 32 deletions
diff --git a/core/node_path.cpp b/core/node_path.cpp index 15f950f605..a12152aca6 100644 --- a/core/node_path.cpp +++ b/core/node_path.cpp @@ -48,8 +48,6 @@ uint32_t NodePath::hash() const { h = h ^ ssn[i].hash(); } - h = h ^ data->property.hash(); - return h; } @@ -81,13 +79,6 @@ StringName NodePath::get_name(int p_idx) const { return data->path[p_idx]; } -StringName NodePath::get_property() const { - - if (!data) - return StringName(); - return data->property; -} - int NodePath::get_subname_count() const { if (!data) @@ -128,9 +119,6 @@ bool NodePath::operator==(const NodePath &p_path) const { if (data->subpath.size() != p_path.data->subpath.size()) return false; - if (data->property != p_path.data->property) - return false; - for (int i = 0; i < data->path.size(); i++) { if (data->path[i] != p_path.data->path[i]) @@ -184,8 +172,6 @@ NodePath::operator String() const { ret += ":" + data->subpath[i].operator String(); } - if (data->property.operator String() != "") - ret += ":" + String(data->property); return ret; } @@ -205,6 +191,7 @@ Vector<StringName> NodePath::get_names() const { return data->path; return Vector<StringName>(); } + Vector<StringName> NodePath::get_subnames() const { if (data) @@ -212,6 +199,21 @@ Vector<StringName> NodePath::get_subnames() const { return Vector<StringName>(); } +StringName NodePath::get_concatenated_subnames() const { + ERR_FAIL_COND_V(!data, StringName()); + + if (!data->concatenated_subpath) { + int spc = data->subpath.size(); + String concatenated; + const StringName *ssn = data->subpath.ptr(); + for (int i = 0; i < spc; i++) { + concatenated += i == 0 ? ssn[i].operator String() : ":" + ssn[i]; + } + data->concatenated_subpath = concatenated; + } + return data->concatenated_subpath; +} + NodePath NodePath::rel_path_to(const NodePath &p_np) const { ERR_FAIL_COND_V(!is_absolute(), NodePath()); @@ -250,10 +252,27 @@ NodePath NodePath::rel_path_to(const NodePath &p_np) const { if (relpath.size() == 0) relpath.push_back("."); - return NodePath(relpath, p_np.get_subnames(), false, p_np.get_property()); + return NodePath(relpath, p_np.get_subnames(), false); } -NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute, const String &p_property) { +NodePath NodePath::get_as_property_path() const { + + if (!data->path.size()) { + return *this; + } else { + Vector<StringName> new_path = data->subpath; + + String initial_subname = data->path[0]; + for (size_t i = 1; i < data->path.size(); i++) { + initial_subname += i == 0 ? data->path[i].operator String() : "/" + data->path[i]; + } + new_path.insert(0, initial_subname); + + return NodePath(Vector<StringName>(), new_path, false); + } +} + +NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) { data = NULL; @@ -264,14 +283,14 @@ NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute, const Stri data->refcount.init(); data->absolute = p_absolute; data->path = p_path; - data->property = p_property; + data->has_slashes = true; } -NodePath::NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p_subpath, bool p_absolute, const String &p_property) { +NodePath::NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p_subpath, bool p_absolute) { data = NULL; - if (p_path.size() == 0) + if (p_path.size() == 0 && p_subpath.size() == 0) return; data = memnew(Data); @@ -279,7 +298,7 @@ NodePath::NodePath(const Vector<StringName> &p_path, const Vector<StringName> &p data->absolute = p_absolute; data->path = p_path; data->subpath = p_subpath; - data->property = p_property; + data->has_slashes = true; } void NodePath::simplify() { @@ -320,11 +339,11 @@ NodePath::NodePath(const String &p_path) { return; String path = p_path; - StringName property; Vector<StringName> subpath; int absolute = (path[0] == '/') ? 1 : 0; bool last_is_slash = true; + bool has_slashes = false; int slices = 0; int subpath_pos = path.find(":"); @@ -337,16 +356,13 @@ NodePath::NodePath(const String &p_path) { if (path[i] == ':' || path[i] == 0) { String str = path.substr(from, i - from); - if (path[i] == ':') { - if (str == "") { - ERR_EXPLAIN("Invalid NodePath: " + p_path); - ERR_FAIL(); - } - subpath.push_back(str); - } else { - //property can be empty - property = str; + if (str == "") { + if (path[i] == 0) continue; // Allow end-of-path : + + ERR_EXPLAIN("Invalid NodePath: " + p_path); + ERR_FAIL(); } + subpath.push_back(str); from = i + 1; } @@ -360,6 +376,7 @@ NodePath::NodePath(const String &p_path) { if (path[i] == '/') { last_is_slash = true; + has_slashes = true; } else { if (last_is_slash) @@ -369,13 +386,13 @@ NodePath::NodePath(const String &p_path) { } } - if (slices == 0 && !absolute && !property) + if (slices == 0 && !absolute && !subpath.size()) return; data = memnew(Data); data->refcount.init(); data->absolute = absolute ? true : false; - data->property = property; + data->has_slashes = has_slashes; data->subpath = subpath; if (slices == 0) |