CCDatas.cpp 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. #include "editor-support/cocostudio/CCDatas.h"
  21. #include "editor-support/cocostudio/CCUtilMath.h"
  22. #include "editor-support/cocostudio/CCTransformHelp.h"
  23. using namespace cocos2d;
  24. namespace cocostudio {
  25. BaseData::BaseData()
  26. : x(0.0f)
  27. , y(0.0f)
  28. , zOrder(0)
  29. , skewX(0.0f)
  30. , skewY(0.0f)
  31. , scaleX(1.0f)
  32. , scaleY(1.0f)
  33. , tweenRotate(0.0f)
  34. , isUseColorInfo(false)
  35. , a(255)
  36. , r(255)
  37. , g(255)
  38. , b(255)
  39. {
  40. }
  41. BaseData::~BaseData()
  42. {
  43. }
  44. void BaseData::copy(const BaseData *node )
  45. {
  46. x = node->x;
  47. y = node->y;
  48. zOrder = node->zOrder;
  49. scaleX = node->scaleX;
  50. scaleY = node->scaleY;
  51. skewX = node->skewX;
  52. skewY = node->skewY;
  53. tweenRotate = node->tweenRotate;
  54. isUseColorInfo = node->isUseColorInfo;
  55. r = node->r;
  56. g = node->g;
  57. b = node->b;
  58. a = node->a;
  59. }
  60. void BaseData::subtract(BaseData *from, BaseData *to, bool limit)
  61. {
  62. x = to->x - from->x;
  63. y = to->y - from->y;
  64. scaleX = to->scaleX - from->scaleX;
  65. scaleY = to->scaleY - from->scaleY;
  66. skewX = to->skewX - from->skewX;
  67. skewY = to->skewY - from->skewY;
  68. if(isUseColorInfo || from->isUseColorInfo || to->isUseColorInfo)
  69. {
  70. a = to->a - from->a;
  71. r = to->r - from->r;
  72. g = to->g - from->g;
  73. b = to->b - from->b;
  74. isUseColorInfo = true;
  75. }
  76. else
  77. {
  78. a = r = g = b = 0;
  79. isUseColorInfo = false;
  80. }
  81. if (limit)
  82. {
  83. if (skewX > M_PI)
  84. {
  85. skewX -= (float)CC_DOUBLE_PI;
  86. }
  87. if (skewX < -M_PI)
  88. {
  89. skewX += (float)CC_DOUBLE_PI;
  90. }
  91. if (skewY > M_PI)
  92. {
  93. skewY -= (float)CC_DOUBLE_PI;
  94. }
  95. if (skewY < -M_PI)
  96. {
  97. skewY += (float)CC_DOUBLE_PI;
  98. }
  99. }
  100. if (to->tweenRotate)
  101. {
  102. skewX += to->tweenRotate * M_PI * 2;
  103. skewY -= to->tweenRotate * M_PI * 2;
  104. }
  105. }
  106. void BaseData::setColor(const Color4B &color)
  107. {
  108. r = color.r;
  109. g = color.g;
  110. b = color.b;
  111. a = color.a;
  112. }
  113. Color4B BaseData::getColor()
  114. {
  115. return Color4B(r, g, b, a);
  116. }
  117. std::string DisplayData::changeDisplayToTexture(const std::string& displayName)
  118. {
  119. // remove .xxx
  120. std::string textureName = displayName;
  121. size_t startPos = textureName.find_last_of(".");
  122. if(startPos != std::string::npos)
  123. {
  124. textureName = textureName.erase(startPos);
  125. }
  126. return textureName;
  127. }
  128. DisplayData::DisplayData(void)
  129. : displayType(CS_DISPLAY_MAX)
  130. , displayName("")
  131. {
  132. }
  133. void DisplayData::copy(DisplayData *displayData)
  134. {
  135. displayName = displayData->displayName;
  136. displayType = displayData->displayType;
  137. }
  138. SpriteDisplayData::SpriteDisplayData(void)
  139. {
  140. displayType = CS_DISPLAY_SPRITE;
  141. }
  142. void SpriteDisplayData::copy(DisplayData *displayData)
  143. {
  144. DisplayData::copy(displayData);
  145. if (SpriteDisplayData *sdd = dynamic_cast<SpriteDisplayData*>(displayData))
  146. {
  147. skinData = sdd->skinData;
  148. }
  149. }
  150. ArmatureDisplayData::ArmatureDisplayData(void)
  151. {
  152. displayType = CS_DISPLAY_ARMATURE;
  153. }
  154. ParticleDisplayData::ParticleDisplayData(void)
  155. {
  156. displayType = CS_DISPLAY_PARTICLE;
  157. }
  158. BoneData::BoneData(void)
  159. : name("")
  160. , parentName("")
  161. {
  162. }
  163. BoneData::~BoneData(void)
  164. {
  165. }
  166. bool BoneData::init()
  167. {
  168. return true;
  169. }
  170. void BoneData::addDisplayData(DisplayData *displayData)
  171. {
  172. displayDataList.pushBack(displayData);
  173. }
  174. DisplayData *BoneData::getDisplayData(int index)
  175. {
  176. return displayDataList.at(index);
  177. }
  178. ArmatureData::ArmatureData()
  179. : dataVersion(0.1f)
  180. {
  181. }
  182. ArmatureData::~ArmatureData()
  183. {
  184. }
  185. bool ArmatureData::init()
  186. {
  187. return true;
  188. }
  189. void ArmatureData::addBoneData(BoneData *boneData)
  190. {
  191. boneDataDic.insert(boneData->name, boneData);
  192. }
  193. BoneData *ArmatureData::getBoneData(const std::string& boneName)
  194. {
  195. return static_cast<BoneData*>(boneDataDic.at(boneName));
  196. }
  197. FrameData::FrameData(void)
  198. : frameID(0)
  199. , duration(1)
  200. , tweenEasing(cocos2d::tweenfunc::Linear)
  201. , easingParamNumber(0)
  202. , easingParams(nullptr)
  203. , isTween(true)
  204. , displayIndex(0)
  205. , blendFunc(BlendFunc::ALPHA_PREMULTIPLIED)
  206. , strEvent("")
  207. , strMovement("")
  208. , strSound("")
  209. , strSoundEffect("")
  210. {
  211. }
  212. FrameData::~FrameData(void)
  213. {
  214. CC_SAFE_DELETE(easingParams);
  215. }
  216. void FrameData::copy(const BaseData *baseData)
  217. {
  218. BaseData::copy(baseData);
  219. if (const FrameData *frameData = dynamic_cast<const FrameData*>(baseData))
  220. {
  221. duration = frameData->duration;
  222. displayIndex = frameData->displayIndex;
  223. tweenEasing = frameData->tweenEasing;
  224. easingParamNumber = frameData->easingParamNumber;
  225. CC_SAFE_DELETE(easingParams);
  226. if (easingParamNumber != 0)
  227. {
  228. easingParams = new (std::nothrow) float[easingParamNumber];
  229. for (int i = 0; i<easingParamNumber; i++)
  230. {
  231. easingParams[i] = frameData->easingParams[i];
  232. }
  233. }
  234. blendFunc = frameData->blendFunc;
  235. isTween = frameData->isTween;
  236. }
  237. }
  238. MovementBoneData::MovementBoneData()
  239. : delay(0.0f)
  240. , scale(1.0f)
  241. , duration(0)
  242. , name("")
  243. {
  244. }
  245. MovementBoneData::~MovementBoneData(void)
  246. {
  247. }
  248. bool MovementBoneData::init()
  249. {
  250. return true;
  251. }
  252. void MovementBoneData::addFrameData(FrameData *frameData)
  253. {
  254. frameList.pushBack(frameData);
  255. }
  256. FrameData *MovementBoneData::getFrameData(int index)
  257. {
  258. return frameList.at(index);
  259. }
  260. MovementData::MovementData(void)
  261. : name("")
  262. , duration(0)
  263. , scale(1.0f)
  264. , durationTo(0)
  265. , durationTween(0)
  266. , loop(true)
  267. , tweenEasing(cocos2d::tweenfunc::Linear)
  268. {
  269. }
  270. MovementData::~MovementData(void)
  271. {
  272. }
  273. void MovementData::addMovementBoneData(MovementBoneData *movBoneData)
  274. {
  275. movBoneDataDic.insert(movBoneData->name, movBoneData);
  276. }
  277. MovementBoneData *MovementData::getMovementBoneData(const std::string& boneName)
  278. {
  279. return movBoneDataDic.at(boneName);
  280. }
  281. AnimationData::AnimationData(void)
  282. {
  283. }
  284. AnimationData::~AnimationData(void)
  285. {
  286. }
  287. void AnimationData::addMovement(MovementData *movData)
  288. {
  289. movementDataDic.insert(movData->name, movData);
  290. movementNames.push_back(movData->name);
  291. }
  292. MovementData *AnimationData::getMovement(const std::string& movementName)
  293. {
  294. return movementDataDic.at(movementName);
  295. }
  296. ssize_t AnimationData::getMovementCount()
  297. {
  298. return movementDataDic.size();
  299. }
  300. ContourData::ContourData()
  301. {
  302. }
  303. ContourData::~ContourData()
  304. {
  305. }
  306. bool ContourData::init()
  307. {
  308. return true;
  309. }
  310. void ContourData::addVertex(Vec2 &vertex)
  311. {
  312. vertexList.push_back(vertex);
  313. }
  314. TextureData::TextureData()
  315. : height(0.0f)
  316. , width(0.0f)
  317. , pivotX(0.5f)
  318. , pivotY(0.5f)
  319. , name("")
  320. {
  321. }
  322. TextureData::~TextureData()
  323. {
  324. }
  325. bool TextureData::init()
  326. {
  327. return true;
  328. }
  329. void TextureData::addContourData(ContourData *contourData)
  330. {
  331. contourDataList.pushBack(contourData);
  332. }
  333. ContourData *TextureData::getContourData(int index)
  334. {
  335. return contourDataList.at(index);
  336. }
  337. }