CCNodeLoader.cpp 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194
  1. /****************************************************************************
  2. Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
  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/cocosbuilder/CCNodeLoader.h"
  21. #include "editor-support/cocosbuilder/CCBSelectorResolver.h"
  22. #include "editor-support/cocosbuilder/CCBMemberVariableAssigner.h"
  23. #include "editor-support/cocosbuilder/CCBAnimationManager.h"
  24. #include "editor-support/cocosbuilder/CCNode+CCBRelativePositioning.h"
  25. #include "deprecated/CCArray.h"
  26. #include "deprecated/CCString.h"
  27. #include "base/CCDirector.h"
  28. #include "renderer/CCTextureCache.h"
  29. #include "2d/CCSpriteFrameCache.h"
  30. #include "2d/CCAnimationCache.h"
  31. #include "platform/CCFileUtils.h"
  32. using namespace std;
  33. using namespace cocos2d;
  34. using namespace cocos2d::extension;
  35. namespace cocosbuilder {
  36. NodeLoader::NodeLoader()
  37. {
  38. }
  39. NodeLoader::~NodeLoader()
  40. {
  41. }
  42. ValueMap& NodeLoader::getCustomProperties()
  43. {
  44. return _customProperties;
  45. }
  46. Node * NodeLoader::loadNode(Node * pParent, CCBReader * ccbReader)
  47. {
  48. Node * ccNode = this->createNode(pParent, ccbReader);
  49. //clear _customProperties, ready for load next node.
  50. _customProperties.clear();
  51. return ccNode;
  52. }
  53. void NodeLoader::parseProperties(Node * pNode, Node * pParent, CCBReader * ccbReader)
  54. {
  55. int numRegularProps = ccbReader->readInt(false);
  56. int numExturaProps = ccbReader->readInt(false);
  57. int propertyCount = numRegularProps + numExturaProps;
  58. for(int i = 0; i < propertyCount; i++) {
  59. bool isExtraProp = (i >= numRegularProps);
  60. CCBReader::PropertyType type = (CCBReader::PropertyType)ccbReader->readInt(false);
  61. std::string propertyName = ccbReader->readCachedString();
  62. // Check if the property can be set for this platform
  63. bool setProp = false;
  64. CCBReader::PlatformType platform = (CCBReader::PlatformType)ccbReader->readByte();
  65. if(platform == CCBReader::PlatformType::ALL)
  66. {
  67. setProp = true;
  68. }
  69. // Cocos2d-x is using touch event callback for all platforms,
  70. // it's different from cocos2d-iphone which uses mouse event for Mac port.
  71. // So we just need to touch event by using CCBReader::PlatformType::IOS.
  72. //#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS) || (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
  73. if(platform == CCBReader::PlatformType::IOS)
  74. {
  75. setProp = true;
  76. }
  77. // #elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC)
  78. // if(platform == CCBReader::PlatformType::MAC)
  79. // {
  80. // setProp = true;
  81. // }
  82. // #endif
  83. // Forward properties for sub ccb files
  84. if (dynamic_cast<CCBFile*>(pNode) != nullptr)
  85. {
  86. CCBFile *ccbNode = (CCBFile*)pNode;
  87. if (ccbNode->getCCBFileNode() && isExtraProp)
  88. {
  89. pNode = ccbNode->getCCBFileNode();
  90. // Skip properties that doesn't have a value to override
  91. __Array *extraPropsNames = (__Array*)pNode->getUserObject();
  92. Ref* pObj = nullptr;
  93. bool bFound = false;
  94. CCARRAY_FOREACH(extraPropsNames, pObj)
  95. {
  96. __String* pStr = static_cast<__String*>(pObj);
  97. if (0 == pStr->compare(propertyName.c_str()))
  98. {
  99. bFound = true;
  100. break;
  101. }
  102. }
  103. setProp &= bFound;
  104. }
  105. }
  106. else if (isExtraProp && pNode == ccbReader->getAnimationManager()->getRootNode())
  107. {
  108. __Array *extraPropsNames = static_cast<__Array*>(pNode->getUserObject());
  109. if (! extraPropsNames)
  110. {
  111. extraPropsNames = __Array::create();
  112. pNode->setUserObject(extraPropsNames);
  113. }
  114. extraPropsNames->addObject(__String::create(propertyName));
  115. }
  116. switch(type)
  117. {
  118. case CCBReader::PropertyType::POSITION:
  119. {
  120. Vec2 position = this->parsePropTypePosition(pNode, pParent, ccbReader, propertyName.c_str());
  121. if (setProp)
  122. {
  123. this->onHandlePropTypePosition(pNode, pParent, propertyName.c_str(), position, ccbReader);
  124. }
  125. break;
  126. }
  127. case CCBReader::PropertyType::POINT:
  128. {
  129. Vec2 point = this->parsePropTypePoint(pNode, pParent, ccbReader);
  130. if (setProp)
  131. {
  132. this->onHandlePropTypePoint(pNode, pParent, propertyName.c_str(), point, ccbReader);
  133. }
  134. break;
  135. }
  136. case CCBReader::PropertyType::POINT_LOCK:
  137. {
  138. Vec2 pointLock = this->parsePropTypePointLock(pNode, pParent, ccbReader);
  139. if (setProp)
  140. {
  141. this->onHandlePropTypePointLock(pNode, pParent, propertyName.c_str(), pointLock, ccbReader);
  142. }
  143. break;
  144. }
  145. case CCBReader::PropertyType::SIZE:
  146. {
  147. Size size = this->parsePropTypeSize(pNode, pParent, ccbReader);
  148. if(setProp) {
  149. this->onHandlePropTypeSize(pNode, pParent, propertyName.c_str(), size, ccbReader);
  150. }
  151. break;
  152. }
  153. case CCBReader::PropertyType::SCALE_LOCK:
  154. {
  155. float * scaleLock = this->parsePropTypeScaleLock(pNode, pParent, ccbReader, propertyName.c_str());
  156. if(setProp)
  157. {
  158. this->onHandlePropTypeScaleLock(pNode, pParent, propertyName.c_str(), scaleLock, ccbReader);
  159. }
  160. CC_SAFE_DELETE_ARRAY(scaleLock);
  161. break;
  162. }
  163. case CCBReader::PropertyType::FLOAT:
  164. {
  165. float f = this->parsePropTypeFloat(pNode, pParent, ccbReader);
  166. if(setProp)
  167. {
  168. this->onHandlePropTypeFloat(pNode, pParent, propertyName.c_str(), f, ccbReader);
  169. }
  170. break;
  171. }
  172. case CCBReader::PropertyType::FLOAT_XY:
  173. {
  174. float * xy = this->parsePropTypeFloatXY(pNode, pParent, ccbReader);
  175. if(setProp)
  176. {
  177. this->onHandlePropTypeFloatXY(pNode, pParent, propertyName.c_str(), xy, ccbReader);
  178. }
  179. CC_SAFE_DELETE_ARRAY(xy);
  180. break;
  181. }
  182. case CCBReader::PropertyType::DEGREES:
  183. {
  184. float degrees = this->parsePropTypeDegrees(pNode, pParent, ccbReader, propertyName.c_str());
  185. if(setProp)
  186. {
  187. this->onHandlePropTypeDegrees(pNode, pParent, propertyName.c_str(), degrees, ccbReader);
  188. }
  189. break;
  190. }
  191. case CCBReader::PropertyType::FLOAT_SCALE:
  192. {
  193. float floatScale = this->parsePropTypeFloatScale(pNode, pParent, ccbReader);
  194. if(setProp)
  195. {
  196. this->onHandlePropTypeFloatScale(pNode, pParent, propertyName.c_str(), floatScale, ccbReader);
  197. }
  198. break;
  199. }
  200. case CCBReader::PropertyType::INTEGER:
  201. {
  202. int integer = this->parsePropTypeInteger(pNode, pParent, ccbReader);
  203. if(setProp)
  204. {
  205. this->onHandlePropTypeInteger(pNode, pParent, propertyName.c_str(), integer, ccbReader);
  206. }
  207. break;
  208. }
  209. case CCBReader::PropertyType::INTEGER_LABELED:
  210. {
  211. int integerLabeled = this->parsePropTypeIntegerLabeled(pNode, pParent, ccbReader);
  212. if(setProp)
  213. {
  214. this->onHandlePropTypeIntegerLabeled(pNode, pParent, propertyName.c_str(), integerLabeled, ccbReader);
  215. }
  216. break;
  217. }
  218. case CCBReader::PropertyType::FLOAT_VAR:
  219. {
  220. float * floatVar = this->parsePropTypeFloatVar(pNode, pParent, ccbReader);
  221. if(setProp)
  222. {
  223. this->onHandlePropTypeFloatVar(pNode, pParent, propertyName.c_str(), floatVar, ccbReader);
  224. }
  225. CC_SAFE_DELETE_ARRAY(floatVar);
  226. break;
  227. }
  228. case CCBReader::PropertyType::CHECK:
  229. {
  230. bool check = this->parsePropTypeCheck(pNode, pParent, ccbReader, propertyName.c_str());
  231. if(setProp)
  232. {
  233. this->onHandlePropTypeCheck(pNode, pParent, propertyName.c_str(), check, ccbReader);
  234. }
  235. break;
  236. }
  237. case CCBReader::PropertyType::SPRITEFRAME:
  238. {
  239. SpriteFrame * ccSpriteFrame = this->parsePropTypeSpriteFrame(pNode, pParent, ccbReader, propertyName.c_str());
  240. if(setProp)
  241. {
  242. this->onHandlePropTypeSpriteFrame(pNode, pParent, propertyName.c_str(), ccSpriteFrame, ccbReader);
  243. }
  244. break;
  245. }
  246. case CCBReader::PropertyType::ANIMATION:
  247. {
  248. Animation * ccAnimation = this->parsePropTypeAnimation(pNode, pParent, ccbReader);
  249. if(setProp)
  250. {
  251. this->onHandlePropTypeAnimation(pNode, pParent, propertyName.c_str(), ccAnimation, ccbReader);
  252. }
  253. break;
  254. }
  255. case CCBReader::PropertyType::TEXTURE:
  256. {
  257. Texture2D * ccTexture2D = this->parsePropTypeTexture(pNode, pParent, ccbReader);
  258. if(setProp)
  259. {
  260. this->onHandlePropTypeTexture(pNode, pParent, propertyName.c_str(), ccTexture2D, ccbReader);
  261. }
  262. break;
  263. }
  264. case CCBReader::PropertyType::BYTE:
  265. {
  266. unsigned char byte = this->parsePropTypeByte(pNode, pParent, ccbReader, propertyName.c_str());
  267. if(setProp)
  268. {
  269. this->onHandlePropTypeByte(pNode, pParent, propertyName.c_str(), byte, ccbReader);
  270. }
  271. break;
  272. }
  273. case CCBReader::PropertyType::COLOR3:
  274. {
  275. Color3B color3B = this->parsePropTypeColor3(pNode, pParent, ccbReader, propertyName.c_str());
  276. if(setProp)
  277. {
  278. this->onHandlePropTypeColor3(pNode, pParent, propertyName.c_str(), color3B, ccbReader);
  279. }
  280. break;
  281. }
  282. case CCBReader::PropertyType::COLOR4F_VAR:
  283. {
  284. Color4F * color4FVar = this->parsePropTypeColor4FVar(pNode, pParent, ccbReader);
  285. if(setProp)
  286. {
  287. this->onHandlePropTypeColor4FVar(pNode, pParent, propertyName.c_str(), color4FVar, ccbReader);
  288. }
  289. CC_SAFE_DELETE_ARRAY(color4FVar);
  290. break;
  291. }
  292. case CCBReader::PropertyType::FLIP:
  293. {
  294. bool * flip = this->parsePropTypeFlip(pNode, pParent, ccbReader);
  295. if(setProp) {
  296. this->onHandlePropTypeFlip(pNode, pParent, propertyName.c_str(), flip, ccbReader);
  297. }
  298. CC_SAFE_DELETE_ARRAY(flip);
  299. break;
  300. }
  301. case CCBReader::PropertyType::BLEND_MODE:
  302. {
  303. BlendFunc blendFunc = this->parsePropTypeBlendFunc(pNode, pParent, ccbReader);
  304. if(setProp)
  305. {
  306. this->onHandlePropTypeBlendFunc(pNode, pParent, propertyName.c_str(), blendFunc, ccbReader);
  307. }
  308. break;
  309. }
  310. case CCBReader::PropertyType::FNT_FILE:
  311. {
  312. std::string fntFile = ccbReader->getCCBRootPath() + this->parsePropTypeFntFile(pNode, pParent, ccbReader);
  313. if(setProp)
  314. {
  315. this->onHandlePropTypeFntFile(pNode, pParent, propertyName.c_str(), fntFile.c_str(), ccbReader);
  316. }
  317. break;
  318. }
  319. case CCBReader::PropertyType::FONT_TTF:
  320. {
  321. std::string fontTTF = this->parsePropTypeFontTTF(pNode, pParent, ccbReader);
  322. if(setProp) {
  323. this->onHandlePropTypeFontTTF(pNode, pParent, propertyName.c_str(), fontTTF.c_str(), ccbReader);
  324. }
  325. break;
  326. }
  327. case CCBReader::PropertyType::STRING:
  328. {
  329. std::string string = this->parsePropTypeString(pNode, pParent, ccbReader);
  330. if(setProp) {
  331. this->onHandlePropTypeString(pNode, pParent, propertyName.c_str(), string.c_str(), ccbReader);
  332. }
  333. break;
  334. }
  335. case CCBReader::PropertyType::TEXT:
  336. {
  337. std::string text = this->parsePropTypeText(pNode, pParent, ccbReader);
  338. if(setProp) {
  339. this->onHandlePropTypeText(pNode, pParent, propertyName.c_str(), text.c_str(), ccbReader);
  340. }
  341. break;
  342. }
  343. case CCBReader::PropertyType::BLOCK:
  344. {
  345. BlockData * blockData = this->parsePropTypeBlock(pNode, pParent, ccbReader);
  346. if(setProp) {
  347. this->onHandlePropTypeBlock(pNode, pParent, propertyName.c_str(), blockData, ccbReader);
  348. }
  349. CC_SAFE_DELETE(blockData);
  350. break;
  351. }
  352. case CCBReader::PropertyType::BLOCK_CONTROL:
  353. {
  354. BlockControlData * blockControlData = this->parsePropTypeBlockControl(pNode, pParent, ccbReader);
  355. if(setProp && blockControlData != nullptr) {
  356. this->onHandlePropTypeBlockControl(pNode, pParent, propertyName.c_str(), blockControlData, ccbReader);
  357. }
  358. CC_SAFE_DELETE(blockControlData);
  359. break;
  360. }
  361. case CCBReader::PropertyType::CCB_FILE:
  362. {
  363. Node * ccbFileNode = this->parsePropTypeCCBFile(pNode, pParent, ccbReader);
  364. if(setProp) {
  365. this->onHandlePropTypeCCBFile(pNode, pParent, propertyName.c_str(), ccbFileNode, ccbReader);
  366. }
  367. break;
  368. }
  369. default:
  370. ASSERT_FAIL_UNEXPECTED_PROPERTYTYPE(static_cast<int>(type));
  371. break;
  372. }
  373. }
  374. }
  375. Vec2 NodeLoader::parsePropTypePosition(Node * pNode, Node * pParent, CCBReader * ccbReader, const char *pPropertyName)
  376. {
  377. float x = ccbReader->readFloat();
  378. float y = ccbReader->readFloat();
  379. CCBReader::PositionType type = static_cast<CCBReader::PositionType>(ccbReader->readInt(false));
  380. Size containerSize = ccbReader->getAnimationManager()->getContainerSize(pParent);
  381. Vec2 pt = getAbsolutePosition(Vec2(x,y), type, containerSize, pPropertyName);
  382. pNode->setPosition(pt);
  383. if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
  384. {
  385. ValueVector vec;
  386. vec.push_back(Value(x));
  387. vec.push_back(Value(y));
  388. vec.push_back(Value((int)type));
  389. ccbReader->getAnimationManager()->setBaseValue(Value(vec), pNode, pPropertyName);
  390. }
  391. return pt;
  392. }
  393. Vec2 NodeLoader::parsePropTypePoint(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader)
  394. {
  395. float x = ccbReader->readFloat();
  396. float y = ccbReader->readFloat();
  397. return Vec2(x, y);
  398. }
  399. Vec2 NodeLoader::parsePropTypePointLock(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader) {
  400. float x = ccbReader->readFloat();
  401. float y = ccbReader->readFloat();
  402. return Vec2(x, y);
  403. }
  404. Size NodeLoader::parsePropTypeSize(Node * /*pNode*/, Node * pParent, CCBReader * ccbReader) {
  405. float width = ccbReader->readFloat();
  406. float height = ccbReader->readFloat();
  407. CCBReader::SizeType type = static_cast<CCBReader::SizeType>(ccbReader->readInt(false));
  408. Size containerSize = ccbReader->getAnimationManager()->getContainerSize(pParent);
  409. switch (type)
  410. {
  411. case CCBReader::SizeType::ABSOLUTE:
  412. {
  413. /* Nothing. */
  414. break;
  415. }
  416. case CCBReader::SizeType::RELATIVE_CONTAINER:
  417. {
  418. width = containerSize.width - width;
  419. height = containerSize.height - height;
  420. break;
  421. }
  422. case CCBReader::SizeType::PERCENT:
  423. {
  424. width = (int)(containerSize.width * width / 100.0f);
  425. height = (int)(containerSize.height * height / 100.0f);
  426. break;
  427. }
  428. case CCBReader::SizeType::HORIZONTAL_PERCENT:
  429. {
  430. width = (int)(containerSize.width * width / 100.0f);
  431. break;
  432. }
  433. case CCBReader::SizeType::VERTICAL_PERCENT:
  434. {
  435. height = (int)(containerSize.height * height / 100.0f);
  436. break;
  437. }
  438. case CCBReader::SizeType::MULTIPLY_RESOLUTION:
  439. {
  440. float resolutionScale = CCBReader::getResolutionScale();
  441. width *= resolutionScale;
  442. height *= resolutionScale;
  443. break;
  444. }
  445. default:
  446. {
  447. log("Unknown CCB type.");
  448. }
  449. break;
  450. }
  451. return Size(width, height);
  452. }
  453. float * NodeLoader::parsePropTypeFloatXY(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader) {
  454. float x = ccbReader->readFloat();
  455. float y = ccbReader->readFloat();
  456. float * floatXY = new (std::nothrow) float[2];
  457. floatXY[0] = x;
  458. floatXY[1] = y;
  459. return floatXY;
  460. }
  461. float * NodeLoader::parsePropTypeScaleLock(Node * pNode, Node * /*pParent*/, CCBReader * ccbReader, const char *pPropertyName) {
  462. float x = ccbReader->readFloat();
  463. float y = ccbReader->readFloat();
  464. CCBReader::ScaleType type = static_cast<CCBReader::ScaleType>(ccbReader->readInt(false));
  465. setRelativeScale(pNode, x, y, type, pPropertyName);
  466. if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
  467. {
  468. ValueVector baseValue;
  469. baseValue.push_back(Value(x));
  470. baseValue.push_back(Value(y));
  471. baseValue.push_back(Value((int)type));
  472. ccbReader->getAnimationManager()->setBaseValue(Value(baseValue), pNode, pPropertyName);
  473. }
  474. if (type == CCBReader::ScaleType::MULTIPLY_RESOLUTION)
  475. {
  476. x *= ccbReader->getResolutionScale();
  477. y *= ccbReader->getResolutionScale();
  478. }
  479. float * scaleLock = new (std::nothrow) float[2];
  480. scaleLock[0] = x;
  481. scaleLock[1] = y;
  482. return scaleLock;
  483. }
  484. float NodeLoader::parsePropTypeFloat(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader) {
  485. return ccbReader->readFloat();
  486. }
  487. float NodeLoader::parsePropTypeDegrees(Node * pNode, Node * /*pParent*/, CCBReader * ccbReader, const char *pPropertyName) {
  488. float ret = ccbReader->readFloat();
  489. if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
  490. {
  491. ccbReader->getAnimationManager()->setBaseValue(Value(ret), pNode, pPropertyName);
  492. }
  493. return ret;
  494. }
  495. float NodeLoader::parsePropTypeFloatScale(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader)
  496. {
  497. float f = ccbReader->readFloat();
  498. CCBReader::ScaleType type = static_cast<CCBReader::ScaleType>(ccbReader->readInt(false));
  499. if(type == CCBReader::ScaleType::MULTIPLY_RESOLUTION)
  500. {
  501. f *= ccbReader->getResolutionScale();
  502. }
  503. return f;
  504. }
  505. int NodeLoader::parsePropTypeInteger(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader)
  506. {
  507. return ccbReader->readInt(true);
  508. }
  509. int NodeLoader::parsePropTypeIntegerLabeled(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader)
  510. {
  511. return ccbReader->readInt(true);
  512. }
  513. float * NodeLoader::parsePropTypeFloatVar(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader)
  514. {
  515. float f = ccbReader->readFloat();
  516. float fVar = ccbReader->readFloat();
  517. float * arr = new (std::nothrow) float[2];
  518. arr[0] = f;
  519. arr[1] = fVar;
  520. return arr;
  521. }
  522. bool NodeLoader::parsePropTypeCheck(Node * pNode, Node * /*pParent*/, CCBReader * ccbReader, const char *pPropertyName)
  523. {
  524. bool ret = ccbReader->readBool();
  525. if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
  526. {
  527. ccbReader->getAnimationManager()->setBaseValue(Value(ret), pNode, pPropertyName);
  528. }
  529. return ret;
  530. }
  531. SpriteFrame * NodeLoader::parsePropTypeSpriteFrame(Node * pNode, Node * /*pParent*/, CCBReader * ccbReader, const char *pPropertyName)
  532. {
  533. std::string spriteSheet = ccbReader->readCachedString();
  534. std::string spriteFile = ccbReader->readCachedString();
  535. SpriteFrame *spriteFrame = nullptr;
  536. if (!spriteFile.empty())
  537. {
  538. if (spriteSheet.empty())
  539. {
  540. spriteFile = ccbReader->getCCBRootPath() + spriteFile;
  541. Texture2D * texture = Director::getInstance()->getTextureCache()->addImage(spriteFile);
  542. if(texture != nullptr) {
  543. Rect bounds = Rect(0, 0, texture->getContentSize().width, texture->getContentSize().height);
  544. spriteFrame = SpriteFrame::createWithTexture(texture, bounds);
  545. }
  546. }
  547. else
  548. {
  549. SpriteFrameCache * frameCache = SpriteFrameCache::getInstance();
  550. spriteSheet = ccbReader->getCCBRootPath() + spriteSheet;
  551. // Load the sprite sheet only if it is not loaded
  552. if (ccbReader->getLoadedSpriteSheet().find(spriteSheet) == ccbReader->getLoadedSpriteSheet().end())
  553. {
  554. frameCache->addSpriteFramesWithFile(spriteSheet);
  555. ccbReader->getLoadedSpriteSheet().insert(spriteSheet);
  556. }
  557. spriteFrame = frameCache->getSpriteFrameByName(spriteFile);
  558. }
  559. if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
  560. {
  561. ccbReader->getAnimationManager()->setObject(spriteFrame, pNode, pPropertyName);
  562. }
  563. }
  564. return spriteFrame;
  565. }
  566. Animation * NodeLoader::parsePropTypeAnimation(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader) {
  567. std::string animationFile = ccbReader->getCCBRootPath() + ccbReader->readCachedString();
  568. std::string animation = ccbReader->readCachedString();
  569. Animation * ccAnimation = nullptr;
  570. // Support for stripping relative file paths, since ios doesn't currently
  571. // know what to do with them, since its pulling from bundle.
  572. // Eventually this should be handled by a client side asset manager
  573. // interface which figured out what resources to load.
  574. // TODO: Does this problem exist in C++?
  575. animation = CCBReader::lastPathComponent(animation.c_str());
  576. animationFile = CCBReader::lastPathComponent(animationFile.c_str());
  577. if (!animation.empty())
  578. {
  579. AnimationCache * animationCache = AnimationCache::getInstance();
  580. animationCache->addAnimationsWithFile(animationFile);
  581. ccAnimation = animationCache->getAnimation(animation);
  582. }
  583. return ccAnimation;
  584. }
  585. Texture2D * NodeLoader::parsePropTypeTexture(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader) {
  586. std::string spriteFile = ccbReader->getCCBRootPath() + ccbReader->readCachedString();
  587. if (!spriteFile.empty())
  588. {
  589. return Director::getInstance()->getTextureCache()->addImage(spriteFile);
  590. }
  591. else
  592. {
  593. return nullptr;
  594. }
  595. }
  596. unsigned char NodeLoader::parsePropTypeByte(Node * pNode, Node * /*pParent*/, CCBReader * ccbReader, const char *pPropertyName)
  597. {
  598. unsigned char ret = ccbReader->readByte();
  599. if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
  600. {
  601. ccbReader->getAnimationManager()->setBaseValue(Value(ret), pNode, pPropertyName);
  602. }
  603. return ret;
  604. }
  605. Color3B NodeLoader::parsePropTypeColor3(Node * pNode, Node * /*pParent*/, CCBReader * ccbReader, const char *pPropertyName) {
  606. unsigned char r = ccbReader->readByte();
  607. unsigned char g = ccbReader->readByte();
  608. unsigned char b = ccbReader->readByte();
  609. Color3B color(r, g, b);
  610. ValueMap colorMap;
  611. colorMap["r"] = r;
  612. colorMap["g"] = g;
  613. colorMap["b"] = b;
  614. if (ccbReader->getAnimatedProperties()->find(pPropertyName) != ccbReader->getAnimatedProperties()->end())
  615. {
  616. ccbReader->getAnimationManager()->setBaseValue(Value(colorMap), pNode, pPropertyName);
  617. }
  618. return color;
  619. }
  620. Color4F * NodeLoader::parsePropTypeColor4FVar(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader) {
  621. float red = ccbReader->readFloat();
  622. float green = ccbReader->readFloat();
  623. float blue = ccbReader->readFloat();
  624. float alpha = ccbReader->readFloat();
  625. float redVar = ccbReader->readFloat();
  626. float greenVar = ccbReader->readFloat();
  627. float blueVar = ccbReader->readFloat();
  628. float alphaVar = ccbReader->readFloat();
  629. Color4F * colors = new (std::nothrow) Color4F[2];
  630. colors[0].r = red;
  631. colors[0].g = green;
  632. colors[0].b = blue;
  633. colors[0].a = alpha;
  634. colors[1].r = redVar;
  635. colors[1].g = greenVar;
  636. colors[1].b = blueVar;
  637. colors[1].a = alphaVar;
  638. return colors;
  639. }
  640. bool * NodeLoader::parsePropTypeFlip(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader) {
  641. bool flipX = ccbReader->readBool();
  642. bool flipY = ccbReader->readBool();
  643. bool * arr = new (std::nothrow) bool[2];
  644. arr[0] = flipX;
  645. arr[1] = flipY;
  646. return arr;
  647. }
  648. BlendFunc NodeLoader::parsePropTypeBlendFunc(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader)
  649. {
  650. int source = ccbReader->readInt(false);
  651. int destination = ccbReader->readInt(false);
  652. BlendFunc blendFunc;
  653. blendFunc.src = source;
  654. blendFunc.dst = destination;
  655. return blendFunc;
  656. }
  657. std::string NodeLoader::parsePropTypeFntFile(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader)
  658. {
  659. return ccbReader->readCachedString();
  660. }
  661. std::string NodeLoader::parsePropTypeString(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader) {
  662. return ccbReader->readCachedString();
  663. }
  664. std::string NodeLoader::parsePropTypeText(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader) {
  665. return ccbReader->readCachedString();
  666. }
  667. std::string NodeLoader::parsePropTypeFontTTF(Node * /*pNode*/, Node * /*pParent*/, CCBReader * ccbReader) {
  668. std::string fontTTF = ccbReader->readCachedString();
  669. // String * ttfEnding = String::create(".ttf");
  670. // TODO: Fix me if it is wrong
  671. /* If the fontTTF comes with the ".ttf" extension, prepend the absolute path.
  672. * System fonts come without the ".ttf" extension and do not need the path prepended. */
  673. /*
  674. if(CCBReader::endsWith(CCBReader::toLowerCase(fontTTF), ttfEnding)){
  675. fontTTF = CCBReader::concat(ccbReader->getCCBRootPath(), fontTTF);
  676. }
  677. */
  678. return fontTTF;
  679. }
  680. BlockData * NodeLoader::parsePropTypeBlock(Node * pNode, Node * /*pParent*/, CCBReader * ccbReader)
  681. {
  682. std::string selectorName = ccbReader->readCachedString();
  683. CCBReader::TargetType selectorTarget = static_cast<CCBReader::TargetType>(ccbReader->readInt(false));
  684. if(selectorTarget != CCBReader::TargetType::NONE)
  685. {
  686. Ref* target = nullptr;
  687. if(!ccbReader->isJSControlled())
  688. {
  689. if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
  690. {
  691. target = ccbReader->getAnimationManager()->getRootNode();
  692. }
  693. else if(selectorTarget == CCBReader::TargetType::OWNER)
  694. {
  695. target = ccbReader->getOwner();
  696. }
  697. if(target != nullptr)
  698. {
  699. if(!selectorName.empty())
  700. {
  701. SEL_MenuHandler selMenuHandler = 0;
  702. CCBSelectorResolver * targetAsCCBSelectorResolver = dynamic_cast<CCBSelectorResolver *>(target);
  703. if(targetAsCCBSelectorResolver != nullptr)
  704. {
  705. selMenuHandler = targetAsCCBSelectorResolver->onResolveCCBCCMenuItemSelector(target, selectorName.c_str());
  706. }
  707. if(selMenuHandler == 0)
  708. {
  709. CCBSelectorResolver * ccbSelectorResolver = ccbReader->getCCBSelectorResolver();
  710. if(ccbSelectorResolver != nullptr)
  711. {
  712. selMenuHandler = ccbSelectorResolver->onResolveCCBCCMenuItemSelector(target, selectorName.c_str());
  713. }
  714. }
  715. if(selMenuHandler == 0) {
  716. CCLOG("Skipping selector '%s' since no CCBSelectorResolver is present.", selectorName.c_str());
  717. } else {
  718. BlockData * blockData = new (std::nothrow) BlockData();
  719. blockData->mSELMenuHandler = selMenuHandler;
  720. blockData->_target = target;
  721. return blockData;
  722. }
  723. } else {
  724. CCLOG("Unexpected empty selector.");
  725. }
  726. } else {
  727. CCLOG("Unexpected nullptr target for selector.");
  728. }
  729. }
  730. else
  731. {
  732. if (selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
  733. {
  734. ccbReader->addDocumentCallbackNode(pNode);
  735. ccbReader->addDocumentCallbackName(selectorName);
  736. // Since there isn't a Control::EventType::NONE, add a TOUCH_DOWN type as a placeholder.
  737. ccbReader->addDocumentCallbackControlEvents(Control::EventType::TOUCH_DOWN);
  738. }
  739. else if (selectorTarget == CCBReader::TargetType::OWNER)
  740. {
  741. ccbReader->addOwnerCallbackNode(pNode);
  742. ccbReader->addOwnerCallbackName(selectorName);
  743. // Since there isn't a Control::EventType::NONE, add a TOUCH_DOWN type as a placeholder.
  744. ccbReader->addOwnerCallbackControlEvents(Control::EventType::TOUCH_DOWN);
  745. }
  746. }
  747. }
  748. return nullptr;
  749. }
  750. BlockControlData * NodeLoader::parsePropTypeBlockControl(Node * pNode, Node * /*pParent*/, CCBReader * ccbReader)
  751. {
  752. std::string selectorName = ccbReader->readCachedString();
  753. CCBReader::TargetType selectorTarget = static_cast<CCBReader::TargetType>(ccbReader->readInt(false));
  754. int controlEvents = ccbReader->readInt(false);
  755. if(selectorTarget != CCBReader::TargetType::NONE)
  756. {
  757. if(!ccbReader->isJSControlled())
  758. {
  759. Ref* target = nullptr;
  760. if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
  761. {
  762. target = ccbReader->getAnimationManager()->getRootNode();
  763. }
  764. else if(selectorTarget == CCBReader::TargetType::OWNER)
  765. {
  766. target = ccbReader->getOwner();
  767. }
  768. if(target != nullptr)
  769. {
  770. if(!selectorName.empty())
  771. {
  772. Control::Handler selControlHandler = 0;
  773. CCBSelectorResolver * targetAsCCBSelectorResolver = dynamic_cast<CCBSelectorResolver *>(target);
  774. if(targetAsCCBSelectorResolver != nullptr)
  775. {
  776. selControlHandler = targetAsCCBSelectorResolver->onResolveCCBCCControlSelector(target, selectorName.c_str());
  777. }
  778. if(selControlHandler == 0)
  779. {
  780. CCBSelectorResolver * ccbSelectorResolver = ccbReader->getCCBSelectorResolver();
  781. if(ccbSelectorResolver != nullptr)
  782. {
  783. selControlHandler = ccbSelectorResolver->onResolveCCBCCControlSelector(target, selectorName.c_str());
  784. }
  785. }
  786. if(selControlHandler == 0)
  787. {
  788. CCLOG("Skipping selector '%s' since no CCBSelectorResolver is present.", selectorName.c_str());
  789. }
  790. else
  791. {
  792. BlockControlData * blockControlData = new (std::nothrow) BlockControlData();
  793. blockControlData->mSELControlHandler = selControlHandler;
  794. blockControlData->_target = target;
  795. blockControlData->mControlEvents = (Control::EventType)controlEvents;
  796. return blockControlData;
  797. }
  798. } else {
  799. CCLOG("Unexpected empty selector.");
  800. }
  801. } else {
  802. CCLOG("Unexpected nullptr target for selector.");
  803. }
  804. }
  805. else
  806. {
  807. if(selectorTarget == CCBReader::TargetType::DOCUMENT_ROOT)
  808. {
  809. ccbReader->addDocumentCallbackNode(pNode);
  810. ccbReader->addDocumentCallbackName(selectorName);
  811. ccbReader->addDocumentCallbackControlEvents((Control::EventType)controlEvents);
  812. }
  813. else
  814. {
  815. ccbReader->addOwnerCallbackNode(pNode);
  816. ccbReader->addOwnerCallbackName(selectorName);
  817. ccbReader->addOwnerCallbackControlEvents((Control::EventType)controlEvents);
  818. }
  819. }
  820. }
  821. return nullptr;
  822. }
  823. Node * NodeLoader::parsePropTypeCCBFile(Node * /*pNode*/, Node * pParent, CCBReader * pCCBReader) {
  824. std::string ccbFileName = pCCBReader->getCCBRootPath() + pCCBReader->readCachedString();
  825. /* Change path extension to .ccbi. */
  826. std::string ccbFileWithoutPathExtension = CCBReader::deletePathExtension(ccbFileName.c_str());
  827. ccbFileName = ccbFileWithoutPathExtension + ".ccbi";
  828. // Load sub file
  829. std::string path = FileUtils::getInstance()->fullPathForFilename(ccbFileName);
  830. auto dataPtr = std::make_shared<Data>(FileUtils::getInstance()->getDataFromFile(path));
  831. CCBReader * reader = new (std::nothrow) CCBReader(pCCBReader);
  832. reader->autorelease();
  833. reader->getAnimationManager()->setRootContainerSize(pParent->getContentSize());
  834. reader->_data = dataPtr;
  835. reader->_bytes = dataPtr->getBytes();
  836. reader->_currentByte = 0;
  837. reader->_currentBit = 0;
  838. CC_SAFE_RETAIN(pCCBReader->_owner);
  839. reader->_owner = pCCBReader->_owner;
  840. reader->getAnimationManager()->_owner = reader->_owner;
  841. // The assignments below are done in the CCBReader constructor.
  842. // reader->_ownerOutletNames = pCCBReader->_ownerOutletNames;
  843. // reader->_ownerOutletNodes = pCCBReader->_ownerOutletNodes;
  844. // reader->_ownerOutletNodes->retain();
  845. // reader->_ownerCallbackNames = pCCBReader->_ownerCallbackNames;
  846. // reader->_ownerCallbackNodes = pCCBReader->_ownerCallbackNodes;
  847. // reader->_ownerCallbackNodes->retain();
  848. Node * ccbFileNode = reader->readFileWithCleanUp(false, pCCBReader->getAnimationManagers());
  849. if (ccbFileNode && reader->getAnimationManager()->getAutoPlaySequenceId() != -1)
  850. {
  851. // Auto play animations
  852. reader->getAnimationManager()->runAnimationsForSequenceIdTweenDuration(reader->getAnimationManager()->getAutoPlaySequenceId(), 0);
  853. }
  854. if (reader->isJSControlled() && pCCBReader->isJSControlled() && nullptr == reader->_owner)
  855. {
  856. //set variables and callback to owner
  857. //set callback
  858. auto ownerCallbackNames = reader->getOwnerCallbackNames();
  859. auto& ownerCallbackNodes = reader->getOwnerCallbackNodes();
  860. if (!ownerCallbackNames.empty() && !ownerCallbackNodes.empty())
  861. {
  862. CCASSERT(ownerCallbackNames.size() == ownerCallbackNodes.size(),
  863. "ownerCallbackNames size should equal to ownerCallbackNodes size.");
  864. ssize_t nCount = ownerCallbackNames.size();
  865. for (ssize_t i = 0 ; i < nCount; i++)
  866. {
  867. pCCBReader->addOwnerCallbackName(ownerCallbackNames[i].asString());
  868. pCCBReader->addOwnerCallbackNode(ownerCallbackNodes.at(i));
  869. }
  870. }
  871. //set variables
  872. auto ownerOutletNames = reader->getOwnerOutletNames();
  873. auto ownerOutletNodes = reader->getOwnerOutletNodes();
  874. if (!ownerOutletNames.empty() && !ownerOutletNodes.empty())
  875. {
  876. CCASSERT(ownerOutletNames.size() == ownerOutletNodes.size(),
  877. "ownerOutletNames size should be equal to ownerOutletNodes's size.");
  878. ssize_t nCount = ownerOutletNames.size();
  879. for (ssize_t i = 0 ; i < nCount; i++)
  880. {
  881. pCCBReader->addOwnerOutletName(ownerOutletNames.at(i).asString());
  882. pCCBReader->addOwnerOutletNode(ownerOutletNodes.at(i));
  883. }
  884. }
  885. }
  886. return ccbFileNode;
  887. }
  888. void NodeLoader::onHandlePropTypePosition(Node * pNode, Node * /*pParent*/, const char* pPropertyName, Vec2 pPosition, CCBReader * /*ccbReader*/) {
  889. if(strcmp(pPropertyName, PROPERTY_POSITION) == 0) {
  890. pNode->setPosition(pPosition);
  891. } else {
  892. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  893. }
  894. }
  895. void NodeLoader::onHandlePropTypePoint(Node * pNode, Node * /*pParent*/, const char* pPropertyName, Vec2 pPoint, CCBReader * /*ccbReader*/) {
  896. if(strcmp(pPropertyName, PROPERTY_ANCHORPOINT) == 0) {
  897. pNode->setAnchorPoint(pPoint);
  898. } else {
  899. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  900. }
  901. }
  902. void NodeLoader::onHandlePropTypePointLock(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, Vec2 /*pPointLock*/, CCBReader * /*ccbReader*/) {
  903. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  904. }
  905. void NodeLoader::onHandlePropTypeSize(Node * pNode, Node * /*pParent*/, const char* pPropertyName, Size pSize, CCBReader * /*ccbReader*/) {
  906. if(strcmp(pPropertyName, PROPERTY_CONTENTSIZE) == 0) {
  907. pNode->setContentSize(pSize);
  908. } else {
  909. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  910. }
  911. }
  912. void NodeLoader::onHandlePropTypeFloatXY(Node * pNode, Node * /*pParent*/, const char* pPropertyName, float * pFloat, CCBReader * /*ccbReader*/) {
  913. if(strcmp(pPropertyName, PROPERTY_SKEW) == 0) {
  914. pNode->setSkewX(pFloat[0]);
  915. pNode->setSkewY(pFloat[1]);
  916. } else {
  917. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  918. }
  919. }
  920. void NodeLoader::onHandlePropTypeScaleLock(Node * pNode, Node * /*pParent*/, const char* pPropertyName, float * pScaleLock, CCBReader * /*ccbReader*/) {
  921. if(strcmp(pPropertyName, PROPERTY_SCALE) == 0) {
  922. pNode->setScaleX(pScaleLock[0]);
  923. pNode->setScaleY(pScaleLock[1]);
  924. } else {
  925. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  926. }
  927. }
  928. void NodeLoader::onHandlePropTypeFloat(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, float pFloat, CCBReader * /*ccbReader*/) {
  929. // ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  930. // It may be a custom property, add it to custom property dictionary.
  931. _customProperties[pPropertyName] = Value(pFloat);
  932. }
  933. void NodeLoader::onHandlePropTypeDegrees(Node * pNode, Node * /*pParent*/, const char* pPropertyName, float pDegrees, CCBReader * /*ccbReader*/) {
  934. if(strcmp(pPropertyName, PROPERTY_ROTATION) == 0) {
  935. pNode->setRotation(pDegrees);
  936. } else if(strcmp(pPropertyName, PROPERTY_ROTATIONX) == 0) {
  937. pNode->setRotationSkewX(pDegrees);
  938. } else if(strcmp(pPropertyName, PROPERTY_ROTATIONY) == 0) {
  939. pNode->setRotationSkewY(pDegrees);
  940. }
  941. else {
  942. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  943. }
  944. }
  945. void NodeLoader::onHandlePropTypeFloatScale(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, float /*pFloatScale*/, CCBReader * /*ccbReader*/) {
  946. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  947. }
  948. void NodeLoader::onHandlePropTypeInteger(Node * pNode, Node * /*pParent*/, const char* pPropertyName, int pInteger, CCBReader * /*ccbReader*/) {
  949. if(strcmp(pPropertyName, PROPERTY_TAG) == 0) {
  950. pNode->setTag(pInteger);
  951. } else {
  952. // ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  953. // It may be a custom property, add it to custom property dictionary.
  954. _customProperties[pPropertyName] = Value(pInteger);
  955. }
  956. }
  957. void NodeLoader::onHandlePropTypeIntegerLabeled(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, int /*pIntegerLabeled*/, CCBReader * /*ccbReader*/) {
  958. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  959. }
  960. void NodeLoader::onHandlePropTypeFloatVar(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, float * /*pFloatVar*/, CCBReader * /*ccbReader*/) {
  961. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  962. }
  963. void NodeLoader::onHandlePropTypeCheck(Node * pNode, Node * /*pParent*/, const char* pPropertyName, bool pCheck, CCBReader * /*ccbReader*/) {
  964. if(strcmp(pPropertyName, PROPERTY_VISIBLE) == 0) {
  965. pNode->setVisible(pCheck);
  966. } else if(strcmp(pPropertyName, PROPERTY_IGNOREANCHORPOINTFORPOSITION) == 0) {
  967. pNode->setIgnoreAnchorPointForPosition(pCheck);
  968. } else {
  969. //ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  970. // It may be a custom property, add it to custom property dictionary.
  971. _customProperties[pPropertyName] = Value(pCheck);
  972. }
  973. }
  974. void NodeLoader::onHandlePropTypeSpriteFrame(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, SpriteFrame * /*pSpriteFrame*/, CCBReader * /*ccbReader*/) {
  975. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  976. }
  977. void NodeLoader::onHandlePropTypeAnimation(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, Animation * /*pAnimation*/, CCBReader * /*ccbReader*/) {
  978. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  979. }
  980. void NodeLoader::onHandlePropTypeTexture(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, Texture2D * /*pTexture2D*/, CCBReader * /*ccbReader*/) {
  981. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  982. }
  983. void NodeLoader::onHandlePropTypeByte(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, unsigned char /*pByte*/, CCBReader * /*ccbReader*/) {
  984. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  985. }
  986. void NodeLoader::onHandlePropTypeColor3(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, Color3B /*pColor3B*/, CCBReader * /*ccbReader*/) {
  987. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  988. }
  989. void NodeLoader::onHandlePropTypeColor4FVar(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, Color4F * /*pColor4FVar*/, CCBReader * /*ccbReader*/) {
  990. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  991. }
  992. void NodeLoader::onHandlePropTypeFlip(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, bool * /*pFlip*/, CCBReader * /*ccbReader*/) {
  993. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  994. }
  995. void NodeLoader::onHandlePropTypeBlendFunc(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, BlendFunc /*pBlendFunc*/, CCBReader * /*ccbReader*/) {
  996. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  997. }
  998. void NodeLoader::onHandlePropTypeFntFile(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, const char* /*pFntFile*/, CCBReader * /*ccbReader*/) {
  999. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  1000. }
  1001. void NodeLoader::onHandlePropTypeString(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, const char * pString, CCBReader * /*ccbReader*/) {
  1002. // ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  1003. // It may be a custom property, add it to custom property dictionary.
  1004. _customProperties[pPropertyName] = Value(pString);
  1005. }
  1006. void NodeLoader::onHandlePropTypeText(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, const char * /*pText*/, CCBReader * /*ccbReader*/) {
  1007. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  1008. }
  1009. void NodeLoader::onHandlePropTypeFontTTF(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, const char * /*pFontTTF*/, CCBReader * /*ccbReader*/) {
  1010. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  1011. }
  1012. void NodeLoader::onHandlePropTypeBlock(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, BlockData * /*pBlockData*/, CCBReader * /*ccbReader*/) {
  1013. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  1014. }
  1015. void NodeLoader::onHandlePropTypeBlockControl(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, BlockControlData * /*pBlockControlData*/, CCBReader * /*ccbReader*/) {
  1016. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  1017. }
  1018. void NodeLoader::onHandlePropTypeCCBFile(Node * /*pNode*/, Node * /*pParent*/, const char* pPropertyName, Node * /*pCCBFileNode*/, CCBReader * /*ccbReader*/) {
  1019. ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
  1020. }
  1021. }