Fix storing of Node Array properties

This commit is contained in:
kobewi
2024-06-21 15:45:55 +02:00
parent 04a530f91f
commit 74cc9e8d93
2 changed files with 75 additions and 2 deletions

View File

@ -44,6 +44,7 @@ bool PropertyUtils::is_property_value_different(const Object *p_object, const Va
// This must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error.
return !Math::is_equal_approx((float)p_a, (float)p_b);
} else if (p_a.get_type() == Variant::NODE_PATH && p_b.get_type() == Variant::OBJECT) {
// With properties of type Node, left side is NodePath, while right side is Node.
const Node *base_node = Object::cast_to<Node>(p_object);
const Node *target_node = Object::cast_to<Node>(p_b);
if (base_node && target_node) {
@ -51,6 +52,23 @@ bool PropertyUtils::is_property_value_different(const Object *p_object, const Va
}
}
if (p_a.get_type() == Variant::ARRAY && p_b.get_type() == Variant::ARRAY) {
const Node *base_node = Object::cast_to<Node>(p_object);
Array array1 = p_a;
Array array2 = p_b;
if (base_node && !array1.is_empty() && array2.size() == array1.size() && array1[0].get_type() == Variant::NODE_PATH && array2[0].get_type() == Variant::OBJECT) {
// Like above, but NodePaths/Nodes are inside arrays.
for (int i = 0; i < array1.size(); i++) {
const Node *target_node = Object::cast_to<Node>(array2[i]);
if (!target_node || array1[i] != base_node->get_path_to(target_node)) {
return true;
}
}
return false;
}
}
// For our purposes, treating null object as NIL is the right thing to do
const Variant &a = p_a.get_type() == Variant::OBJECT && (Object *)p_a == nullptr ? Variant() : p_a;
const Variant &b = p_b.get_type() == Variant::OBJECT && (Object *)p_b == nullptr ? Variant() : p_b;