CCNode* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, CCObject *pOwner, const CCSize &parentSize) { if (NULL == pCCBFileName || strlen(pCCBFileName) == 0) { return NULL; } std::string strCCBFileName(pCCBFileName); std::string strSuffix(".ccbi"); // Add ccbi suffix if (!CCBReader::endsWith(strCCBFileName.c_str(), strSuffix.c_str())) { strCCBFileName += strSuffix; } std::string strPath = CCFileUtils::sharedFileUtils()->fullPathForFilename(strCCBFileName.c_str()); unsigned long size = 0; unsigned char * pBytes = CCFileUtils::sharedFileUtils()->getFileData(strPath.c_str(), "rb", &size); CCData *data = new CCData(pBytes, size); CC_SAFE_DELETE_ARRAY(pBytes); CCNode *ret = this->readNodeGraphFromData(data, pOwner, parentSize); data->release(); // (jason_shi): 将未命名的JSController命名为路径名 CCBAnimationManager* animMgr = (CCBAnimationManager*)ret->getUserObject(); std::string controllerName = animMgr->getDocumentControllerName(); if (controllerName.compare("") == 0) { animMgr->setDocumentControllerName(pCCBFileName); } return ret; }
CCNode* CCBReader::readNodeGraphFromData(CCData *pData, CCObject *pOwner, const CCSize &parentSize) { mData = pData; CC_SAFE_RETAIN(mData); mBytes = mData->getBytes(); mCurrentByte = 0; mCurrentBit = 0; mOwner = pOwner; CC_SAFE_RETAIN(mOwner); mActionManager->setRootContainerSize(parentSize); mActionManager->mOwner = mOwner; CCDictionary* animationManagers = CCDictionary::create(); CCNode *pNodeGraph = readFileWithCleanUp(true, animationManagers); if (pNodeGraph && mActionManager->getAutoPlaySequenceId() != -1 && !jsControlled) { // Auto play animations mActionManager->runAnimationsForSequenceIdTweenDuration(mActionManager->getAutoPlaySequenceId(), 0); } // Assign actionManagers to userObject if(jsControlled) { mNodesWithAnimationManagers = new CCArray(); mAnimationManagersForNodes = new CCArray(); } CCDictElement* pElement = NULL; CCDICT_FOREACH(animationManagers, pElement) { CCNode* pNode = (CCNode*)pElement->getIntKey(); CCBAnimationManager* manager = (CCBAnimationManager*)animationManagers->objectForKey((intptr_t)pNode); // (jason_shi): 将未命名的JSController命名为路径名 if (manager->getDocumentControllerName().compare("") == 0) { CCString* pStr = dynamic_cast<CCString*>(pNode->getCustObject()); if (pStr) { manager->setDocumentControllerName(pStr->getCString()); pNode->setCustObject(nullptr); } } pNode->setUserObject(manager); if (jsControlled) { mNodesWithAnimationManagers->addObject(pNode); mAnimationManagersForNodes->addObject(manager); } }