CCArmatureDataManager.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /****************************************************************************
  2. Copyright (c) 2013-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  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. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CCARMATUREDATAMANAGER_H__
  21. #define __CCARMATUREDATAMANAGER_H__
  22. #include "editor-support/cocostudio/CCArmatureDefine.h"
  23. #include "editor-support/cocostudio/CCDatas.h"
  24. #include "editor-support/cocostudio/CocosStudioExport.h"
  25. namespace cocostudio {
  26. struct RelativeData
  27. {
  28. std::vector<std::string> plistFiles;
  29. std::vector<std::string> armatures;
  30. std::vector<std::string> animations;
  31. std::vector<std::string> textures;
  32. };
  33. /**
  34. * @brief format and manage armature configuration and armature animation
  35. */
  36. class CC_STUDIO_DLL ArmatureDataManager : public cocos2d::Ref
  37. {
  38. public:
  39. /** @deprecated Use getInstance() instead */
  40. CC_DEPRECATED_ATTRIBUTE static ArmatureDataManager *sharedArmatureDataManager() { return ArmatureDataManager::getInstance(); }
  41. /** @deprecated Use destroyInstance() instead */
  42. CC_DEPRECATED_ATTRIBUTE static void purge() { ArmatureDataManager::destroyInstance(); };
  43. static ArmatureDataManager *getInstance();
  44. static void destroyInstance();
  45. private:
  46. /**
  47. * @js ctor
  48. */
  49. ArmatureDataManager(void);
  50. /**
  51. * @js NA
  52. * @lua NA
  53. */
  54. ~ArmatureDataManager(void);
  55. public:
  56. /**
  57. * Init ArmatureDataManager
  58. */
  59. virtual bool init();
  60. /**
  61. * Add armature data
  62. * @param id The id of the armature data
  63. * @param armatureData ArmatureData *
  64. */
  65. void addArmatureData(const std::string& id, ArmatureData *armatureData, const std::string& configFilePath = "");
  66. /**
  67. * @brief get armature data
  68. * @param id the id of the armature data you want to get
  69. * @return ArmatureData *
  70. */
  71. ArmatureData *getArmatureData(const std::string& id);
  72. /**
  73. * @brief remove armature data
  74. * @param id the id of the armature data you want to get
  75. */
  76. void removeArmatureData(const std::string& id);
  77. /**
  78. * @brief add animation data
  79. * @param id the id of the animation data
  80. * @return AnimationData *
  81. */
  82. void addAnimationData(const std::string& id, AnimationData *animationData, const std::string& configFilePath = "");
  83. /**
  84. * @brief get animation data from _animationDatas(Dictionary)
  85. * @param id the id of the animation data you want to get
  86. * @return AnimationData *
  87. */
  88. AnimationData *getAnimationData(const std::string& id);
  89. /**
  90. * @brief remove animation data
  91. * @param id the id of the animation data
  92. */
  93. void removeAnimationData(const std::string& id);
  94. /**
  95. * @brief add texture data
  96. * @param id the id of the texture data
  97. * @return TextureData *
  98. */
  99. void addTextureData(const std::string& id, TextureData *textureData, const std::string& configFilePath = "");
  100. /**
  101. * @brief get texture data
  102. * @param id the id of the texture data you want to get
  103. * @return TextureData *
  104. */
  105. TextureData *getTextureData(const std::string& id);
  106. /**
  107. * @brief remove texture data
  108. * @param id the id of the texture data you want to get
  109. */
  110. void removeTextureData(const std::string& id);
  111. /**
  112. * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
  113. */
  114. void addArmatureFileInfo(const std::string& configFilePath);
  115. /**
  116. * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
  117. * It will load data in a new thread
  118. */
  119. void addArmatureFileInfoAsync(const std::string& configFilePath, cocos2d::Ref *target, cocos2d::SEL_SCHEDULE selector);
  120. /**
  121. * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
  122. */
  123. void addArmatureFileInfo(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath);
  124. /**
  125. * @brief Add ArmatureFileInfo, it is managed by ArmatureDataManager.
  126. * It will load data in a new thread
  127. */
  128. void addArmatureFileInfoAsync(const std::string& imagePath, const std::string& plistPath, const std::string& configFilePath, cocos2d::Ref *target, cocos2d::SEL_SCHEDULE selector);
  129. /**
  130. * @brief Add sprite frame to CCSpriteFrameCache, it will save display name and it's relative image name
  131. */
  132. void addSpriteFrameFromFile(const std::string& plistPath, const std::string& imagePath, const std::string& configFilePath = "");
  133. virtual void removeArmatureFileInfo(const std::string& configFilePath);
  134. /**
  135. * @brief Judge whether or not need auto load sprite file
  136. */
  137. bool isAutoLoadSpriteFile();
  138. const cocos2d::Map<std::string, ArmatureData*>& getArmatureDatas() const;
  139. const cocos2d::Map<std::string, AnimationData*>& getAnimationDatas() const;
  140. const cocos2d::Map<std::string, TextureData*>& getTextureDatas() const;
  141. protected:
  142. void addRelativeData(const std::string& configFilePath);
  143. RelativeData *getRelativeData(const std::string& configFilePath);
  144. private:
  145. /**
  146. * @brief save armature datas
  147. * @key std::string
  148. * @value ArmatureData *
  149. */
  150. cocos2d::Map<std::string, ArmatureData*> _armarureDatas;
  151. /**
  152. * @brief save animation datas
  153. * @key std::string
  154. * @value AnimationData *
  155. */
  156. cocos2d::Map<std::string, AnimationData*> _animationDatas;
  157. /**
  158. * @brief save texture datas
  159. * @key std::string
  160. * @value TextureData *
  161. */
  162. cocos2d::Map<std::string, TextureData*> _textureDatas;
  163. bool _autoLoadSpriteFile;
  164. std::unordered_map<std::string, RelativeData> _relativeDatas;
  165. };
  166. }
  167. #endif/*__CCARMATUREDATAMANAGER_H__*/