2012-05-31 07:51:33 +08:00
|
|
|
#include "CCBReader.h"
|
|
|
|
|
2012-06-14 06:25:59 +08:00
|
|
|
#include <algorithm>
|
|
|
|
|
2012-05-31 02:28:50 +08:00
|
|
|
#include "CCNodeLoader.h"
|
2012-06-06 08:15:28 +08:00
|
|
|
#include "CCNodeLoaderLibrary.h"
|
2012-06-13 02:59:49 +08:00
|
|
|
#include "CCNodeLoaderListener.h"
|
|
|
|
#include "CCBMemberVariableAssigner.h"
|
|
|
|
#include "CCBSelectorResolver.h"
|
2012-09-17 14:27:17 +08:00
|
|
|
#include "CCBAnimationManager.h"
|
|
|
|
#include "CCBSequenceProperty.h"
|
|
|
|
#include "CCBKeyframe.h"
|
|
|
|
#include "CCBValue.h"
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-08-18 05:45:21 +08:00
|
|
|
#include <ctype.h>
|
|
|
|
|
2012-06-05 07:16:42 +08:00
|
|
|
#ifdef __CC_PLATFORM_IOS
|
2012-06-13 02:59:49 +08:00
|
|
|
#include <UIKit/UIDevice.h>
|
2012-06-05 07:16:42 +08:00
|
|
|
#endif
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
using namespace std;
|
2012-09-24 11:47:33 +08:00
|
|
|
|
2012-07-19 17:22:36 +08:00
|
|
|
NS_CC_EXT_BEGIN;
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
/*************************************************************************
|
|
|
|
Implementation of CCBFile
|
|
|
|
*************************************************************************/
|
2012-06-06 08:15:28 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
CCBFile::CCBFile():mCCBFileNode(NULL) {}
|
|
|
|
|
|
|
|
CCBFile* CCBFile::create()
|
|
|
|
{
|
|
|
|
CCBFile *ret = new CCBFile();
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
{
|
|
|
|
ret->autorelease();
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* CCBFile::getCCBFileNode()
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
return mCCBFileNode;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBFile::setCCBFileNode(Node *pNode)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(mCCBFileNode);
|
|
|
|
mCCBFileNode = pNode;
|
|
|
|
CC_SAFE_RETAIN(mCCBFileNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*************************************************************************
|
|
|
|
Implementation of CCBReader
|
|
|
|
*************************************************************************/
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
CCBReader::CCBReader(NodeLoaderLibrary * pNodeLoaderLibrary, CCBMemberVariableAssigner * pCCBMemberVariableAssigner, CCBSelectorResolver * pCCBSelectorResolver, NodeLoaderListener * pNodeLoaderListener)
|
2012-09-17 14:27:17 +08:00
|
|
|
: mData(NULL)
|
|
|
|
, mBytes(NULL)
|
|
|
|
, mCurrentByte(-1)
|
|
|
|
, mCurrentBit(-1)
|
|
|
|
, mOwner(NULL)
|
|
|
|
, mActionManager(NULL)
|
2012-11-26 21:51:05 +08:00
|
|
|
, mActionManagers(NULL)
|
2013-03-03 10:32:09 +08:00
|
|
|
, mAnimatedProps(NULL)
|
|
|
|
, mOwnerOutletNodes(NULL)
|
2012-11-26 21:51:05 +08:00
|
|
|
, mNodesWithAnimationManagers(NULL)
|
|
|
|
, mAnimationManagersForNodes(NULL)
|
2013-01-21 14:40:29 +08:00
|
|
|
, mOwnerCallbackNodes(NULL)
|
2013-03-03 10:32:09 +08:00
|
|
|
, hasScriptingOwner(false)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
this->mNodeLoaderLibrary = pNodeLoaderLibrary;
|
|
|
|
this->mNodeLoaderLibrary->retain();
|
2012-06-05 06:52:49 +08:00
|
|
|
this->mCCBMemberVariableAssigner = pCCBMemberVariableAssigner;
|
|
|
|
this->mCCBSelectorResolver = pCCBSelectorResolver;
|
2013-06-20 14:15:53 +08:00
|
|
|
this->mNodeLoaderListener = pNodeLoaderListener;
|
2012-11-26 21:51:05 +08:00
|
|
|
init();
|
2012-06-01 05:57:13 +08:00
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
CCBReader::CCBReader(CCBReader * pCCBReader)
|
|
|
|
: mData(NULL)
|
|
|
|
, mBytes(NULL)
|
|
|
|
, mCurrentByte(-1)
|
|
|
|
, mCurrentBit(-1)
|
|
|
|
, mOwner(NULL)
|
|
|
|
, mActionManager(NULL)
|
2012-11-26 21:51:05 +08:00
|
|
|
, mActionManagers(NULL)
|
2013-03-03 10:32:09 +08:00
|
|
|
, mAnimatedProps(NULL)
|
|
|
|
, mOwnerOutletNodes(NULL)
|
2012-11-26 21:51:05 +08:00
|
|
|
, mNodesWithAnimationManagers(NULL)
|
|
|
|
, mAnimationManagersForNodes(NULL)
|
2013-01-21 14:40:29 +08:00
|
|
|
, mOwnerCallbackNodes(NULL)
|
2013-03-03 10:32:09 +08:00
|
|
|
, hasScriptingOwner(false)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-06-01 05:57:13 +08:00
|
|
|
this->mLoadedSpriteSheets = pCCBReader->mLoadedSpriteSheets;
|
2013-06-20 14:15:53 +08:00
|
|
|
this->mNodeLoaderLibrary = pCCBReader->mNodeLoaderLibrary;
|
|
|
|
this->mNodeLoaderLibrary->retain();
|
2012-06-14 05:19:13 +08:00
|
|
|
|
2012-06-05 06:52:49 +08:00
|
|
|
this->mCCBMemberVariableAssigner = pCCBReader->mCCBMemberVariableAssigner;
|
|
|
|
this->mCCBSelectorResolver = pCCBReader->mCCBSelectorResolver;
|
2013-06-20 14:15:53 +08:00
|
|
|
this->mNodeLoaderListener = pCCBReader->mNodeLoaderListener;
|
2012-11-01 02:06:56 +08:00
|
|
|
|
|
|
|
this->mOwnerCallbackNames = pCCBReader->mOwnerCallbackNames;
|
|
|
|
this->mOwnerCallbackNodes = pCCBReader->mOwnerCallbackNodes;
|
2012-11-26 21:51:05 +08:00
|
|
|
this->mOwnerCallbackNodes->retain();
|
2012-11-01 02:06:56 +08:00
|
|
|
this->mOwnerOutletNames = pCCBReader->mOwnerOutletNames;
|
|
|
|
this->mOwnerOutletNodes = pCCBReader->mOwnerOutletNodes;
|
2012-11-26 21:51:05 +08:00
|
|
|
this->mOwnerOutletNodes->retain();
|
2013-06-27 09:41:38 +08:00
|
|
|
|
|
|
|
this->mCCBRootPath = pCCBReader->getCCBRootPath();
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
init();
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
CCBReader::CCBReader()
|
|
|
|
: mData(NULL)
|
|
|
|
, mBytes(NULL)
|
|
|
|
, mCurrentByte(-1)
|
|
|
|
, mCurrentBit(-1)
|
|
|
|
, mOwner(NULL)
|
|
|
|
, mActionManager(NULL)
|
2013-03-03 10:32:09 +08:00
|
|
|
, mActionManagers(NULL)
|
2013-06-20 14:15:53 +08:00
|
|
|
, mNodeLoaderLibrary(NULL)
|
|
|
|
, mNodeLoaderListener(NULL)
|
2012-09-17 14:27:17 +08:00
|
|
|
, mCCBMemberVariableAssigner(NULL)
|
|
|
|
, mCCBSelectorResolver(NULL)
|
2012-11-26 21:51:05 +08:00
|
|
|
, mNodesWithAnimationManagers(NULL)
|
|
|
|
, mAnimationManagersForNodes(NULL)
|
2013-03-03 10:32:09 +08:00
|
|
|
, hasScriptingOwner(false)
|
2012-11-26 21:51:05 +08:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2012-06-14 15:01:01 +08:00
|
|
|
CCBReader::~CCBReader() {
|
2012-09-17 14:27:17 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(mOwner);
|
|
|
|
CC_SAFE_RELEASE_NULL(mData);
|
2012-06-14 15:01:01 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
this->mNodeLoaderLibrary->release();
|
2012-06-14 15:01:01 +08:00
|
|
|
|
2013-01-21 14:40:29 +08:00
|
|
|
CC_SAFE_RELEASE(mOwnerOutletNodes);
|
2012-12-04 18:44:32 +08:00
|
|
|
mOwnerOutletNames.clear();
|
2013-01-21 14:40:29 +08:00
|
|
|
CC_SAFE_RELEASE(mOwnerCallbackNodes);
|
2012-11-26 21:51:05 +08:00
|
|
|
mOwnerCallbackNames.clear();
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
// Clear string cache.
|
2012-11-26 21:51:05 +08:00
|
|
|
|
2012-06-14 15:01:01 +08:00
|
|
|
this->mStringCache.clear();
|
2012-11-26 21:51:05 +08:00
|
|
|
CC_SAFE_RELEASE(mNodesWithAnimationManagers);
|
|
|
|
CC_SAFE_RELEASE(mAnimationManagersForNodes);
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
setAnimationManager(NULL);
|
2012-06-14 15:01:01 +08:00
|
|
|
}
|
|
|
|
|
2012-12-03 18:27:50 +08:00
|
|
|
void CCBReader::setCCBRootPath(const char* pCCBRootPath)
|
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(pCCBRootPath != NULL, "");
|
2012-12-03 18:27:50 +08:00
|
|
|
mCCBRootPath = pCCBRootPath;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& CCBReader::getCCBRootPath() const
|
|
|
|
{
|
|
|
|
return mCCBRootPath;
|
|
|
|
}
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
bool CCBReader::init()
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
// Setup action manager
|
|
|
|
CCBAnimationManager *pActionManager = new CCBAnimationManager();
|
|
|
|
setAnimationManager(pActionManager);
|
|
|
|
pActionManager->release();
|
|
|
|
|
|
|
|
// Setup resolution scale and container size
|
2013-07-12 06:24:23 +08:00
|
|
|
mActionManager->setRootContainerSize(Director::getInstance()->getWinSize());
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBAnimationManager* CCBReader::getAnimationManager()
|
|
|
|
{
|
|
|
|
return mActionManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBReader::setAnimationManager(CCBAnimationManager *pAnimationManager)
|
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE(mActionManager);
|
|
|
|
mActionManager = pAnimationManager;
|
|
|
|
CC_SAFE_RETAIN(mActionManager);
|
2012-06-12 09:31:11 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Dictionary* CCBReader::getAnimationManagers()
|
2012-11-26 21:51:05 +08:00
|
|
|
{
|
|
|
|
return mActionManagers;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBReader::setAnimationManagers(Dictionary* x)
|
2012-11-26 21:51:05 +08:00
|
|
|
{
|
|
|
|
mActionManagers = x;
|
|
|
|
}
|
|
|
|
|
2012-06-05 06:52:49 +08:00
|
|
|
CCBMemberVariableAssigner * CCBReader::getCCBMemberVariableAssigner() {
|
|
|
|
return this->mCCBMemberVariableAssigner;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCBSelectorResolver * CCBReader::getCCBSelectorResolver() {
|
|
|
|
return this->mCCBSelectorResolver;
|
|
|
|
}
|
|
|
|
|
2012-09-18 17:04:10 +08:00
|
|
|
set<string>* CCBReader::getAnimatedProperties()
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
return mAnimatedProps;
|
2012-06-05 07:16:42 +08:00
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
set<string>& CCBReader::getLoadedSpriteSheet()
|
|
|
|
{
|
|
|
|
return mLoadedSpriteSheets;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Object* CCBReader::getOwner()
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
return mOwner;
|
2012-06-14 15:01:01 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
return this->readNodeGraphFromFile(pCCBFileName, NULL);
|
2012-06-14 15:01:01 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* CCBReader::readNodeGraphFromFile(const char* pCCBFileName, Object* pOwner)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
return this->readNodeGraphFromFile(pCCBFileName, pOwner, Director::getInstance()->getWinSize());
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
2012-06-12 09:31:11 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* CCBReader::readNodeGraphFromFile(const char *pCCBFileName, Object *pOwner, const Size &parentSize)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-11-30 14:16:38 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
std::string strPath = FileUtils::getInstance()->fullPathForFilename(strCCBFileName.c_str());
|
2012-11-30 14:16:38 +08:00
|
|
|
unsigned long size = 0;
|
2012-06-06 08:15:28 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
unsigned char * pBytes = FileUtils::getInstance()->getFileData(strPath.c_str(), "rb", &size);
|
2013-06-20 14:15:53 +08:00
|
|
|
Data *data = new Data(pBytes, size);
|
2012-11-27 10:26:40 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(pBytes);
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node *ret = this->readNodeGraphFromData(data, pOwner, parentSize);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
data->release();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2012-06-14 15:01:01 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* CCBReader::readNodeGraphFromData(Data *pData, Object *pOwner, const Size &parentSize)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-11-26 21:51:05 +08:00
|
|
|
mData = pData;
|
|
|
|
CC_SAFE_RETAIN(mData);
|
|
|
|
mBytes = mData->getBytes();
|
|
|
|
mCurrentByte = 0;
|
|
|
|
mCurrentBit = 0;
|
|
|
|
mOwner = pOwner;
|
|
|
|
CC_SAFE_RETAIN(mOwner);
|
2012-06-06 08:15:28 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
mActionManager->setRootContainerSize(parentSize);
|
2013-03-15 08:43:56 +08:00
|
|
|
mActionManager->mOwner = mOwner;
|
2013-06-20 14:15:53 +08:00
|
|
|
mOwnerOutletNodes = new Array();
|
|
|
|
mOwnerCallbackNodes = new Array();
|
2012-11-01 02:06:56 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Dictionary* animationManagers = Dictionary::create();
|
|
|
|
Node *pNodeGraph = readFileWithCleanUp(true, animationManagers);
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
if (pNodeGraph && mActionManager->getAutoPlaySequenceId() != -1 && !jsControlled)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
// Auto play animations
|
2012-11-28 11:49:20 +08:00
|
|
|
mActionManager->runAnimationsForSequenceIdTweenDuration(mActionManager->getAutoPlaySequenceId(), 0);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2012-11-26 21:51:05 +08:00
|
|
|
// Assign actionManagers to userObject
|
2012-11-01 02:06:56 +08:00
|
|
|
if(jsControlled) {
|
2013-06-20 14:15:53 +08:00
|
|
|
mNodesWithAnimationManagers = new Array();
|
|
|
|
mAnimationManagersForNodes = new Array();
|
2012-11-01 02:06:56 +08:00
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
DictElement* pElement = NULL;
|
2012-11-26 21:51:05 +08:00
|
|
|
CCDICT_FOREACH(animationManagers, pElement)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* pNode = (Node*)pElement->getIntKey();
|
2013-07-09 14:40:43 +08:00
|
|
|
CCBAnimationManager* manager = static_cast<CCBAnimationManager*>(animationManagers->objectForKey((intptr_t)pNode));
|
2013-01-23 15:14:40 +08:00
|
|
|
pNode->setUserObject(manager);
|
2012-12-04 18:44:32 +08:00
|
|
|
|
|
|
|
if (jsControlled)
|
|
|
|
{
|
|
|
|
mNodesWithAnimationManagers->addObject(pNode);
|
|
|
|
mAnimationManagersForNodes->addObject(manager);
|
2012-11-26 21:51:05 +08:00
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return pNodeGraph;
|
|
|
|
}
|
2012-06-06 08:15:28 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Scene* CCBReader::createSceneWithNodeGraphFromFile(const char *pCCBFileName)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
return createSceneWithNodeGraphFromFile(pCCBFileName, NULL);
|
|
|
|
}
|
2012-06-06 08:15:28 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Scene* CCBReader::createSceneWithNodeGraphFromFile(const char *pCCBFileName, Object *pOwner)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-07-12 06:24:23 +08:00
|
|
|
return createSceneWithNodeGraphFromFile(pCCBFileName, pOwner, Director::getInstance()->getWinSize());
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Scene* CCBReader::createSceneWithNodeGraphFromFile(const char *pCCBFileName, Object *pOwner, const Size &parentSize)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Node *pNode = readNodeGraphFromFile(pCCBFileName, pOwner, parentSize);
|
|
|
|
Scene *pScene = Scene::create();
|
2012-09-17 14:27:17 +08:00
|
|
|
pScene->addChild(pNode);
|
|
|
|
|
|
|
|
return pScene;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBReader::cleanUpNodeGraph(Node *pNode)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
pNode->setUserObject(NULL);
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Object *pChild = NULL;
|
2012-09-17 14:27:17 +08:00
|
|
|
CCARRAY_FOREACH(pNode->getChildren(), pChild)
|
|
|
|
{
|
2013-07-09 14:29:51 +08:00
|
|
|
cleanUpNodeGraph(static_cast<Node*>(pChild));
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node* CCBReader::readFileWithCleanUp(bool bCleanUp, Dictionary* am)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
if (! readHeader())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! readStringCache())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (! readSequences())
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-11-28 11:49:20 +08:00
|
|
|
setAnimationManagers(am);
|
2012-11-01 02:06:56 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node *pNode = readNodeGraph(NULL);
|
2012-11-26 21:51:05 +08:00
|
|
|
|
|
|
|
mActionManagers->setObject(mActionManager, intptr_t(pNode));
|
2012-11-01 02:06:56 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
if (bCleanUp)
|
|
|
|
{
|
|
|
|
cleanUpNodeGraph(pNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
return pNode;
|
|
|
|
}
|
|
|
|
|
2012-05-31 02:28:50 +08:00
|
|
|
bool CCBReader::readStringCache() {
|
|
|
|
int numStrings = this->readInt(false);
|
|
|
|
|
|
|
|
for(int i = 0; i < numStrings; i++) {
|
2012-11-26 21:51:05 +08:00
|
|
|
this->mStringCache.push_back(this->readUTF8());
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
bool CCBReader::readHeader()
|
|
|
|
{
|
|
|
|
/* If no bytes loaded, don't crash about it. */
|
|
|
|
if(this->mBytes == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
/* Read magic bytes */
|
|
|
|
int magicBytes = *((int*)(this->mBytes + this->mCurrentByte));
|
|
|
|
this->mCurrentByte += 4;
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
if(CC_SWAP_INT32_LITTLE_TO_HOST(magicBytes) != 'ccbi') {
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
/* Read version. */
|
|
|
|
int version = this->readInt(false);
|
|
|
|
if(version != kCCBVersion) {
|
2013-07-24 06:20:22 +08:00
|
|
|
log("WARNING! Incompatible ccbi file version (file: %d reader: %d)", version, kCCBVersion);
|
2012-11-26 21:51:05 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read JS check
|
|
|
|
jsControlled = this->readBool();
|
2013-03-15 08:43:56 +08:00
|
|
|
mActionManager->jsControlled = jsControlled;
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
return true;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char CCBReader::readByte() {
|
|
|
|
unsigned char byte = this->mBytes[this->mCurrentByte];
|
|
|
|
this->mCurrentByte++;
|
|
|
|
return byte;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCBReader::readBool() {
|
2012-06-20 11:48:31 +08:00
|
|
|
return 0 == this->readByte() ? false : true;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2012-12-04 18:44:32 +08:00
|
|
|
std::string CCBReader::readUTF8()
|
|
|
|
{
|
|
|
|
std::string ret;
|
|
|
|
|
|
|
|
int b0 = this->readByte();
|
|
|
|
int b1 = this->readByte();
|
|
|
|
|
|
|
|
int numBytes = b0 << 8 | b1;
|
|
|
|
|
|
|
|
char* pStr = (char*)malloc(numBytes+1);
|
|
|
|
memcpy(pStr, mBytes+mCurrentByte, numBytes);
|
|
|
|
pStr[numBytes] = '\0';
|
|
|
|
ret = pStr;
|
|
|
|
free(pStr);
|
|
|
|
|
|
|
|
mCurrentByte += numBytes;
|
|
|
|
|
|
|
|
return ret;
|
2012-11-26 21:51:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool CCBReader::getBit() {
|
|
|
|
bool bit;
|
|
|
|
unsigned char byte = *(this->mBytes + this->mCurrentByte);
|
|
|
|
if(byte & (1 << this->mCurrentBit)) {
|
|
|
|
bit = true;
|
|
|
|
} else {
|
|
|
|
bit = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->mCurrentBit++;
|
|
|
|
|
|
|
|
if(this->mCurrentBit >= 8) {
|
|
|
|
this->mCurrentBit = 0;
|
|
|
|
this->mCurrentByte++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBReader::alignBits() {
|
|
|
|
if(this->mCurrentBit) {
|
|
|
|
this->mCurrentBit = 0;
|
|
|
|
this->mCurrentByte++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-19 03:03:06 +08:00
|
|
|
int CCBReader::readInt(bool pSigned) {
|
2012-11-26 21:51:05 +08:00
|
|
|
// Read encoded int
|
2012-05-31 02:28:50 +08:00
|
|
|
int numBits = 0;
|
|
|
|
while(!this->getBit()) {
|
|
|
|
numBits++;
|
|
|
|
}
|
|
|
|
|
|
|
|
long long current = 0;
|
|
|
|
for(int a = numBits - 1; a >= 0; a--) {
|
|
|
|
if(this->getBit()) {
|
2012-08-25 00:22:02 +08:00
|
|
|
current |= 1LL << a;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
}
|
2012-08-25 00:22:02 +08:00
|
|
|
current |= 1LL << numBits;
|
2012-05-31 02:28:50 +08:00
|
|
|
|
|
|
|
int num;
|
2012-06-19 03:03:06 +08:00
|
|
|
if(pSigned) {
|
2012-05-31 02:28:50 +08:00
|
|
|
int s = current % 2;
|
|
|
|
if(s) {
|
|
|
|
num = (int)(current / 2);
|
|
|
|
} else {
|
|
|
|
num = (int)(-current / 2);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
num = current - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
this->alignBits();
|
|
|
|
|
|
|
|
return num;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
float CCBReader::readFloat() {
|
|
|
|
unsigned char type = this->readByte();
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case kCCBFloat0:
|
|
|
|
return 0;
|
|
|
|
case kCCBFloat1:
|
|
|
|
return 1;
|
|
|
|
case kCCBFloatMinus1:
|
|
|
|
return -1;
|
|
|
|
case kCCBFloat05:
|
|
|
|
return 0.5f;
|
|
|
|
case kCCBFloatInteger:
|
2012-06-20 11:48:31 +08:00
|
|
|
return (float)this->readInt(true);
|
2012-05-31 02:28:50 +08:00
|
|
|
default:
|
2012-11-26 21:51:05 +08:00
|
|
|
{
|
|
|
|
/* using a memcpy since the compiler isn't
|
|
|
|
* doing the float ptr math correctly on device.
|
|
|
|
* TODO still applies in C++ ? */
|
2013-03-17 06:47:58 +08:00
|
|
|
unsigned char* pF = (this->mBytes + this->mCurrentByte);
|
2012-11-26 21:51:05 +08:00
|
|
|
float f = 0;
|
2013-02-07 06:44:15 +08:00
|
|
|
|
|
|
|
// N.B - in order to avoid an unaligned memory access crash on 'memcpy()' the the (void*) casts of the source and
|
|
|
|
// destination pointers are EXTREMELY important for the ARM compiler.
|
|
|
|
//
|
|
|
|
// Without a (void*) cast, the ARM compiler makes the assumption that the float* pointer is naturally aligned
|
|
|
|
// according to it's type size (aligned along 4 byte boundaries) and thus tries to call a more optimized
|
|
|
|
// version of memcpy() which makes this alignment assumption also. When reading back from a file of course our pointers
|
|
|
|
// may not be aligned, hence we need to avoid the compiler making this assumption. The (void*) cast serves this purpose,
|
|
|
|
// and causes the ARM compiler to choose the slower, more generalized (unaligned) version of memcpy()
|
|
|
|
//
|
|
|
|
// For more about this compiler behavior, see:
|
|
|
|
// http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka3934.html
|
|
|
|
memcpy((void*) &f, (const void*) pF, sizeof(float));
|
|
|
|
|
|
|
|
this->mCurrentByte += sizeof(float);
|
2012-11-26 21:51:05 +08:00
|
|
|
return f;
|
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
std::string CCBReader::readCachedString() {
|
|
|
|
int n = this->readInt(false);
|
|
|
|
return this->mStringCache[n];
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node * CCBReader::readNodeGraph(Node * pParent) {
|
2012-06-05 06:52:49 +08:00
|
|
|
/* Read class name. */
|
2012-11-26 21:51:05 +08:00
|
|
|
std::string className = this->readCachedString();
|
2012-05-31 02:28:50 +08:00
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
std::string jsControlledName;
|
2012-11-02 08:52:07 +08:00
|
|
|
|
|
|
|
if(jsControlled) {
|
|
|
|
jsControlledName = this->readCachedString();
|
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
// Read assignment type and name
|
2012-05-31 02:28:50 +08:00
|
|
|
int memberVarAssignmentType = this->readInt(false);
|
2012-11-26 21:51:05 +08:00
|
|
|
std::string memberVarAssignmentName;
|
2012-06-05 06:52:49 +08:00
|
|
|
if(memberVarAssignmentType != kCCBTargetTypeNone) {
|
2012-06-14 15:01:01 +08:00
|
|
|
memberVarAssignmentName = this->readCachedString();
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2013-06-05 15:17:00 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
NodeLoader *ccNodeLoader = this->mNodeLoaderLibrary->getNodeLoader(className.c_str());
|
2013-06-05 15:17:00 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
if (! ccNodeLoader)
|
|
|
|
{
|
2013-07-24 06:20:22 +08:00
|
|
|
log("no corresponding node loader for %s", className.c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node *node = ccNodeLoader->loadNode(pParent, this);
|
2012-06-05 06:52:49 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
// Set root node
|
|
|
|
if (! mActionManager->getRootNode())
|
|
|
|
{
|
|
|
|
mActionManager->setRootNode(node);
|
|
|
|
}
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
// Assign controller
|
|
|
|
if(jsControlled && node == mActionManager->getRootNode())
|
|
|
|
{
|
|
|
|
mActionManager->setDocumentControllerName(jsControlledName);
|
2012-11-01 02:06:56 +08:00
|
|
|
}
|
2012-11-02 08:52:07 +08:00
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
// Read animated properties
|
2013-06-20 14:15:53 +08:00
|
|
|
Dictionary *seqs = Dictionary::create();
|
2012-09-18 17:04:10 +08:00
|
|
|
mAnimatedProps = new set<string>();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
int numSequence = readInt(false);
|
|
|
|
for (int i = 0; i < numSequence; ++i)
|
|
|
|
{
|
|
|
|
int seqId = readInt(false);
|
2013-06-20 14:15:53 +08:00
|
|
|
Dictionary *seqNodeProps = Dictionary::create();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
int numProps = readInt(false);
|
|
|
|
|
|
|
|
for (int j = 0; j < numProps; ++j)
|
|
|
|
{
|
|
|
|
CCBSequenceProperty *seqProp = new CCBSequenceProperty();
|
|
|
|
seqProp->autorelease();
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
seqProp->setName(readCachedString().c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
seqProp->setType(readInt(false));
|
2012-09-18 17:04:10 +08:00
|
|
|
mAnimatedProps->insert(seqProp->getName());
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
int numKeyframes = readInt(false);
|
|
|
|
|
|
|
|
for (int k = 0; k < numKeyframes; ++k)
|
|
|
|
{
|
|
|
|
CCBKeyframe *keyframe = readKeyframe(seqProp->getType());
|
|
|
|
|
|
|
|
seqProp->getKeyframes()->addObject(keyframe);
|
|
|
|
}
|
|
|
|
|
|
|
|
seqNodeProps->setObject(seqProp, seqProp->getName());
|
|
|
|
}
|
|
|
|
|
|
|
|
seqs->setObject(seqNodeProps, seqId);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seqs->count() > 0)
|
|
|
|
{
|
|
|
|
mActionManager->addNode(node, seqs);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Read properties
|
|
|
|
ccNodeLoader->parseProperties(node, pParent, this);
|
|
|
|
|
2013-06-07 12:50:02 +08:00
|
|
|
bool isCCBFileNode = (NULL == dynamic_cast<CCBFile*>(node)) ? false : true;
|
2012-09-17 14:27:17 +08:00
|
|
|
// Handle sub ccb files (remove middle node)
|
2013-04-15 10:39:44 +08:00
|
|
|
if (isCCBFileNode)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
CCBFile *ccbFileNode = (CCBFile*)node;
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node *embeddedNode = ccbFileNode->getCCBFileNode();
|
2012-09-17 14:27:17 +08:00
|
|
|
embeddedNode->setPosition(ccbFileNode->getPosition());
|
|
|
|
embeddedNode->setRotation(ccbFileNode->getRotation());
|
2013-04-15 10:18:35 +08:00
|
|
|
embeddedNode->setScaleX(ccbFileNode->getScaleX());
|
|
|
|
embeddedNode->setScaleY(ccbFileNode->getScaleY());
|
2012-09-17 14:27:17 +08:00
|
|
|
embeddedNode->setTag(ccbFileNode->getTag());
|
|
|
|
embeddedNode->setVisible(true);
|
2013-05-08 05:51:21 +08:00
|
|
|
//embeddedNode->ignoreAnchorPointForPosition(ccbFileNode->isIgnoreAnchorPointForPosition());
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2012-11-01 02:06:56 +08:00
|
|
|
mActionManager->moveAnimationsFromNode(ccbFileNode, embeddedNode);
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
ccbFileNode->setCCBFileNode(NULL);
|
|
|
|
|
|
|
|
node = embeddedNode;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
#ifdef CCB_ENABLE_JAVASCRIPT
|
|
|
|
/*
|
|
|
|
if (memberVarAssignmentType && memberVarAssignmentName && ![memberVarAssignmentName isEqualToString:@""])
|
|
|
|
{
|
|
|
|
[[JSCocoa sharedController] setObject:node withName:memberVarAssignmentName];
|
|
|
|
}*/
|
|
|
|
#else
|
2013-01-21 18:37:17 +08:00
|
|
|
if (memberVarAssignmentType != kCCBTargetTypeNone)
|
|
|
|
{
|
|
|
|
if(!jsControlled)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Object * target = NULL;
|
2013-01-21 18:37:17 +08:00
|
|
|
if(memberVarAssignmentType == kCCBTargetTypeDocumentRoot)
|
|
|
|
{
|
|
|
|
target = mActionManager->getRootNode();
|
|
|
|
}
|
|
|
|
else if(memberVarAssignmentType == kCCBTargetTypeOwner)
|
|
|
|
{
|
|
|
|
target = this->mOwner;
|
2012-06-14 05:19:13 +08:00
|
|
|
}
|
2013-01-21 18:37:17 +08:00
|
|
|
|
|
|
|
if(target != NULL)
|
|
|
|
{
|
|
|
|
CCBMemberVariableAssigner * targetAsCCBMemberVariableAssigner = dynamic_cast<CCBMemberVariableAssigner *>(target);
|
|
|
|
|
|
|
|
bool assigned = false;
|
|
|
|
if (memberVarAssignmentType != kCCBTargetTypeNone)
|
|
|
|
{
|
|
|
|
if(targetAsCCBMemberVariableAssigner != NULL) {
|
|
|
|
assigned = targetAsCCBMemberVariableAssigner->onAssignCCBMemberVariable(target, memberVarAssignmentName.c_str(), node);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!assigned && this->mCCBMemberVariableAssigner != NULL) {
|
|
|
|
assigned = this->mCCBMemberVariableAssigner->onAssignCCBMemberVariable(target, memberVarAssignmentName.c_str(), node);
|
|
|
|
}
|
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
}
|
2013-01-21 18:37:17 +08:00
|
|
|
else
|
|
|
|
{
|
2012-11-02 08:52:07 +08:00
|
|
|
if(memberVarAssignmentType == kCCBTargetTypeDocumentRoot) {
|
2012-11-26 21:51:05 +08:00
|
|
|
mActionManager->addDocumentOutletName(memberVarAssignmentName);
|
2012-11-02 08:52:07 +08:00
|
|
|
mActionManager->addDocumentOutletNode(node);
|
|
|
|
} else {
|
2012-11-26 21:51:05 +08:00
|
|
|
mOwnerOutletNames.push_back(memberVarAssignmentName);
|
2012-11-02 08:52:07 +08:00
|
|
|
mOwnerOutletNodes->addObject(node);
|
|
|
|
}
|
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2013-01-21 18:37:17 +08:00
|
|
|
|
|
|
|
// Assign custom properties.
|
|
|
|
if (ccNodeLoader->getCustomProperties()->count() > 0) {
|
|
|
|
|
|
|
|
bool customAssigned = false;
|
|
|
|
|
|
|
|
if(!jsControlled)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Object * target = node;
|
2013-01-21 18:37:17 +08:00
|
|
|
if(target != NULL)
|
|
|
|
{
|
|
|
|
CCBMemberVariableAssigner * targetAsCCBMemberVariableAssigner = dynamic_cast<CCBMemberVariableAssigner *>(target);
|
|
|
|
if(targetAsCCBMemberVariableAssigner != NULL) {
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Dictionary* pCustomPropeties = ccNodeLoader->getCustomProperties();
|
|
|
|
DictElement* pElement;
|
2013-01-21 18:37:17 +08:00
|
|
|
CCDICT_FOREACH(pCustomPropeties, pElement)
|
|
|
|
{
|
2013-07-09 14:40:43 +08:00
|
|
|
customAssigned = targetAsCCBMemberVariableAssigner->onAssignCCBCustomProperty(target, pElement->getStrKey(), static_cast<CCBValue*>(pElement->getObject()));
|
2013-01-21 18:37:17 +08:00
|
|
|
|
|
|
|
if(!customAssigned && this->mCCBMemberVariableAssigner != NULL)
|
|
|
|
{
|
2013-07-09 14:40:43 +08:00
|
|
|
customAssigned = this->mCCBMemberVariableAssigner->onAssignCCBCustomProperty(target, pElement->getStrKey(), static_cast<CCBValue*>(pElement->getObject()));
|
2013-01-21 18:37:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
#endif // CCB_ENABLE_JAVASCRIPT
|
2012-09-18 17:04:10 +08:00
|
|
|
|
|
|
|
delete mAnimatedProps;
|
|
|
|
mAnimatedProps = NULL;
|
2012-06-05 06:52:49 +08:00
|
|
|
|
|
|
|
/* Read and add children. */
|
2012-05-31 02:28:50 +08:00
|
|
|
int numChildren = this->readInt(false);
|
|
|
|
for(int i = 0; i < numChildren; i++) {
|
2013-06-20 14:15:53 +08:00
|
|
|
Node * child = this->readNodeGraph(node);
|
2012-05-31 02:28:50 +08:00
|
|
|
node->addChild(child);
|
|
|
|
}
|
2012-06-06 08:15:28 +08:00
|
|
|
|
2013-04-15 10:39:44 +08:00
|
|
|
// FIX ISSUE #1860: "onNodeLoaded will be called twice if ccb was added as a CCBFile".
|
2013-06-20 14:15:53 +08:00
|
|
|
// If it's a sub-ccb node, skip notification to NodeLoaderListener since it will be
|
|
|
|
// notified at LINE #734: Node * child = this->readNodeGraph(node);
|
2013-04-15 10:39:44 +08:00
|
|
|
if (!isCCBFileNode) {
|
|
|
|
// Call onNodeLoaded
|
2013-06-20 14:15:53 +08:00
|
|
|
NodeLoaderListener * nodeAsNodeLoaderListener = dynamic_cast<NodeLoaderListener *>(node);
|
|
|
|
if(nodeAsNodeLoaderListener != NULL) {
|
|
|
|
nodeAsNodeLoaderListener->onNodeLoaded(node, ccNodeLoader);
|
|
|
|
} else if(this->mNodeLoaderListener != NULL) {
|
|
|
|
this->mNodeLoaderListener->onNodeLoaded(node, ccNodeLoader);
|
2013-04-15 10:39:44 +08:00
|
|
|
}
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
CCBKeyframe* CCBReader::readKeyframe(int type)
|
|
|
|
{
|
|
|
|
CCBKeyframe *keyframe = new CCBKeyframe();
|
|
|
|
keyframe->autorelease();
|
|
|
|
|
|
|
|
keyframe->setTime(readFloat());
|
|
|
|
|
|
|
|
int easingType = readInt(false);
|
|
|
|
float easingOpt = 0;
|
2013-06-20 14:15:53 +08:00
|
|
|
Object *value = NULL;
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
if (easingType == kCCBKeyframeEasingCubicIn
|
|
|
|
|| easingType == kCCBKeyframeEasingCubicOut
|
|
|
|
|| easingType == kCCBKeyframeEasingCubicInOut
|
|
|
|
|| easingType == kCCBKeyframeEasingElasticIn
|
|
|
|
|| easingType == kCCBKeyframeEasingElasticOut
|
|
|
|
|| easingType == kCCBKeyframeEasingElasticInOut)
|
|
|
|
{
|
|
|
|
easingOpt = readFloat();
|
|
|
|
}
|
|
|
|
keyframe->setEasingType(easingType);
|
|
|
|
keyframe->setEasingOpt(easingOpt);
|
|
|
|
|
|
|
|
if (type == kCCBPropTypeCheck)
|
|
|
|
{
|
|
|
|
value = CCBValue::create(readBool());
|
|
|
|
}
|
|
|
|
else if (type == kCCBPropTypeByte)
|
|
|
|
{
|
|
|
|
value = CCBValue::create(readByte());
|
|
|
|
}
|
|
|
|
else if (type == kCCBPropTypeColor3)
|
|
|
|
{
|
|
|
|
int r = readByte();
|
|
|
|
int g = readByte();
|
|
|
|
int b = readByte();
|
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
Color3B c = Color3B(r,g,b);
|
|
|
|
value = Color3BWapper::create(c);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else if (type == kCCBPropTypeDegrees)
|
|
|
|
{
|
|
|
|
value = CCBValue::create(readFloat());
|
|
|
|
}
|
2013-03-15 08:43:56 +08:00
|
|
|
else if (type == kCCBPropTypeScaleLock || type == kCCBPropTypePosition
|
|
|
|
|| type == kCCBPropTypeFloatXY)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
|
|
|
float a = readFloat();
|
|
|
|
float b = readFloat();
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
value = Array::create(CCBValue::create(a),
|
2012-09-17 14:27:17 +08:00
|
|
|
CCBValue::create(b),
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
else if (type == kCCBPropTypeSpriteFrame)
|
|
|
|
{
|
2012-11-26 21:51:05 +08:00
|
|
|
std::string spriteSheet = readCachedString();
|
|
|
|
std::string spriteFile = readCachedString();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
SpriteFrame* spriteFrame;
|
2012-11-26 21:51:05 +08:00
|
|
|
|
|
|
|
if (spriteSheet.length() == 0)
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-12-03 18:27:50 +08:00
|
|
|
spriteFile = mCCBRootPath + spriteFile;
|
2013-07-12 18:04:32 +08:00
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Texture2D *texture = TextureCache::getInstance()->addImage(spriteFile.c_str());
|
2013-07-12 14:30:26 +08:00
|
|
|
Rect bounds = Rect(0, 0, texture->getContentSize().width, texture->getContentSize().height);
|
2013-07-12 18:04:32 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
spriteFrame = SpriteFrame::createWithTexture(texture, bounds);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-03 18:27:50 +08:00
|
|
|
spriteSheet = mCCBRootPath + spriteSheet;
|
2013-07-12 06:24:23 +08:00
|
|
|
SpriteFrameCache* frameCache = SpriteFrameCache::getInstance();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
// Load the sprite sheet only if it is not loaded
|
2012-11-26 21:51:05 +08:00
|
|
|
if (mLoadedSpriteSheets.find(spriteSheet) == mLoadedSpriteSheets.end())
|
2012-09-17 14:27:17 +08:00
|
|
|
{
|
2012-11-26 21:51:05 +08:00
|
|
|
frameCache->addSpriteFramesWithFile(spriteSheet.c_str());
|
|
|
|
mLoadedSpriteSheets.insert(spriteSheet);
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
spriteFrame = frameCache->getSpriteFrameByName(spriteFile.c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
value = spriteFrame;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
keyframe->setValue(value);
|
|
|
|
|
|
|
|
return keyframe;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
bool CCBReader::readCallbackKeyframesForSeq(CCBSequence* seq) {
|
|
|
|
int numKeyframes = readInt(false);
|
|
|
|
if(!numKeyframes) return true;
|
|
|
|
|
|
|
|
CCBSequenceProperty* channel = new CCBSequenceProperty();
|
2013-03-19 16:33:23 +08:00
|
|
|
channel->autorelease();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
for(int i = 0; i < numKeyframes; ++i) {
|
|
|
|
|
|
|
|
float time = readFloat();
|
|
|
|
std::string callbackName = readCachedString();
|
|
|
|
|
|
|
|
int callbackType = readInt(false);
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* value = Array::create();
|
|
|
|
value->addObject(String::create(callbackName));
|
|
|
|
value->addObject(String::createWithFormat("%d", callbackType));
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
CCBKeyframe* keyframe = new CCBKeyframe();
|
2013-03-19 16:33:23 +08:00
|
|
|
keyframe->autorelease();
|
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
keyframe->setTime(time);
|
|
|
|
keyframe->setValue(value);
|
|
|
|
|
|
|
|
if(jsControlled) {
|
|
|
|
string callbackIdentifier;
|
2013-06-20 14:15:53 +08:00
|
|
|
mActionManager->getKeyframeCallbacks()->addObject(String::createWithFormat("%d:%s",callbackType, callbackName.c_str()));
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
channel->getKeyframes()->addObject(keyframe);
|
|
|
|
}
|
|
|
|
|
|
|
|
seq->setCallbackChannel(channel);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCBReader::readSoundKeyframesForSeq(CCBSequence* seq) {
|
|
|
|
int numKeyframes = readInt(false);
|
|
|
|
if(!numKeyframes) return true;
|
|
|
|
|
|
|
|
CCBSequenceProperty* channel = new CCBSequenceProperty();
|
2013-03-21 09:00:55 +08:00
|
|
|
channel->autorelease();
|
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
for(int i = 0; i < numKeyframes; ++i) {
|
|
|
|
|
|
|
|
float time = readFloat();
|
|
|
|
std::string soundFile = readCachedString();
|
|
|
|
float pitch = readFloat();
|
|
|
|
float pan = readFloat();
|
|
|
|
float gain = readFloat();
|
2013-03-19 14:15:36 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* value = Array::create();
|
2013-03-15 08:43:56 +08:00
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
value->addObject(String::create(soundFile));
|
|
|
|
value->addObject(String::createWithFormat("%f", pitch));
|
|
|
|
value->addObject(String::createWithFormat("%f", pan));
|
|
|
|
value->addObject(String::createWithFormat("%f", gain));
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
CCBKeyframe* keyframe = new CCBKeyframe();
|
|
|
|
keyframe->setTime(time);
|
|
|
|
keyframe->setValue(value);
|
|
|
|
channel->getKeyframes()->addObject(keyframe);
|
2013-03-21 09:00:55 +08:00
|
|
|
keyframe->release();
|
2013-03-15 08:43:56 +08:00
|
|
|
}
|
|
|
|
|
2013-03-19 14:15:36 +08:00
|
|
|
seq->setSoundChannel(channel);
|
2013-03-15 08:43:56 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Node * CCBReader::readNodeGraph() {
|
2012-09-17 14:27:17 +08:00
|
|
|
return this->readNodeGraph(NULL);
|
2012-06-05 08:45:25 +08:00
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
bool CCBReader::readSequences()
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
Array *sequences = mActionManager->getSequences();
|
2012-09-17 14:27:17 +08:00
|
|
|
|
|
|
|
int numSeqs = readInt(false);
|
|
|
|
|
|
|
|
for (int i = 0; i < numSeqs; i++)
|
|
|
|
{
|
|
|
|
CCBSequence *seq = new CCBSequence();
|
|
|
|
seq->autorelease();
|
|
|
|
|
|
|
|
seq->setDuration(readFloat());
|
2012-11-26 21:51:05 +08:00
|
|
|
seq->setName(readCachedString().c_str());
|
2012-09-17 14:27:17 +08:00
|
|
|
seq->setSequenceId(readInt(false));
|
|
|
|
seq->setChainedSequenceId(readInt(true));
|
|
|
|
|
2013-03-15 08:43:56 +08:00
|
|
|
if(!readCallbackKeyframesForSeq(seq)) return false;
|
|
|
|
if(!readSoundKeyframesForSeq(seq)) return false;
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
sequences->addObject(seq);
|
|
|
|
}
|
|
|
|
|
|
|
|
mActionManager->setAutoPlaySequenceId(readInt(true));
|
|
|
|
return true;
|
2012-06-05 08:45:25 +08:00
|
|
|
}
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
std::string CCBReader::lastPathComponent(const char* pPath) {
|
|
|
|
std::string path(pPath);
|
2013-03-03 10:32:09 +08:00
|
|
|
size_t slashPos = path.find_last_of("/");
|
2012-06-06 08:15:28 +08:00
|
|
|
if(slashPos != std::string::npos) {
|
2012-11-26 21:51:05 +08:00
|
|
|
return path.substr(slashPos + 1, path.length() - slashPos);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2012-11-26 21:51:05 +08:00
|
|
|
return path;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
std::string CCBReader::deletePathExtension(const char* pPath) {
|
|
|
|
std::string path(pPath);
|
2013-03-03 10:32:09 +08:00
|
|
|
size_t dotPos = path.find_last_of(".");
|
2012-06-06 08:15:28 +08:00
|
|
|
if(dotPos != std::string::npos) {
|
2012-11-26 21:51:05 +08:00
|
|
|
return path.substr(0, dotPos);
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
2012-11-26 21:51:05 +08:00
|
|
|
return path;
|
2012-05-31 02:28:50 +08:00
|
|
|
}
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
std::string CCBReader::toLowerCase(const char* pString) {
|
|
|
|
std::string copy(pString);
|
2012-05-31 02:28:50 +08:00
|
|
|
std::transform(copy.begin(), copy.end(), copy.begin(), ::tolower);
|
2012-11-26 21:51:05 +08:00
|
|
|
return copy;
|
2012-06-12 09:31:11 +08:00
|
|
|
}
|
|
|
|
|
2012-11-26 21:51:05 +08:00
|
|
|
bool CCBReader::endsWith(const char* pString, const char* pEnding) {
|
|
|
|
std::string string(pString);
|
|
|
|
std::string ending(pEnding);
|
2012-06-06 08:15:28 +08:00
|
|
|
if(string.length() >= ending.length()) {
|
2012-06-05 08:45:25 +08:00
|
|
|
return (string.compare(string.length() - ending.length(), ending.length(), ending) == 0);
|
2012-05-31 02:28:50 +08:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-07-19 17:22:36 +08:00
|
|
|
|
2012-11-01 02:06:56 +08:00
|
|
|
bool CCBReader::isJSControlled() {
|
|
|
|
return jsControlled;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBReader::addOwnerCallbackName(std::string name) {
|
2012-11-26 21:51:05 +08:00
|
|
|
mOwnerCallbackNames.push_back(name);
|
2012-11-01 02:06:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBReader::addOwnerCallbackNode(Node *node) {
|
2012-11-01 02:06:56 +08:00
|
|
|
mOwnerCallbackNodes->addObject(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CCBReader::addDocumentCallbackName(std::string name) {
|
|
|
|
mActionManager->addDocumentCallbackName(name);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBReader::addDocumentCallbackNode(Node *node) {
|
2012-11-01 02:06:56 +08:00
|
|
|
mActionManager->addDocumentCallbackNode(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBReader::getOwnerCallbackNames() {
|
|
|
|
Array* pRet = Array::createWithCapacity(mOwnerCallbackNames.size());
|
2012-11-26 21:51:05 +08:00
|
|
|
std::vector<std::string>::iterator it = mOwnerCallbackNames.begin();
|
|
|
|
for (; it != mOwnerCallbackNames.end(); ++it)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
pRet->addObject(String::create(*it));
|
2012-11-26 21:51:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
2012-11-01 02:06:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBReader::getOwnerCallbackNodes() {
|
2012-11-01 02:06:56 +08:00
|
|
|
return mOwnerCallbackNodes;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBReader::getOwnerOutletNames() {
|
|
|
|
Array* pRet = Array::createWithCapacity(mOwnerOutletNames.size());
|
2012-11-26 21:51:05 +08:00
|
|
|
std::vector<std::string>::iterator it = mOwnerOutletNames.begin();
|
|
|
|
for (; it != mOwnerOutletNames.end(); ++it)
|
|
|
|
{
|
2013-06-20 14:15:53 +08:00
|
|
|
pRet->addObject(String::create(*it));
|
2012-11-26 21:51:05 +08:00
|
|
|
}
|
|
|
|
return pRet;
|
2012-11-01 02:06:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBReader::getOwnerOutletNodes() {
|
2012-11-01 02:06:56 +08:00
|
|
|
return mOwnerOutletNodes;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBReader::getNodesWithAnimationManagers() {
|
2012-11-01 02:06:56 +08:00
|
|
|
return mNodesWithAnimationManagers;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:15:53 +08:00
|
|
|
Array* CCBReader::getAnimationManagersForNodes() {
|
2012-11-26 21:51:05 +08:00
|
|
|
return mAnimationManagersForNodes;
|
2012-11-01 02:06:56 +08:00
|
|
|
}
|
|
|
|
|
2013-06-05 15:17:00 +08:00
|
|
|
void CCBReader::addOwnerOutletName(std::string name)
|
|
|
|
{
|
|
|
|
mOwnerOutletNames.push_back(name);
|
|
|
|
|
|
|
|
}
|
2013-06-20 14:15:53 +08:00
|
|
|
void CCBReader::addOwnerOutletNode(Node *node)
|
2013-06-05 15:17:00 +08:00
|
|
|
{
|
|
|
|
if (NULL != node)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mOwnerOutletNodes->addObject(node);
|
|
|
|
}
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
/************************************************************************
|
|
|
|
Static functions
|
|
|
|
************************************************************************/
|
|
|
|
|
2013-04-23 10:34:16 +08:00
|
|
|
static float __ccbResolutionScale = 1.0f;
|
|
|
|
|
2012-09-17 14:27:17 +08:00
|
|
|
float CCBReader::getResolutionScale()
|
|
|
|
{
|
2013-04-23 10:34:16 +08:00
|
|
|
return __ccbResolutionScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCBReader::setResolutionScale(float scale)
|
|
|
|
{
|
|
|
|
__ccbResolutionScale = scale;
|
2012-09-17 14:27:17 +08:00
|
|
|
}
|
|
|
|
|
2012-07-19 17:22:36 +08:00
|
|
|
NS_CC_EXT_END;
|