AnimationSet2D.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // Copyright (c) 2008-2020 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 URHO3D_SPINE
  26. struct spAtlas;
  27. struct spSkeletonData;
  28. struct spAnimationStateData;
  29. #endif
  30. namespace Urho3D
  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 URHO3D_API AnimationSet2D : public Resource
  40. {
  41. URHO3D_OBJECT(AnimationSet2D, Resource);
  42. public:
  43. /// Construct.
  44. explicit AnimationSet2D(Context* context);
  45. /// Destruct.
  46. ~AnimationSet2D() override;
  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. bool BeginLoad(Deserializer& source) override;
  51. /// Finish resource loading. Always called from the main thread. Return true if successful.
  52. bool EndLoad() override;
  53. /// Get number of animations.
  54. /// @property
  55. unsigned GetNumAnimations() const;
  56. /// Return animation name.
  57. String GetAnimation(unsigned index) const;
  58. /// Check has animation.
  59. bool HasAnimation(const String& animationName) const;
  60. /// Return sprite.
  61. Sprite2D* GetSprite() const;
  62. #ifdef URHO3D_SPINE
  63. /// Return spine skeleton data.
  64. spSkeletonData* GetSkeletonData() const { return skeletonData_; }
  65. #endif
  66. /// Return spriter data.
  67. Spriter::SpriterData* GetSpriterData() const { return spriterData_.Get(); }
  68. /// Return spriter file sprite.
  69. Sprite2D* GetSpriterFileSprite(int folderId, int fileId) const;
  70. private:
  71. /// Return sprite by hash.
  72. Sprite2D* GetSpriterFileSprite(const StringHash& hash) const;
  73. #ifdef URHO3D_SPINE
  74. /// Begin load spine.
  75. bool BeginLoadSpine(Deserializer& source);
  76. /// Finish load spine.
  77. bool EndLoadSpine();
  78. #endif
  79. /// Begin load scml.
  80. bool BeginLoadSpriter(Deserializer& source);
  81. /// Finish load scml.
  82. bool EndLoadSpriter();
  83. /// Dispose all data.
  84. void Dispose();
  85. /// Spine sprite.
  86. SharedPtr<Sprite2D> sprite_;
  87. #ifdef URHO3D_SPINE
  88. /// Spine json data.
  89. SharedArrayPtr<char> jsonData_;
  90. /// Spine skeleton data.
  91. spSkeletonData* skeletonData_;
  92. /// Spine atlas.
  93. spAtlas* atlas_;
  94. #endif
  95. /// Spriter data.
  96. UniquePtr<Spriter::SpriterData> spriterData_;
  97. /// Has sprite sheet.
  98. bool hasSpriteSheet_;
  99. /// Sprite sheet file path.
  100. String spriteSheetFilePath_;
  101. /// Sprite sheet.
  102. SharedPtr<SpriteSheet2D> spriteSheet_;
  103. /// Spriter sprites.
  104. HashMap<unsigned, SharedPtr<Sprite2D> > spriterFileSprites_;
  105. };
  106. }