Fix regression with dictionaries because of the variant srtingname support.

This commit is contained in:
Relintai 2022-03-21 23:22:19 +01:00
parent 8273710235
commit fd20cdfb0f

View File

@ -2001,8 +2001,28 @@ Variant Variant::get_named(const StringName &p_index, bool *r_valid) const {
return obj->get(p_index, r_valid);
} break;
case DICTIONARY: {
const Dictionary *dic = reinterpret_cast<const Dictionary *>(_data._mem);
const Variant *res = dic->getptr(p_index);
if (!res) {
// Backwards compatibility for before variants supported stringnames.
const Variant *res2 = dic->getptr(p_index.operator String());
if (res2) {
if (r_valid) {
*r_valid = true;
}
return *res2;
}
} else {
if (r_valid) {
*r_valid = true;
}
return *res;
}
} break;
default: {
return get(p_index, r_valid);
return get(p_index.operator String(), r_valid);
}
}
@ -2783,7 +2803,6 @@ void Variant::set(const Variant &p_index, const Variant &p_value, bool *r_valid)
valid = true;
}
} else if (p_index.get_type() == Variant::STRING_NAME) {
Color *v = reinterpret_cast<Color *>(_data._mem);
if (p_index == CoreStringNames::singleton->r) {
valid = true;
@ -3246,7 +3265,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
return v->w;
}
} else if (p_index.get_type() == Variant::STRING_NAME) {
const Quat *v = reinterpret_cast<const Quat *>(_data._mem);
if (p_index == CoreStringNames::singleton->x) {
valid = true;
@ -3323,7 +3341,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
return v->get_axis(2);
}
} else if (p_index.get_type() == Variant::STRING_NAME) {
const Basis *v = _data._basis;
if (p_index == CoreStringNames::singleton->x) {
@ -3425,7 +3442,6 @@ Variant Variant::get(const Variant &p_index, bool *r_valid) const {
return (*v)[idx];
}
} else if (p_index.get_type() == Variant::STRING) {
const Color *v = reinterpret_cast<const Color *>(_data._mem);
if (p_index == CoreStringNames::singleton->r) {
valid = true;