Browse Source

Add resource load and save functions for animations.

Aster Jian 11 years ago
parent
commit
21ddb94b52

+ 19 - 0
Source/Engine/Scene/AttributeAnimation.cpp

@@ -60,6 +60,25 @@ void AttributeAnimation::RegisterObject(Context* context)
     context->RegisterFactory<AttributeAnimation>();
 }
 
+bool AttributeAnimation::Load(Deserializer& source)
+{
+    XMLFile xmlFile(context_);
+    if (!xmlFile.Load(source))
+        return false;
+
+    return LoadXML(xmlFile.GetRoot());
+}
+
+bool AttributeAnimation::Save(Serializer& dest) const
+{
+    XMLFile xmlFile(context_);
+
+    if (!SaveXML(xmlFile.CreateRoot("attributeAnimation")))
+        return false;
+
+    return xmlFile.Save(dest);
+}
+
 bool AttributeAnimation::LoadXML(const XMLElement& source)
 {
     valueType_ = VAR_NONE;

+ 4 - 0
Source/Engine/Scene/AttributeAnimation.h

@@ -75,6 +75,10 @@ public:
     /// Register object factory.
     static void RegisterObject(Context* context);
     
+    /// Load resource. Return true if successful.
+    virtual bool Load(Deserializer& source);
+    /// Save resource. Return true if successful.
+    virtual bool Save(Serializer& dest) const;
     /// Load from XML data. Return true if successful.
     bool LoadXML(const XMLElement& source);
     /// Save as XML data. Return true if successful.

+ 19 - 0
Source/Engine/Scene/ObjectAnimation.cpp

@@ -45,6 +45,25 @@ void ObjectAnimation::RegisterObject(Context* context)
     context->RegisterFactory<ObjectAnimation>();
 }
 
+bool ObjectAnimation::Load(Deserializer& source)
+{
+    XMLFile xmlFile(context_);
+    if (!xmlFile.Load(source))
+        return false;
+
+    return LoadXML(xmlFile.GetRoot());
+}
+
+bool ObjectAnimation::Save(Serializer& dest) const
+{
+    XMLFile xmlFile(context_);
+
+    if (!SaveXML(xmlFile.CreateRoot("objectAnimation")))
+        return false;
+
+    return xmlFile.Save(dest);
+}
+
 bool ObjectAnimation::LoadXML(const XMLElement& source)
 {
     attributeAnimations_.Clear();

+ 4 - 0
Source/Engine/Scene/ObjectAnimation.h

@@ -42,6 +42,10 @@ public:
     /// Register object factory.
     static void RegisterObject(Context* context);
 
+    /// Load resource. Return true if successful.
+    virtual bool Load(Deserializer& source);
+    /// Save resource. Return true if successful.
+    virtual bool Save(Serializer& dest) const;
     /// Load from XML data. Return true if successful.
     bool LoadXML(const XMLElement& source);
     /// Save as XML data. Return true if successful.