Allow for getting/setting indexed properties of objects using get/set_indexed
Performance is around the same as using pure set() through GDScript.
This commit is contained in:
@ -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,23 @@ 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->has_slashes || !data->path.size()) {
|
||||
return NodePath(Vector<StringName>(), data->subpath, false);
|
||||
} else {
|
||||
ERR_FAIL_COND_V(data->path.size() != 1, NodePath());
|
||||
|
||||
Vector<StringName> new_path = data->subpath;
|
||||
new_path.insert(0, data->path[0]);
|
||||
return NodePath(Vector<StringName>(), new_path, false);
|
||||
}
|
||||
}
|
||||
|
||||
NodePath::NodePath(const Vector<StringName> &p_path, bool p_absolute) {
|
||||
|
||||
data = NULL;
|
||||
|
||||
@ -264,14 +279,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 +294,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() {
|
||||
@ -325,6 +340,7 @@ NodePath::NodePath(const String &p_path) {
|
||||
|
||||
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 +353,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 +373,7 @@ NodePath::NodePath(const String &p_path) {
|
||||
if (path[i] == '/') {
|
||||
|
||||
last_is_slash = true;
|
||||
has_slashes = true;
|
||||
} else {
|
||||
|
||||
if (last_is_slash)
|
||||
@ -369,13 +383,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)
|
||||
|
||||
Reference in New Issue
Block a user