From db9e3f257f6f5eebb36db802ac6d9f137cfcb9a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Sun, 21 Feb 2021 03:03:07 +0100 Subject: [PATCH] Rationalize property reversion --- editor/editor_inspector.cpp | 131 ++++++++++++++++-------------------- editor/editor_inspector.h | 2 + 2 files changed, 59 insertions(+), 74 deletions(-) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 3db03c02761..4a3413d9efa 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -493,6 +493,7 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian if (ss.is_valid()) { found_state = true; + break; } if (node == edited_scene) { //just in case @@ -506,59 +507,71 @@ bool EditorPropertyRevert::is_node_property_different(Node *p_node, const Varian } } - if (p_current.get_type() == Variant::FLOAT && p_orig.get_type() == Variant::FLOAT) { - float a = p_current; - float b = p_orig; - - return !Math::is_equal_approx(a, b); //this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error - } - - return bool(Variant::evaluate(Variant::OP_NOT_EQUAL, p_current, p_orig)); + return is_property_value_different(p_current, p_orig); } -bool EditorPropertyRevert::can_property_revert(Object *p_object, const StringName &p_property) { - bool has_revert = false; - - Node *node = Object::cast_to(p_object); - - if (node && EditorPropertyRevert::may_node_be_in_instance(node)) { - //check for difference including instantiation - Variant vorig; - if (EditorPropertyRevert::get_instantiated_node_original_property(node, p_property, vorig)) { - Variant v = p_object->get(p_property); - - if (EditorPropertyRevert::is_node_property_different(node, v, vorig)) { - has_revert = true; - } - } +bool EditorPropertyRevert::is_property_value_different(const Variant &p_a, const Variant &p_b) { + if (p_a.get_type() == Variant::FLOAT && p_b.get_type() == Variant::FLOAT) { + //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 { - //check for difference against default class value instead - Variant default_value = ClassDB::class_get_default_property_value(p_object->get_class_name(), p_property); - if (default_value != Variant() && default_value != p_object->get(p_property)) { - has_revert = true; - } + return p_a != p_b; } +} +Variant EditorPropertyRevert::get_property_revert_value(Object *p_object, const StringName &p_property) { // If the object implements property_can_revert, rely on that completely // (i.e. don't then try to revert to default value - the property_get_revert implementation // can do that if so desired) - if (p_object->has_method("property_can_revert")) { - has_revert = p_object->call("property_can_revert", p_property).operator bool(); - } else { - if (!has_revert && !p_object->get_script().is_null()) { - Ref