AnimationSet2D.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //
  2. // Copyright (c) 2008-2017 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. #pragma once
  23. #include "../Container/ArrayPtr.h"
  24. #include "../Resource/Resource.h"
  25. #ifdef ATOMIC_SPINE
  26. struct spAtlas;
  27. struct spSkeletonData;
  28. struct spAnimationStateData;
  29. #endif
  30. namespace Atomic
  31. {
  32. namespace Spriter
  33. {
  34. struct SpriterData;
  35. }
  36. class Sprite2D;
  37. class SpriteSheet2D;
  38. /// Spriter animation set, it includes one or more animations, for more information please refer to http://www.esotericsoftware.com and http://www.brashmonkey.com/spriter.htm.
  39. class ATOMIC_API AnimationSet2D : public Resource
  40. {
  41. ATOMIC_OBJECT(AnimationSet2D, Resource);
  42. public:
  43. /// Construct.
  44. AnimationSet2D(Context* context);
  45. /// Destruct.
  46. virtual ~AnimationSet2D();
  47. /// Register object factory.
  48. static void RegisterObject(Context* context);
  49. /// Load resource from stream. May be called from a worker thread. Return true if successful.
  50. virtual bool BeginLoad(Deserializer& source);
  51. /// Finish resource loading. Always called from the main thread. Return true if successful.
  52. virtual bool EndLoad();
  53. /// Get number of animations.
  54. unsigned GetNumAnimations() const;
  55. /// Return animation name.
  56. String GetAnimation(unsigned index) const;
  57. /// Check has animation.
  58. bool HasAnimation(const String& animation) const;
  59. /// Return sprite.
  60. Sprite2D* GetSprite() const;
  61. #ifdef ATOMIC_SPINE
  62. /// Return spine skeleton data.
  63. spSkeletonData* GetSkeletonData() const { return skeletonData_; }
  64. #endif
  65. /// Return spriter data.
  66. Spriter::SpriterData* GetSpriterData() const { return spriterData_.Get(); }
  67. /// Return spriter file sprite.
  68. Sprite2D* GetSpriterFileSprite(int folderId, int fileId) const;
  69. private:
  70. /// Return sprite by hash.
  71. Sprite2D* GetSpriterFileSprite(const StringHash& hash) const;
  72. #ifdef ATOMIC_SPINE
  73. /// Begin load spine.
  74. bool BeginLoadSpine(Deserializer& source);
  75. /// Finish load spine.
  76. bool EndLoadSpine();
  77. #endif
  78. /// Begin load scml.
  79. bool BeginLoadSpriter(Deserializer& source);
  80. /// Finish load scml.
  81. bool EndLoadSpriter();
  82. /// Dispose all data.
  83. void Dispose();
  84. /// Spine sprite.
  85. SharedPtr<Sprite2D> sprite_;
  86. #ifdef ATOMIC_SPINE
  87. /// Spine json data.
  88. SharedArrayPtr<char> jsonData_;
  89. /// Spine skeleton data.
  90. spSkeletonData* skeletonData_;
  91. /// Spine atlas.
  92. spAtlas* atlas_;
  93. #endif
  94. /// Spriter data.
  95. UniquePtr<Spriter::SpriterData> spriterData_;
  96. /// Has sprite sheet.
  97. bool hasSpriteSheet_;
  98. /// Sprite sheet file path.
  99. String spriteSheetFilePath_;
  100. /// Sprite sheet.
  101. SharedPtr<SpriteSheet2D> spriteSheet_;
  102. /// Spriter sprites.
  103. HashMap<int, SharedPtr<Sprite2D> > spriterFileSprites_;
  104. };
  105. }