ObjectAnimation.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. //
  2. // Copyright (c) 2008-2014 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #include "Precompiled.h"
  23. #include "AttributeAnimation.h"
  24. #include "Context.h"
  25. #include "ObjectAnimation.h"
  26. #include "XMLFile.h"
  27. #include "DebugNew.h"
  28. namespace Urho3D
  29. {
  30. ObjectAnimation::ObjectAnimation(Context* context) :
  31. Resource(context)
  32. {
  33. }
  34. ObjectAnimation::~ObjectAnimation()
  35. {
  36. }
  37. void ObjectAnimation::RegisterObject(Context* context)
  38. {
  39. context->RegisterFactory<ObjectAnimation>();
  40. }
  41. bool ObjectAnimation::Load(Deserializer& source)
  42. {
  43. // Not implement
  44. return false;
  45. }
  46. bool ObjectAnimation::Save(Serializer& dest) const
  47. {
  48. // Not implement
  49. return false;
  50. }
  51. bool ObjectAnimation::LoadXML(const XMLElement& source)
  52. {
  53. if (source.GetName() != "ObjectAnimation")
  54. return false;
  55. XMLElement animElem;
  56. animElem = source.GetChild("AttributeAnimation");
  57. while (animElem)
  58. {
  59. String name = animElem.GetAttribute("name");
  60. SharedPtr<AttributeAnimation> animation(new AttributeAnimation(context_));
  61. if (!animation->LoadXML(animElem))
  62. return false;
  63. AddAttributeAnimation(name, animation);
  64. animElem = animElem.GetNext("AttributeAnimation");
  65. }
  66. return true;
  67. }
  68. bool ObjectAnimation::SaveXML(XMLElement& dest) const
  69. {
  70. if (dest.GetName() != "ObjectAnimation")
  71. return false;
  72. for (HashMap<String, SharedPtr<AttributeAnimation> >::ConstIterator i = attributeAnimations_.Begin(); i != attributeAnimations_.End(); ++i)
  73. {
  74. XMLElement animElem = dest.CreateChild("AttributeAnimation");
  75. animElem.SetAttribute("name", i->first_);
  76. if (!i->second_->SaveXML(animElem))
  77. return false;
  78. }
  79. return true;
  80. }
  81. void ObjectAnimation::AddAttributeAnimation(const String& name, AttributeAnimation* attributeAnimation)
  82. {
  83. if (!attributeAnimation)
  84. return;
  85. attributeAnimation->SetObjectAnimation(this);
  86. attributeAnimations_[name] = attributeAnimation;
  87. }
  88. void ObjectAnimation::RemoveAttributeAnimation(const String& name)
  89. {
  90. RemoveAttributeAnimation(GetAttributeAnimation(name));
  91. }
  92. void ObjectAnimation::RemoveAttributeAnimation(AttributeAnimation* attributeAnimation)
  93. {
  94. if (!attributeAnimation)
  95. return;
  96. for (HashMap<String, SharedPtr<AttributeAnimation> >::Iterator i = attributeAnimations_.Begin(); i != attributeAnimations_.End(); ++i)
  97. {
  98. if (i->second_ == attributeAnimation)
  99. {
  100. attributeAnimation->SetObjectAnimation(0);
  101. attributeAnimations_.Erase(i);
  102. return;
  103. }
  104. }
  105. }
  106. AttributeAnimation* ObjectAnimation::GetAttributeAnimation(const String& name) const
  107. {
  108. HashMap<String, SharedPtr<AttributeAnimation> >::ConstIterator i = attributeAnimations_.Find(name);
  109. if (i != attributeAnimations_.End())
  110. return i->second_;
  111. return 0;
  112. }
  113. }