瀏覽代碼

Clang-Tidy - google-default-arguments.
Refactor Serializable::Load(), Seriazable::LoadXML(), and Serializable::LoadJSON() virtual methods.

Yao Wei Tjong 姚伟忠 8 年之前
父節點
當前提交
c29cb530b6

+ 11 - 11
Source/Urho3D/AngelScript/APITemplates.h

@@ -427,14 +427,14 @@ static const AttributeInfo& SerializableGetAttributeInfo(unsigned index, Seriali
         return attributes->At(index);
         return attributes->At(index);
 }
 }
 
 
-static bool SerializableLoad(File* file, bool setInstanceDefault, Serializable* ptr)
+static bool SerializableLoad(File* file, Serializable* ptr)
 {
 {
-    return file && ptr->Load(*file, setInstanceDefault);
+    return file && ptr->Load(*file);
 }
 }
 
 
-static bool SerializableLoadVectorBuffer(VectorBuffer& buffer, bool setInstanceDefault, Serializable* ptr)
+static bool SerializableLoadVectorBuffer(VectorBuffer& buffer, Serializable* ptr)
 {
 {
-    return ptr->Load(buffer, setInstanceDefault);
+    return ptr->Load(buffer);
 }
 }
 
 
 static bool SerializableSave(File* file, Serializable* ptr)
 static bool SerializableSave(File* file, Serializable* ptr)
@@ -451,13 +451,13 @@ static bool SerializableSaveVectorBuffer(VectorBuffer& buffer, Serializable* ptr
 template <class T> void RegisterSerializable(asIScriptEngine* engine, const char* className)
 template <class T> void RegisterSerializable(asIScriptEngine* engine, const char* className)
 {
 {
     RegisterObject<T>(engine, className);
     RegisterObject<T>(engine, className);
-    engine->RegisterObjectMethod(className, "bool Load(File@+, bool setInstanceDefault = false)", asFUNCTION(SerializableLoad), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod(className, "bool Load(VectorBuffer&, bool setInstanceDefault = false)", asFUNCTION(SerializableLoadVectorBuffer), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod(className, "bool Load(File@+)", asFUNCTION(SerializableLoad), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod(className, "bool Load(VectorBuffer&)", asFUNCTION(SerializableLoadVectorBuffer), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool Save(File@+) const", asFUNCTION(SerializableSave), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool Save(File@+) const", asFUNCTION(SerializableSave), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool Save(VectorBuffer&) const", asFUNCTION(SerializableSaveVectorBuffer), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool Save(VectorBuffer&) const", asFUNCTION(SerializableSaveVectorBuffer), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod(className, "bool LoadXML(const XMLElement&, bool setInstanceDefault = false)", asMETHODPR(T, LoadXML, (const XMLElement&, bool), bool), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "bool LoadXML(const XMLElement&)", asMETHODPR(T, LoadXML, (const XMLElement&), bool), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool SaveXML(XMLElement&) const", asMETHODPR(T, SaveXML, (XMLElement&) const, bool), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool SaveXML(XMLElement&) const", asMETHODPR(T, SaveXML, (XMLElement&) const, bool), asCALL_THISCALL);
-    engine->RegisterObjectMethod(className, "bool LoadJSON(const JSONValue&, bool setInstanceDefault = false)", asMETHODPR(T, LoadJSON, (const JSONValue&, bool), bool), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "bool LoadJSON(const JSONValue&)", asMETHODPR(T, LoadJSON, (const JSONValue&), bool), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool SaveJSON(JSONValue&) const", asMETHODPR(T, SaveJSON, (JSONValue&) const, bool), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool SaveJSON(JSONValue&) const", asMETHODPR(T, SaveJSON, (JSONValue&) const, bool), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void MarkNetworkUpdate() const", asMETHODPR(T, MarkNetworkUpdate, (), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void MarkNetworkUpdate() const", asMETHODPR(T, MarkNetworkUpdate, (), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void ApplyAttributes()", asMETHODPR(T, ApplyAttributes, (), void), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "void ApplyAttributes()", asMETHODPR(T, ApplyAttributes, (), void), asCALL_THISCALL);
@@ -1111,12 +1111,12 @@ template <class T> void RegisterUIElement(asIScriptEngine* engine, const char* c
     RegisterObjectConstructor<T>(engine, className);
     RegisterObjectConstructor<T>(engine, className);
     RegisterNamedObjectConstructor<T>(engine, className);
     RegisterNamedObjectConstructor<T>(engine, className);
     RegisterSubclass<UIElement, T>(engine, "UIElement", className);
     RegisterSubclass<UIElement, T>(engine, "UIElement", className);
-    engine->RegisterObjectMethod(className, "bool LoadXML(const XMLElement&in, XMLFile@+, bool arg2 = false)", asMETHODPR(T, LoadXML, (const XMLElement&, XMLFile*, bool), bool), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "bool LoadXML(const XMLElement&in, XMLFile@+)", asMETHODPR(T, LoadXML, (const XMLElement&, XMLFile*), bool), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool LoadXML(File@+)", asFUNCTIONPR(UIElementLoadXML, (File*, UIElement*), bool), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool LoadXML(File@+)", asFUNCTIONPR(UIElementLoadXML, (File*, UIElement*), bool), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool LoadXML(VectorBuffer&)", asFUNCTIONPR(UIElementLoadXMLVectorBuffer, (VectorBuffer&, UIElement*), bool), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool LoadXML(VectorBuffer&)", asFUNCTIONPR(UIElementLoadXMLVectorBuffer, (VectorBuffer&, UIElement*), bool), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool LoadXML(XMLFile@+, XMLFile@+)", asFUNCTIONPR(UIElementLoadXML, (XMLFile*, XMLFile*, UIElement*), bool), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool LoadXML(XMLFile@+, XMLFile@+)", asFUNCTIONPR(UIElementLoadXML, (XMLFile*, XMLFile*, UIElement*), bool), asCALL_CDECL_OBJLAST);
-    engine->RegisterObjectMethod(className, "UIElement@+ LoadChildXML(const XMLElement&in, XMLFile@+ arg1 = null, bool arg2 = false)", asMETHOD(T, LoadChildXML), asCALL_THISCALL);
-    engine->RegisterObjectMethod(className, "UIElement@+ LoadChildXML(XMLFile@+, XMLFile@+ arg1 = null)", asFUNCTION(UIElementLoadChildXML), asCALL_CDECL_OBJLAST);
+    engine->RegisterObjectMethod(className, "UIElement@+ LoadChildXML(const XMLElement&in, XMLFile@+)", asMETHOD(T, LoadChildXML), asCALL_THISCALL);
+    engine->RegisterObjectMethod(className, "UIElement@+ LoadChildXML(XMLFile@+, XMLFile@+)", asFUNCTION(UIElementLoadChildXML), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool SaveXML(File@+, const String&in indentation = \"\t\")", asFUNCTION(UIElementSaveXML), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool SaveXML(File@+, const String&in indentation = \"\t\")", asFUNCTION(UIElementSaveXML), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool SaveXML(VectorBuffer&, const String&in indentation = \"\t\")", asFUNCTION(UIElementSaveXMLVectorBuffer), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool SaveXML(VectorBuffer&, const String&in indentation = \"\t\")", asFUNCTION(UIElementSaveXMLVectorBuffer), asCALL_CDECL_OBJLAST);
     engine->RegisterObjectMethod(className, "bool SetStyle(const XMLElement&in)", asMETHODPR(T, SetStyle, (const XMLElement&), bool), asCALL_THISCALL);
     engine->RegisterObjectMethod(className, "bool SetStyle(const XMLElement&in)", asMETHODPR(T, SetStyle, (const XMLElement&), bool), asCALL_THISCALL);

+ 6 - 6
Source/Urho3D/Graphics/AnimatedModel.cpp

@@ -125,28 +125,28 @@ void AnimatedModel::RegisterObject(Context* context)
         AM_DEFAULT | AM_NOEDIT);
         AM_DEFAULT | AM_NOEDIT);
 }
 }
 
 
-bool AnimatedModel::Load(Deserializer& source, bool setInstanceDefault)
+bool AnimatedModel::Load(Deserializer& source)
 {
 {
     loading_ = true;
     loading_ = true;
-    bool success = Component::Load(source, setInstanceDefault);
+    bool success = Component::Load(source);
     loading_ = false;
     loading_ = false;
 
 
     return success;
     return success;
 }
 }
 
 
-bool AnimatedModel::LoadXML(const XMLElement& source, bool setInstanceDefault)
+bool AnimatedModel::LoadXML(const XMLElement& source)
 {
 {
     loading_ = true;
     loading_ = true;
-    bool success = Component::LoadXML(source, setInstanceDefault);
+    bool success = Component::LoadXML(source);
     loading_ = false;
     loading_ = false;
 
 
     return success;
     return success;
 }
 }
 
 
-bool AnimatedModel::LoadJSON(const JSONValue& source, bool setInstanceDefault)
+bool AnimatedModel::LoadJSON(const JSONValue& source)
 {
 {
     loading_ = true;
     loading_ = true;
-    bool success = Component::LoadJSON(source, setInstanceDefault);
+    bool success = Component::LoadJSON(source);
     loading_ = false;
     loading_ = false;
 
 
     return success;
     return success;

+ 3 - 3
Source/Urho3D/Graphics/AnimatedModel.h

@@ -48,11 +48,11 @@ public:
     static void RegisterObject(Context* context);
     static void RegisterObject(Context* context);
 
 
     /// Load from binary data. Return true if successful.
     /// Load from binary data. Return true if successful.
-    bool Load(Deserializer& source, bool setInstanceDefault = false) override;
+    bool Load(Deserializer& source) override;
     /// Load from XML data. Return true if successful.
     /// Load from XML data. Return true if successful.
-    bool LoadXML(const XMLElement& source, bool setInstanceDefault = false) override;
+    bool LoadXML(const XMLElement& source) override;
     /// Load from JSON data. Return true if successful.
     /// Load from JSON data. Return true if successful.
-    bool LoadJSON(const JSONValue& source, bool setInstanceDefault = false) override;
+    bool LoadJSON(const JSONValue& source) override;
     /// Apply attribute changes that can not be applied immediately. Called after scene load or a network update.
     /// Apply attribute changes that can not be applied immediately. Called after scene load or a network update.
     void ApplyAttributes() override;
     void ApplyAttributes() override;
     /// Process octree raycast. May be called from a worker thread.
     /// Process octree raycast. May be called from a worker thread.

+ 4 - 4
Source/Urho3D/Scene/Animatable.cpp

@@ -74,9 +74,9 @@ void Animatable::RegisterObject(Context* context)
         ResourceRef(ObjectAnimation::GetTypeStatic()), AM_DEFAULT);
         ResourceRef(ObjectAnimation::GetTypeStatic()), AM_DEFAULT);
 }
 }
 
 
-bool Animatable::LoadXML(const XMLElement& source, bool setInstanceDefault)
+bool Animatable::LoadXML(const XMLElement& source)
 {
 {
-    if (!Serializable::LoadXML(source, setInstanceDefault))
+    if (!Serializable::LoadXML(source))
         return false;
         return false;
 
 
     SetObjectAnimation(nullptr);
     SetObjectAnimation(nullptr);
@@ -120,9 +120,9 @@ bool Animatable::LoadXML(const XMLElement& source, bool setInstanceDefault)
     return true;
     return true;
 }
 }
 
 
-bool Animatable::LoadJSON(const JSONValue& source, bool setInstanceDefault)
+bool Animatable::LoadJSON(const JSONValue& source)
 {
 {
-    if (!Serializable::LoadJSON(source, setInstanceDefault))
+    if (!Serializable::LoadJSON(source))
         return false;
         return false;
 
 
     SetObjectAnimation(nullptr);
     SetObjectAnimation(nullptr);

+ 4 - 4
Source/Urho3D/Scene/Animatable.h

@@ -72,12 +72,12 @@ public:
     /// Register object factory.
     /// Register object factory.
     static void RegisterObject(Context* context);
     static void RegisterObject(Context* context);
 
 
-    /// Load from XML data. When setInstanceDefault is set to true, after setting the attribute value, store the value as instance's default value. Return true if successful.
-    bool LoadXML(const XMLElement& source, bool setInstanceDefault = false) override;
+    /// Load from XML data. Return true if successful.
+    bool LoadXML(const XMLElement& source) override;
     /// Save as XML data. Return true if successful.
     /// Save as XML data. Return true if successful.
     bool SaveXML(XMLElement& dest) const override;
     bool SaveXML(XMLElement& dest) const override;
-    /// Load from JSON data. When setInstanceDefault is set to true, after setting the attribute value, store the value as instance's default value. Return true if successful.
-    bool LoadJSON(const JSONValue& source, bool setInstanceDefault = false) override;
+    /// Load from JSON data. Return true if successful.
+    bool LoadJSON(const JSONValue& source) override;
     /// Save as JSON data. Return true if successful.
     /// Save as JSON data. Return true if successful.
     bool SaveJSON(JSONValue& dest) const override;
     bool SaveJSON(JSONValue& dest) const override;
 
 

+ 3 - 3
Source/Urho3D/Scene/Node.cpp

@@ -93,7 +93,7 @@ void Node::RegisterObject(Context* context)
         AM_NET | AM_NOEDIT);
         AM_NET | AM_NOEDIT);
 }
 }
 
 
-bool Node::Load(Deserializer& source, bool setInstanceDefault)
+bool Node::Load(Deserializer& source)
 {
 {
     SceneResolver resolver;
     SceneResolver resolver;
 
 
@@ -153,7 +153,7 @@ bool Node::Save(Serializer& dest) const
     return true;
     return true;
 }
 }
 
 
-bool Node::LoadXML(const XMLElement& source, bool setInstanceDefault)
+bool Node::LoadXML(const XMLElement& source)
 {
 {
     SceneResolver resolver;
     SceneResolver resolver;
 
 
@@ -172,7 +172,7 @@ bool Node::LoadXML(const XMLElement& source, bool setInstanceDefault)
     return success;
     return success;
 }
 }
 
 
-bool Node::LoadJSON(const JSONValue& source, bool setInstanceDefault)
+bool Node::LoadJSON(const JSONValue& source)
 {
 {
     SceneResolver resolver;
     SceneResolver resolver;
 
 

+ 3 - 3
Source/Urho3D/Scene/Node.h

@@ -85,11 +85,11 @@ public:
     static void RegisterObject(Context* context);
     static void RegisterObject(Context* context);
 
 
     /// Load from binary data. Return true if successful.
     /// Load from binary data. Return true if successful.
-    bool Load(Deserializer& source, bool setInstanceDefault = false) override;
+    bool Load(Deserializer& source) override;
     /// Load from XML data. Return true if successful.
     /// Load from XML data. Return true if successful.
-    bool LoadXML(const XMLElement& source, bool setInstanceDefault = false) override;
+    bool LoadXML(const XMLElement& source) override;
     /// Load from JSON data. Return true if successful.
     /// Load from JSON data. Return true if successful.
-    bool LoadJSON(const JSONValue& source, bool setInstanceDefault = false) override;
+    bool LoadJSON(const JSONValue& source) override;
     /// Save as binary data. Return true if successful.
     /// Save as binary data. Return true if successful.
     bool Save(Serializer& dest) const override;
     bool Save(Serializer& dest) const override;
     /// Save as XML data. Return true if successful.
     /// Save as XML data. Return true if successful.

+ 6 - 6
Source/Urho3D/Scene/Scene.cpp

@@ -111,7 +111,7 @@ void Scene::RegisterObject(Context* context)
     URHO3D_MIXED_ACCESSOR_ATTRIBUTE("Variable Names", GetVarNamesAttr, SetVarNamesAttr, String, String::EMPTY, AM_FILE | AM_NOEDIT);
     URHO3D_MIXED_ACCESSOR_ATTRIBUTE("Variable Names", GetVarNamesAttr, SetVarNamesAttr, String, String::EMPTY, AM_FILE | AM_NOEDIT);
 }
 }
 
 
-bool Scene::Load(Deserializer& source, bool setInstanceDefault)
+bool Scene::Load(Deserializer& source)
 {
 {
     URHO3D_PROFILE(LoadScene);
     URHO3D_PROFILE(LoadScene);
 
 
@@ -129,7 +129,7 @@ bool Scene::Load(Deserializer& source, bool setInstanceDefault)
     Clear();
     Clear();
 
 
     // Load the whole scene, then perform post-load if successfully loaded
     // Load the whole scene, then perform post-load if successfully loaded
-    if (Node::Load(source, setInstanceDefault))
+    if (Node::Load(source))
     {
     {
         FinishLoading(&source);
         FinishLoading(&source);
         return true;
         return true;
@@ -162,7 +162,7 @@ bool Scene::Save(Serializer& dest) const
         return false;
         return false;
 }
 }
 
 
-bool Scene::LoadXML(const XMLElement& source, bool setInstanceDefault)
+bool Scene::LoadXML(const XMLElement& source)
 {
 {
     URHO3D_PROFILE(LoadSceneXML);
     URHO3D_PROFILE(LoadSceneXML);
 
 
@@ -170,7 +170,7 @@ bool Scene::LoadXML(const XMLElement& source, bool setInstanceDefault)
 
 
     // Load the whole scene, then perform post-load if successfully loaded
     // Load the whole scene, then perform post-load if successfully loaded
     // Note: the scene filename and checksum can not be set, as we only used an XML element
     // Note: the scene filename and checksum can not be set, as we only used an XML element
-    if (Node::LoadXML(source, setInstanceDefault))
+    if (Node::LoadXML(source))
     {
     {
         FinishLoading(nullptr);
         FinishLoading(nullptr);
         return true;
         return true;
@@ -179,7 +179,7 @@ bool Scene::LoadXML(const XMLElement& source, bool setInstanceDefault)
         return false;
         return false;
 }
 }
 
 
-bool Scene::LoadJSON(const JSONValue& source, bool setInstanceDefault)
+bool Scene::LoadJSON(const JSONValue& source)
 {
 {
     URHO3D_PROFILE(LoadSceneJSON);
     URHO3D_PROFILE(LoadSceneJSON);
 
 
@@ -187,7 +187,7 @@ bool Scene::LoadJSON(const JSONValue& source, bool setInstanceDefault)
 
 
     // Load the whole scene, then perform post-load if successfully loaded
     // Load the whole scene, then perform post-load if successfully loaded
     // Note: the scene filename and checksum can not be set, as we only used an XML element
     // Note: the scene filename and checksum can not be set, as we only used an XML element
-    if (Node::LoadJSON(source, setInstanceDefault))
+    if (Node::LoadJSON(source))
     {
     {
         FinishLoading(nullptr);
         FinishLoading(nullptr);
         return true;
         return true;

+ 3 - 3
Source/Urho3D/Scene/Scene.h

@@ -99,13 +99,13 @@ public:
     static void RegisterObject(Context* context);
     static void RegisterObject(Context* context);
 
 
     /// Load from binary data. Removes all existing child nodes and components first. Return true if successful.
     /// Load from binary data. Removes all existing child nodes and components first. Return true if successful.
-    bool Load(Deserializer& source, bool setInstanceDefault = false) override;
+    bool Load(Deserializer& source) override;
     /// Save to binary data. Return true if successful.
     /// Save to binary data. Return true if successful.
     bool Save(Serializer& dest) const override;
     bool Save(Serializer& dest) const override;
     /// Load from XML data. Removes all existing child nodes and components first. Return true if successful.
     /// Load from XML data. Removes all existing child nodes and components first. Return true if successful.
-    bool LoadXML(const XMLElement& source, bool setInstanceDefault = false) override;
+    bool LoadXML(const XMLElement& source) override;
     /// Load from JSON data. Removes all existing child nodes and components first. Return true if successful.
     /// Load from JSON data. Removes all existing child nodes and components first. Return true if successful.
-    bool LoadJSON(const JSONValue& source, bool setInstanceDefault = false) override;
+    bool LoadJSON(const JSONValue& source) override;
     /// Mark for attribute check on the next network update.
     /// Mark for attribute check on the next network update.
     void MarkNetworkUpdate() override;
     void MarkNetworkUpdate() override;
     /// Add a replication state that is tracking this scene.
     /// Add a replication state that is tracking this scene.

+ 8 - 16
Source/Urho3D/Scene/Serializable.cpp

@@ -55,6 +55,7 @@ static unsigned RemapAttributeIndex(const Vector<AttributeInfo>* attributes, con
 
 
 Serializable::Serializable(Context* context) :
 Serializable::Serializable(Context* context) :
     Object(context),
     Object(context),
+    setInstanceDefault_(false),
     temporary_(false)
     temporary_(false)
 {
 {
 }
 }
@@ -63,6 +64,10 @@ Serializable::~Serializable() = default;
 
 
 void Serializable::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
 void Serializable::OnSetAttribute(const AttributeInfo& attr, const Variant& src)
 {
 {
+    // TODO: may be could use an observer pattern here
+    if (setInstanceDefault_)
+        SetInstanceDefault(attr.name_, src);
+
     // Check for accessor function mode
     // Check for accessor function mode
     if (attr.accessor_)
     if (attr.accessor_)
     {
     {
@@ -285,7 +290,7 @@ const Vector<AttributeInfo>* Serializable::GetNetworkAttributes() const
     return networkState_ ? networkState_->attributes_ : context_->GetNetworkAttributes(GetType());
     return networkState_ ? networkState_->attributes_ : context_->GetNetworkAttributes(GetType());
 }
 }
 
 
-bool Serializable::Load(Deserializer& source, bool setInstanceDefault)
+bool Serializable::Load(Deserializer& source)
 {
 {
     const Vector<AttributeInfo>* attributes = GetAttributes();
     const Vector<AttributeInfo>* attributes = GetAttributes();
     if (!attributes)
     if (!attributes)
@@ -305,9 +310,6 @@ bool Serializable::Load(Deserializer& source, bool setInstanceDefault)
 
 
         Variant varValue = source.ReadVariant(attr.type_);
         Variant varValue = source.ReadVariant(attr.type_);
         OnSetAttribute(attr, varValue);
         OnSetAttribute(attr, varValue);
-
-        if (setInstanceDefault)
-            SetInstanceDefault(attr.name_, varValue);
     }
     }
 
 
     return true;
     return true;
@@ -339,7 +341,7 @@ bool Serializable::Save(Serializer& dest) const
     return true;
     return true;
 }
 }
 
 
-bool Serializable::LoadXML(const XMLElement& source, bool setInstanceDefault)
+bool Serializable::LoadXML(const XMLElement& source)
 {
 {
     if (source.IsNull())
     if (source.IsNull())
     {
     {
@@ -393,13 +395,8 @@ bool Serializable::LoadXML(const XMLElement& source, bool setInstanceDefault)
                     varValue = attrElem.GetVariantValue(attr.type_);
                     varValue = attrElem.GetVariantValue(attr.type_);
 
 
                 if (!varValue.IsEmpty())
                 if (!varValue.IsEmpty())
-                {
                     OnSetAttribute(attr, varValue);
                     OnSetAttribute(attr, varValue);
 
 
-                    if (setInstanceDefault)
-                        SetInstanceDefault(attr.name_, varValue);
-                }
-
                 startIndex = (i + 1) % attributes->Size();
                 startIndex = (i + 1) % attributes->Size();
                 break;
                 break;
             }
             }
@@ -419,7 +416,7 @@ bool Serializable::LoadXML(const XMLElement& source, bool setInstanceDefault)
     return true;
     return true;
 }
 }
 
 
-bool Serializable::LoadJSON(const JSONValue& source, bool setInstanceDefault)
+bool Serializable::LoadJSON(const JSONValue& source)
 {
 {
     if (source.IsNull())
     if (source.IsNull())
     {
     {
@@ -486,13 +483,8 @@ bool Serializable::LoadJSON(const JSONValue& source, bool setInstanceDefault)
                     varValue = value.GetVariantValue(attr.type_);
                     varValue = value.GetVariantValue(attr.type_);
 
 
                 if (!varValue.IsEmpty())
                 if (!varValue.IsEmpty())
-                {
                     OnSetAttribute(attr, varValue);
                     OnSetAttribute(attr, varValue);
 
 
-                    if (setInstanceDefault)
-                        SetInstanceDefault(attr.name_, varValue);
-                }
-
                 startIndex = (i + 1) % attributes->Size();
                 startIndex = (i + 1) % attributes->Size();
                 break;
                 break;
             }
             }

+ 10 - 6
Source/Urho3D/Scene/Serializable.h

@@ -59,16 +59,16 @@ public:
     virtual const Vector<AttributeInfo>* GetAttributes() const;
     virtual const Vector<AttributeInfo>* GetAttributes() const;
     /// Return network replication attribute descriptions, or null if none defined.
     /// Return network replication attribute descriptions, or null if none defined.
     virtual const Vector<AttributeInfo>* GetNetworkAttributes() const;
     virtual const Vector<AttributeInfo>* GetNetworkAttributes() const;
-    /// Load from binary data. When setInstanceDefault is set to true, after setting the attribute value, store the value as instance's default value. Return true if successful.
-    virtual bool Load(Deserializer& source, bool setInstanceDefault = false);
+    /// Load from binary data. Return true if successful.
+    virtual bool Load(Deserializer& source);
     /// Save as binary data. Return true if successful.
     /// Save as binary data. Return true if successful.
     virtual bool Save(Serializer& dest) const;
     virtual bool Save(Serializer& dest) const;
-    /// Load from XML data. When setInstanceDefault is set to true, after setting the attribute value, store the value as instance's default value. Return true if successful.
-    virtual bool LoadXML(const XMLElement& source, bool setInstanceDefault = false);
+    /// Load from XML data. Return true if successful.
+    virtual bool LoadXML(const XMLElement& source);
     /// Save as XML data. Return true if successful.
     /// Save as XML data. Return true if successful.
     virtual bool SaveXML(XMLElement& dest) const;
     virtual bool SaveXML(XMLElement& dest) const;
-    /// Load from JSON data. When setInstanceDefault is set to true, after setting the attribute value, store the value as instance's default value. Return true if successful.
-    virtual bool LoadJSON(const JSONValue& source, bool setInstanceDefault = false);
+    /// Load from JSON data. Return true if successful.
+    virtual bool LoadJSON(const JSONValue& source);
     /// Save as JSON data. Return true if successful.
     /// Save as JSON data. Return true if successful.
     virtual bool SaveJSON(JSONValue& dest) const;
     virtual bool SaveJSON(JSONValue& dest) const;
 
 
@@ -85,6 +85,8 @@ public:
     bool SetAttribute(unsigned index, const Variant& value);
     bool SetAttribute(unsigned index, const Variant& value);
     /// Set attribute by name. Return true if successfully set.
     /// Set attribute by name. Return true if successfully set.
     bool SetAttribute(const String& name, const Variant& value);
     bool SetAttribute(const String& name, const Variant& value);
+    /// Set instance-level default flag.
+    void SetInstanceDefault(bool enable) { setInstanceDefault_ = enable; }
     /// Reset all editable attributes to their default values.
     /// Reset all editable attributes to their default values.
     void ResetToDefault();
     void ResetToDefault();
     /// Remove instance's default values if they are set previously.
     /// Remove instance's default values if they are set previously.
@@ -140,6 +142,8 @@ private:
 
 
     /// Attribute default value at each instance level.
     /// Attribute default value at each instance level.
     UniquePtr<VariantMap> instanceDefaultValues_;
     UniquePtr<VariantMap> instanceDefaultValues_;
+    /// When true, store the attribute value as instance's default value (internal use only).
+    bool setInstanceDefault_;
     /// Temporary flag.
     /// Temporary flag.
     bool temporary_;
     bool temporary_;
 };
 };

+ 3 - 3
Source/Urho3D/Scene/UnknownComponent.cpp

@@ -92,7 +92,7 @@ void UnknownComponent::RegisterObject(Context* context)
     context->RegisterFactory<UnknownComponent>();
     context->RegisterFactory<UnknownComponent>();
 }
 }
 
 
-bool UnknownComponent::Load(Deserializer& source, bool setInstanceDefault)
+bool UnknownComponent::Load(Deserializer& source)
 {
 {
     useXML_ = false;
     useXML_ = false;
     xmlAttributes_.Clear();
     xmlAttributes_.Clear();
@@ -104,7 +104,7 @@ bool UnknownComponent::Load(Deserializer& source, bool setInstanceDefault)
     return dataSize ? source.Read(&binaryAttributes_[0], dataSize) == dataSize : true;
     return dataSize ? source.Read(&binaryAttributes_[0], dataSize) == dataSize : true;
 }
 }
 
 
-bool UnknownComponent::LoadXML(const XMLElement& source, bool setInstanceDefault)
+bool UnknownComponent::LoadXML(const XMLElement& source)
 {
 {
     useXML_ = true;
     useXML_ = true;
     xmlAttributes_.Clear();
     xmlAttributes_.Clear();
@@ -138,7 +138,7 @@ bool UnknownComponent::LoadXML(const XMLElement& source, bool setInstanceDefault
 }
 }
 
 
 
 
-bool UnknownComponent::LoadJSON(const JSONValue& source, bool setInstanceDefault)
+bool UnknownComponent::LoadJSON(const JSONValue& source)
 {
 {
     useXML_ = true;
     useXML_ = true;
     xmlAttributes_.Clear();
     xmlAttributes_.Clear();

+ 3 - 3
Source/Urho3D/Scene/UnknownComponent.h

@@ -47,11 +47,11 @@ public:
     const Vector<AttributeInfo>* GetAttributes() const override { return &xmlAttributeInfos_; }
     const Vector<AttributeInfo>* GetAttributes() const override { return &xmlAttributeInfos_; }
 
 
     /// Load from binary data. Return true if successful.
     /// Load from binary data. Return true if successful.
-    bool Load(Deserializer& source, bool setInstanceDefault = false) override;
+    bool Load(Deserializer& source) override;
     /// Load from XML data. Return true if successful.
     /// Load from XML data. Return true if successful.
-    bool LoadXML(const XMLElement& source, bool setInstanceDefault = false) override;
+    bool LoadXML(const XMLElement& source) override;
     /// Load from JSON data. Return true if successful.
     /// Load from JSON data. Return true if successful.
-    bool LoadJSON(const JSONValue& source, bool setInstanceDefault = false) override;
+    bool LoadJSON(const JSONValue& source) override;
     /// Save as binary data. Return true if successful.
     /// Save as binary data. Return true if successful.
     bool Save(Serializer& dest) const override;
     bool Save(Serializer& dest) const override;
     /// Save as XML data. Return true if successful.
     /// Save as XML data. Return true if successful.

+ 3 - 3
Source/Urho3D/UI/Menu.cpp

@@ -124,7 +124,7 @@ void Menu::OnShowPopup()
 {
 {
 }
 }
 
 
-bool Menu::LoadXML(const XMLElement& source, XMLFile* styleFile, bool setInstanceDefault)
+bool Menu::LoadXML(const XMLElement& source, XMLFile* styleFile)
 {
 {
     // Get style override if defined
     // Get style override if defined
     String styleName = source.GetAttribute("style");
     String styleName = source.GetAttribute("style");
@@ -154,7 +154,7 @@ bool Menu::LoadXML(const XMLElement& source, XMLFile* styleFile, bool setInstanc
     }
     }
 
 
     // Then load rest of the attributes from the source
     // Then load rest of the attributes from the source
-    if (!Serializable::LoadXML(source, setInstanceDefault))
+    if (!Serializable::LoadXML(source))
         return false;
         return false;
 
 
     unsigned nextInternalChild = 0;
     unsigned nextInternalChild = 0;
@@ -220,7 +220,7 @@ bool Menu::LoadXML(const XMLElement& source, XMLFile* styleFile, bool setInstanc
             if (popupElem)
             if (popupElem)
                 child->SetDefaultStyle(styleFile);
                 child->SetDefaultStyle(styleFile);
 
 
-            if (!child->LoadXML(childElem, styleFile, setInstanceDefault))
+            if (!child->LoadXML(childElem, styleFile))
                 return false;
                 return false;
         }
         }
 
 

+ 1 - 1
Source/Urho3D/UI/Menu.h

@@ -43,7 +43,7 @@ public:
     static void RegisterObject(Context* context);
     static void RegisterObject(Context* context);
 
 
     /// Load from XML data with style. Return true if successful.
     /// Load from XML data with style. Return true if successful.
-    bool LoadXML(const XMLElement& source, XMLFile* styleFile, bool setInstanceDefault = false) override;
+    bool LoadXML(const XMLElement& source, XMLFile* styleFile) override;
     /// Save as XML data. Return true if successful.
     /// Save as XML data. Return true if successful.
     bool SaveXML(XMLElement& dest) const override;
     bool SaveXML(XMLElement& dest) const override;
 
 

+ 11 - 8
Source/Urho3D/UI/UIElement.cpp

@@ -213,12 +213,12 @@ void UIElement::ApplyAttributes()
     }
     }
 }
 }
 
 
-bool UIElement::LoadXML(const XMLElement& source, bool setInstanceDefault)
+bool UIElement::LoadXML(const XMLElement& source)
 {
 {
-    return LoadXML(source, nullptr, setInstanceDefault);
+    return LoadXML(source, nullptr);
 }
 }
 
 
-bool UIElement::LoadXML(const XMLElement& source, XMLFile* styleFile, bool setInstanceDefault)
+bool UIElement::LoadXML(const XMLElement& source, XMLFile* styleFile)
 {
 {
     // Get style override if defined
     // Get style override if defined
     String styleName = source.GetAttribute("style");
     String styleName = source.GetAttribute("style");
@@ -251,7 +251,7 @@ bool UIElement::LoadXML(const XMLElement& source, XMLFile* styleFile, bool setIn
     DisableLayoutUpdate();
     DisableLayoutUpdate();
 
 
     // Then load rest of the attributes from the source
     // Then load rest of the attributes from the source
-    if (!Animatable::LoadXML(source, setInstanceDefault))
+    if (!Animatable::LoadXML(source))
         return false;
         return false;
 
 
     unsigned nextInternalChild = 0;
     unsigned nextInternalChild = 0;
@@ -289,7 +289,7 @@ bool UIElement::LoadXML(const XMLElement& source, XMLFile* styleFile, bool setIn
         {
         {
             if (!styleFile)
             if (!styleFile)
                 styleFile = GetDefaultStyle();
                 styleFile = GetDefaultStyle();
-            if (!child->LoadXML(childElem, styleFile, setInstanceDefault))
+            if (!child->LoadXML(childElem, styleFile))
                 return false;
                 return false;
         }
         }
 
 
@@ -304,7 +304,7 @@ bool UIElement::LoadXML(const XMLElement& source, XMLFile* styleFile, bool setIn
     return true;
     return true;
 }
 }
 
 
-UIElement* UIElement::LoadChildXML(const XMLElement& childElem, XMLFile* styleFile, bool setInstanceDefault)
+UIElement* UIElement::LoadChildXML(const XMLElement& childElem, XMLFile* styleFile)
 {
 {
     bool internalElem = childElem.GetBool("internal");
     bool internalElem = childElem.GetBool("internal");
     if (internalElem)
     if (internalElem)
@@ -323,7 +323,7 @@ UIElement* UIElement::LoadChildXML(const XMLElement& childElem, XMLFile* styleFi
     {
     {
         if (!styleFile)
         if (!styleFile)
             styleFile = GetDefaultStyle();
             styleFile = GetDefaultStyle();
-        if (!child->LoadXML(childElem, styleFile, setInstanceDefault))
+        if (!child->LoadXML(childElem, styleFile))
         {
         {
             RemoveChild(child, index);
             RemoveChild(child, index);
             return nullptr;
             return nullptr;
@@ -1070,7 +1070,10 @@ bool UIElement::SetStyle(const XMLElement& element)
     appliedStyle_ = element.GetAttribute("type");
     appliedStyle_ = element.GetAttribute("type");
 
 
     // Consider style attribute values as instance-level attribute default values
     // Consider style attribute values as instance-level attribute default values
-    return LoadXML(element, true);
+    SetInstanceDefault(true);
+    bool success = LoadXML(element);
+    SetInstanceDefault(false);
+    return success;
 }
 }
 
 
 bool UIElement::SetStyleAuto(XMLFile* file)
 bool UIElement::SetStyleAuto(XMLFile* file)

+ 3 - 3
Source/Urho3D/UI/UIElement.h

@@ -127,11 +127,11 @@ public:
     /// Apply attribute changes that can not be applied immediately.
     /// Apply attribute changes that can not be applied immediately.
     void ApplyAttributes() override;
     void ApplyAttributes() override;
     /// Load from XML data. Return true if successful.
     /// Load from XML data. Return true if successful.
-    bool LoadXML(const XMLElement& source, bool setInstanceDefault = false) override;
+    bool LoadXML(const XMLElement& source) override;
     /// Load from XML data with style. Return true if successful.
     /// Load from XML data with style. Return true if successful.
-    virtual bool LoadXML(const XMLElement& source, XMLFile* styleFile, bool setInstanceDefault = false);
+    virtual bool LoadXML(const XMLElement& source, XMLFile* styleFile);
     /// Create a child by loading from XML data with style. Returns the child element if successful, null if otherwise.
     /// Create a child by loading from XML data with style. Returns the child element if successful, null if otherwise.
-    virtual UIElement* LoadChildXML(const XMLElement& childElem, XMLFile* styleFile = nullptr, bool setInstanceDefault = false);
+    virtual UIElement* LoadChildXML(const XMLElement& childElem, XMLFile* styleFile);
     /// Save as XML data. Return true if successful.
     /// Save as XML data. Return true if successful.
     bool SaveXML(XMLElement& dest) const override;
     bool SaveXML(XMLElement& dest) const override;
 
 

+ 12 - 12
bin/Data/Scripts/Editor/EditorResourceBrowser.as

@@ -266,7 +266,7 @@ void CreateResourceFilterUI()
     Array<ResourceType@> sorted;
     Array<ResourceType@> sorted;
     for (int i=1; i <= NUMBER_OF_VALID_RESOURCE_TYPES; ++i)
     for (int i=1; i <= NUMBER_OF_VALID_RESOURCE_TYPES; ++i)
         sorted.Push(ResourceType(i, ResourceTypeName(i)));
         sorted.Push(ResourceType(i, ResourceTypeName(i)));
-        
+
     // 2 unknown types are reserved for the top, the rest are alphabetized
     // 2 unknown types are reserved for the top, the rest are alphabetized
     sorted.Sort();
     sorted.Sort();
     sorted.Insert(0, ResourceType(RESOURCE_TYPE_UNKNOWN, ResourceTypeName(RESOURCE_TYPE_UNKNOWN)) );
     sorted.Insert(0, ResourceType(RESOURCE_TYPE_UNKNOWN, ResourceTypeName(RESOURCE_TYPE_UNKNOWN)) );
@@ -351,7 +351,7 @@ void InitializeBrowserFileListRow(Text@ fileText, BrowserFile@ file)
         text.text = file.ResourceTypeName();
         text.text = file.ResourceTypeName();
     }
     }
 
 
-    if (file.resourceType == RESOURCE_TYPE_MATERIAL || 
+    if (file.resourceType == RESOURCE_TYPE_MATERIAL ||
             file.resourceType == RESOURCE_TYPE_MODEL ||
             file.resourceType == RESOURCE_TYPE_MODEL ||
             file.resourceType == RESOURCE_TYPE_PARTICLEEFFECT ||
             file.resourceType == RESOURCE_TYPE_PARTICLEEFFECT ||
             file.resourceType == RESOURCE_TYPE_PREFAB
             file.resourceType == RESOURCE_TYPE_PREFAB
@@ -491,7 +491,7 @@ BrowserDir@ InitBrowserDir(String path)
                 parent.children.Push(browserDir);
                 parent.children.Push(browserDir);
             }
             }
             @parent = browserDir;
             @parent = browserDir;
-        } 
+        }
         return browserDir;
         return browserDir;
     }
     }
     return null;
     return null;
@@ -1031,7 +1031,7 @@ void HandleBrowserFileDragEnd(StringHash eventType, VariantMap& eventData)
             StaticModel@ sm = createdNode.CreateComponent("StaticModel");
             StaticModel@ sm = createdNode.CreateComponent("StaticModel");
             sm.model = model;
             sm.model = model;
         }
         }
-        
+
         AdjustNodePositionByAABB(createdNode);
         AdjustNodePositionByAABB(createdNode);
     }
     }
 
 
@@ -1044,10 +1044,10 @@ void HandleFileChanged(StringHash eventType, VariantMap& eventData)
 {
 {
     String filename = eventData["FileName"].GetString();
     String filename = eventData["FileName"].GetString();
     BrowserFile@ file = GetBrowserFileFromPath(filename);
     BrowserFile@ file = GetBrowserFileFromPath(filename);
-    
+
     if (file is null)
     if (file is null)
     {
     {
-        // TODO: new file logic when watchers are supported 
+        // TODO: new file logic when watchers are supported
         return;
         return;
     }
     }
     else
     else
@@ -1280,7 +1280,7 @@ bool GetExtensionType(String path, StringHash &out fileType)
 }
 }
 
 
 bool GetBinaryType(String path, StringHash &out fileType, bool useCache = false)
 bool GetBinaryType(String path, StringHash &out fileType, bool useCache = false)
-{   
+{
     StringHash type;
     StringHash type;
     if (useCache)
     if (useCache)
     {
     {
@@ -1550,7 +1550,7 @@ class BrowserFile
             InitializeBrowserFileListRow(browserFileListRow_, this);
             InitializeBrowserFileListRow(browserFileListRow_, this);
         }
         }
     }
     }
-    
+
     String ResourceTypeName()
     String ResourceTypeName()
     {
     {
         return ::ResourceTypeName(resourceType);
         return ::ResourceTypeName(resourceType);
@@ -1570,7 +1570,7 @@ class BrowserFile
 void CreateResourcePreview(String path, Node@ previewNode)
 void CreateResourcePreview(String path, Node@ previewNode)
 {
 {
     resourceBrowserPreview.autoUpdate = false;
     resourceBrowserPreview.autoUpdate = false;
-    int resourceType = GetResourceType(path); 
+    int resourceType = GetResourceType(path);
     if (resourceType > 0)
     if (resourceType > 0)
     {
     {
         File file;
         File file;
@@ -1618,12 +1618,12 @@ void CreateResourcePreview(String path, Node@ previewNode)
             {
             {
                 XMLFile xmlFile;
                 XMLFile xmlFile;
                 if(xmlFile.Load(file))
                 if(xmlFile.Load(file))
-                    if(previewNode.LoadXML(xmlFile.root, true) && (previewNode.GetComponents("StaticModel", true).length > 0 || previewNode.GetComponents("AnimatedModel", true).length > 0))
+                    if(previewNode.LoadXML(xmlFile.root) && (previewNode.GetComponents("StaticModel", true).length > 0 || previewNode.GetComponents("AnimatedModel", true).length > 0))
                     {
                     {
                         return;
                         return;
                     }
                     }
             }
             }
-            else if(previewNode.Load(file, true) && (previewNode.GetComponents("StaticModel", true).length > 0 || previewNode.GetComponents("AnimatedModel", true).length > 0))
+            else if(previewNode.Load(file) && (previewNode.GetComponents("StaticModel", true).length > 0 || previewNode.GetComponents("AnimatedModel", true).length > 0))
                 return;
                 return;
 
 
             previewNode.RemoveAllChildren();
             previewNode.RemoveAllChildren();
@@ -1660,7 +1660,7 @@ void RotateResourceBrowserPreview(StringHash eventType, VariantMap& eventData)
 {
 {
     int elemX = eventData["ElementX"].GetInt();
     int elemX = eventData["ElementX"].GetInt();
     int elemY = eventData["ElementY"].GetInt();
     int elemY = eventData["ElementY"].GetInt();
-    
+
     if (resourceBrowserPreview.height > 0 && resourceBrowserPreview.width > 0)
     if (resourceBrowserPreview.height > 0 && resourceBrowserPreview.width > 0)
     {
     {
         float yaw = ((resourceBrowserPreview.height / 2) - elemY) * (90.0 / resourceBrowserPreview.height);
         float yaw = ((resourceBrowserPreview.height / 2) - elemY) * (90.0 / resourceBrowserPreview.height);