From 1a24c9e14bf1f9578eda338344c12faf66fb0e65 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Fri, 12 Aug 2022 23:57:11 +0300 Subject: Make `_validate_property` a multilevel method --- core/input/input_event.cpp | 14 +++++++------- core/input/input_event.h | 2 +- core/object/class_db.cpp | 4 ++-- core/object/object.cpp | 3 ++- core/object/object.h | 16 +++++++++++++++- 5 files changed, 27 insertions(+), 12 deletions(-) (limited to 'core') diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index 8ad2193fca..3f02d80c26 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -274,24 +274,24 @@ void InputEventWithModifiers::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "command_pressed"), "set_command_pressed", "is_command_pressed"); } -void InputEventWithModifiers::_validate_property(PropertyInfo &property) const { +void InputEventWithModifiers::_validate_property(PropertyInfo &p_property) const { if (store_command) { // If we only want to Store "Command". #ifdef APPLE_STYLE_KEYS // Don't store "Meta" on Mac. - if (property.name == "meta_pressed") { - property.usage ^= PROPERTY_USAGE_STORAGE; + if (p_property.name == "meta_pressed") { + p_property.usage ^= PROPERTY_USAGE_STORAGE; } #else // Don't store "Ctrl". - if (property.name == "ctrl_pressed") { - property.usage ^= PROPERTY_USAGE_STORAGE; + if (p_property.name == "ctrl_pressed") { + p_property.usage ^= PROPERTY_USAGE_STORAGE; } #endif } else { // We don't want to store command, only ctrl or meta (on mac). - if (property.name == "command_pressed") { - property.usage ^= PROPERTY_USAGE_STORAGE; + if (p_property.name == "command_pressed") { + p_property.usage ^= PROPERTY_USAGE_STORAGE; } } } diff --git a/core/input/input_event.h b/core/input/input_event.h index 59a2df497c..6cfc031c8a 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -128,7 +128,7 @@ class InputEventWithModifiers : public InputEventFromWindow { protected: static void _bind_methods(); - virtual void _validate_property(PropertyInfo &property) const override; + void _validate_property(PropertyInfo &p_property) const; public: void set_store_command(bool p_enabled); diff --git a/core/object/class_db.cpp b/core/object/class_db.cpp index 9790cc44e3..99b20560da 100644 --- a/core/object/class_db.cpp +++ b/core/object/class_db.cpp @@ -981,7 +981,7 @@ void ClassDB::get_property_list(const StringName &p_class, List *p if (p_validator) { // Making a copy as we may modify it. PropertyInfo pi_mut = pi; - p_validator->_validate_property(pi_mut); + p_validator->validate_property(pi_mut); p_list->push_back(pi_mut); } else { p_list->push_back(pi); @@ -1022,7 +1022,7 @@ bool ClassDB::get_property_info(const StringName &p_class, const StringName &p_p if (check->property_map.has(p_property)) { PropertyInfo pinfo = check->property_map[p_property]; if (p_validator) { - p_validator->_validate_property(pinfo); + p_validator->validate_property(pinfo); } if (r_info) { *r_info = pinfo; diff --git a/core/object/object.cpp b/core/object/object.cpp index a95ba7992b..5203685c7f 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -515,7 +515,8 @@ void Object::get_property_list(List *p_list, bool p_reversed) cons } } -void Object::_validate_property(PropertyInfo &property) const { +void Object::validate_property(PropertyInfo &p_property) const { + _validate_propertyv(p_property); } bool Object::property_can_revert(const String &p_name) const { diff --git a/core/object/object.h b/core/object/object.h index 154ef176d3..093b104664 100644 --- a/core/object/object.h +++ b/core/object/object.h @@ -471,6 +471,15 @@ protected: m_inherits::_get_property_listv(p_list, p_reversed); \ } \ } \ + _FORCE_INLINE_ void (Object::*_get_validate_property() const)(PropertyInfo & p_property) const { \ + return (void(Object::*)(PropertyInfo &) const) & m_class::_validate_property; \ + } \ + virtual void _validate_propertyv(PropertyInfo &p_property) const override { \ + m_inherits::_validate_propertyv(p_property); \ + if (m_class::_get_validate_property() != m_inherits::_get_validate_property()) { \ + _validate_property(p_property); \ + } \ + } \ _FORCE_INLINE_ bool (Object::*_get_property_can_revert() const)(const StringName &p_name) const { \ return (bool(Object::*)(const StringName &) const) & m_class::_property_can_revert; \ } \ @@ -637,6 +646,7 @@ protected: virtual bool _setv(const StringName &p_name, const Variant &p_property) { return false; }; virtual bool _getv(const StringName &p_name, Variant &r_property) const { return false; }; virtual void _get_property_listv(List *p_list, bool p_reversed) const {}; + virtual void _validate_propertyv(PropertyInfo &p_property) const {}; virtual bool _property_can_revertv(const StringName &p_name) const { return false; }; virtual bool _property_get_revertv(const StringName &p_name, Variant &r_property) const { return false; }; virtual void _notificationv(int p_notification, bool p_reversed) {} @@ -645,6 +655,7 @@ protected: bool _set(const StringName &p_name, const Variant &p_property) { return false; }; bool _get(const StringName &p_name, Variant &r_property) const { return false; }; void _get_property_list(List *p_list) const {}; + void _validate_property(PropertyInfo &p_property) const {}; bool _property_can_revert(const StringName &p_name) const { return false; }; bool _property_get_revert(const StringName &p_name, Variant &r_property) const { return false; }; void _notification(int p_notification) {} @@ -661,6 +672,9 @@ protected: _FORCE_INLINE_ void (Object::*_get_get_property_list() const)(List *p_list) const { return &Object::_get_property_list; } + _FORCE_INLINE_ void (Object::*_get_validate_property() const)(PropertyInfo &p_property) const { + return &Object::_validate_property; + } _FORCE_INLINE_ bool (Object::*_get_property_can_revert() const)(const StringName &p_name) const { return &Object::_property_can_revert; } @@ -690,7 +704,6 @@ protected: void _clear_internal_resource_paths(const Variant &p_var); friend class ClassDB; - virtual void _validate_property(PropertyInfo &property) const; void _disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force = false); @@ -791,6 +804,7 @@ public: Variant get_indexed(const Vector &p_names, bool *r_valid = nullptr) const; void get_property_list(List *p_list, bool p_reversed = false) const; + void validate_property(PropertyInfo &p_property) const; bool property_can_revert(const String &p_name) const; Variant property_get_revert(const String &p_name) const; -- cgit v1.2.3