2012-06-14 05:19:13 +08:00
|
|
|
#ifndef _CCB_CCBREADER_H_
|
|
|
|
#define _CCB_CCBREADER_H_
|
2012-05-03 11:58:53 +08:00
|
|
|
|
|
|
|
#include "cocos2d.h"
|
2012-07-20 14:05:52 +08:00
|
|
|
#include "ExtensionMacros.h"
|
2012-05-03 14:43:27 +08:00
|
|
|
|
2012-06-15 05:23:53 +08:00
|
|
|
#define CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(T, METHOD) static T * METHOD() { \
|
2012-06-15 09:16:54 +08:00
|
|
|
T * ptr = new T(); \
|
|
|
|
if(ptr != NULL) { \
|
|
|
|
ptr->autorelease(); \
|
|
|
|
return ptr; \
|
|
|
|
} \
|
|
|
|
CC_SAFE_DELETE(ptr); \
|
|
|
|
return NULL; \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(T, METHOD) static T * METHOD() { \
|
|
|
|
T * ptr = new T(); \
|
|
|
|
if(ptr != NULL && ptr->init()) { \
|
|
|
|
ptr->autorelease(); \
|
|
|
|
return ptr; \
|
|
|
|
} \
|
|
|
|
CC_SAFE_DELETE(ptr); \
|
|
|
|
return NULL; \
|
2012-06-14 05:19:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define kCCBVersion 2
|
|
|
|
|
|
|
|
#define kCCBPropTypePosition 0
|
|
|
|
#define kCCBPropTypeSize 1
|
|
|
|
#define kCCBPropTypePoint 2
|
|
|
|
#define kCCBPropTypePointLock 3
|
|
|
|
#define kCCBPropTypeScaleLock 4
|
|
|
|
#define kCCBPropTypeDegrees 5
|
|
|
|
#define kCCBPropTypeInteger 6
|
|
|
|
#define kCCBPropTypeFloat 7
|
|
|
|
#define kCCBPropTypeFloatVar 8
|
|
|
|
#define kCCBPropTypeCheck 9
|
|
|
|
#define kCCBPropTypeSpriteFrame 10
|
|
|
|
#define kCCBPropTypeTexture 11
|
|
|
|
#define kCCBPropTypeByte 12
|
|
|
|
#define kCCBPropTypeColor3 13
|
|
|
|
#define kCCBPropTypeColor4FVar 14
|
|
|
|
#define kCCBPropTypeFlip 15
|
|
|
|
#define kCCBPropTypeBlendFunc 16
|
|
|
|
#define kCCBPropTypeFntFile 17
|
|
|
|
#define kCCBPropTypeText 18
|
|
|
|
#define kCCBPropTypeFontTTF 19
|
|
|
|
#define kCCBPropTypeIntegerLabeled 20
|
|
|
|
#define kCCBPropTypeBlock 21
|
|
|
|
#define kCCBPropTypeAnimation 22
|
|
|
|
#define kCCBPropTypeCCBFile 23
|
|
|
|
#define kCCBPropTypeString 24
|
|
|
|
#define kCCBPropTypeBlockCCControl 25
|
|
|
|
#define kCCBPropTypeFloatScale 26
|
|
|
|
|
|
|
|
#define kCCBFloat0 0
|
|
|
|
#define kCCBFloat1 1
|
|
|
|
#define kCCBFloatMinus1 2
|
|
|
|
#define kCCBFloat05 3
|
|
|
|
#define kCCBFloatInteger 4
|
|
|
|
#define kCCBFloatFull 5
|
|
|
|
|
|
|
|
#define kCCBPlatformAll 0
|
|
|
|
#define kCCBPlatformIOS 1
|
|
|
|
#define kCCBPlatformMac 2
|
|
|
|
|
|
|
|
#define kCCBTargetTypeNone 0
|
|
|
|
#define kCCBTargetTypeDocumentRoot 1
|
|
|
|
#define kCCBTargetTypeOwner 2
|
|
|
|
|
|
|
|
#define kCCBPositionTypeRelativeBottomLeft 0
|
|
|
|
#define kCCBPositionTypeRelativeTopLeft 1
|
|
|
|
#define kCCBPositionTypeRelativeTopRight 2
|
|
|
|
#define kCCBPositionTypeRelativeBottomRight 3
|
|
|
|
#define kCCBPositionTypePercent 4
|
|
|
|
|
|
|
|
#define kCCBSizeTypeAbsolute 0
|
|
|
|
#define kCCBSizeTypePercent 1
|
|
|
|
#define kCCBSizeTypeRelativeContainer 2
|
|
|
|
#define kCCBSizeTypeHorizontalPercent 3
|
|
|
|
#define kCCBSzieTypeVerticalPercent 4
|
|
|
|
|
|
|
|
|
|
|
|
#define kCCBScaleTypeAbsolute 0
|
|
|
|
#define kCCBScaleTypeMultiplyResolution 1
|
2012-06-12 01:43:07 +08:00
|
|
|
|
2012-07-19 17:22:36 +08:00
|
|
|
USING_NS_CC;
|
2012-05-07 17:05:17 +08:00
|
|
|
NS_CC_EXT_BEGIN
|
2012-05-03 11:58:53 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup cocosbuilder
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2012-06-14 05:19:13 +08:00
|
|
|
/* Forward declaration. */
|
|
|
|
class CCNodeLoader;
|
|
|
|
class CCNodeLoaderLibrary;
|
|
|
|
class CCNodeLoaderListener;
|
|
|
|
class CCBMemberVariableAssigner;
|
|
|
|
class CCBSelectorResolver;
|
|
|
|
|
2012-05-07 18:14:15 +08:00
|
|
|
/**
|
2012-06-14 05:19:13 +08:00
|
|
|
* @brief Parse CCBI file which is generated by CocosBuilder
|
2012-05-07 18:14:15 +08:00
|
|
|
*/
|
2012-07-20 14:05:52 +08:00
|
|
|
class CCBReader : public CCObject {
|
2012-06-14 05:19:13 +08:00
|
|
|
private:
|
2012-06-14 15:01:01 +08:00
|
|
|
CCString * mCCBRootPath;
|
2012-06-14 05:19:13 +08:00
|
|
|
bool mRootCCBReader;
|
|
|
|
|
|
|
|
unsigned char * mBytes;
|
|
|
|
int mCurrentByte;
|
|
|
|
int mCurrentBit;
|
|
|
|
CCObject * mOwner;
|
|
|
|
CCNode * mRootNode;
|
|
|
|
CCSize mRootContainerSize;
|
|
|
|
float mResolutionScale;
|
|
|
|
|
|
|
|
CCNodeLoaderLibrary * mCCNodeLoaderLibrary;
|
|
|
|
CCNodeLoaderListener * mCCNodeLoaderListener;
|
|
|
|
CCBMemberVariableAssigner * mCCBMemberVariableAssigner;
|
|
|
|
CCBSelectorResolver * mCCBSelectorResolver;
|
|
|
|
|
2012-06-14 15:01:01 +08:00
|
|
|
std::vector<CCString *> mStringCache;
|
2012-06-14 05:19:13 +08:00
|
|
|
std::set<std::string> mLoadedSpriteSheets;
|
|
|
|
|
|
|
|
public:
|
2012-06-19 03:03:06 +08:00
|
|
|
CCBReader(CCNodeLoaderLibrary * pCCNodeLoaderLibrary, CCBMemberVariableAssigner * pCCBMemberVariableAssigner = NULL, CCBSelectorResolver * pCCBSelectorResolver = NULL, CCNodeLoaderListener * pCCNodeLoaderListener = NULL);
|
|
|
|
CCBReader(CCBReader * pCCBReader);
|
|
|
|
virtual ~CCBReader();
|
2012-06-14 15:01:01 +08:00
|
|
|
|
2012-06-14 05:19:13 +08:00
|
|
|
CCNode * readNodeGraphFromFile(const char * pCCBRootPath, const char * pCCBFileName, CCObject * pOwner = NULL);
|
2012-06-14 15:01:01 +08:00
|
|
|
CCNode * readNodeGraphFromFile(CCString * pCCBRootPath, CCString * pCCBFileName, CCObject * pOwner = NULL);
|
2012-06-14 05:19:13 +08:00
|
|
|
CCNode * readNodeGraphFromFile(const char * pCCBRootPath, const char * pCCBFileName, CCObject * pOwner, CCSize pRootContainerSize);
|
2012-06-14 15:01:01 +08:00
|
|
|
CCNode * readNodeGraphFromFile(CCString * pCCBRootPath, CCString * pCCBFileName, CCObject * pOwner, CCSize pRootContainerSize);
|
|
|
|
|
2012-06-14 05:19:13 +08:00
|
|
|
CCBMemberVariableAssigner * getCCBMemberVariableAssigner();
|
|
|
|
CCBSelectorResolver * getCCBSelectorResolver();
|
|
|
|
|
2012-06-14 15:01:01 +08:00
|
|
|
CCString * getCCBRootPath();
|
2012-06-14 05:19:13 +08:00
|
|
|
CCObject * getOwner();
|
|
|
|
CCNode * getRootNode();
|
2012-06-19 03:03:06 +08:00
|
|
|
CCSize getContainerSize(CCNode * pNode);
|
2012-06-14 05:19:13 +08:00
|
|
|
float getResolutionScale();
|
|
|
|
|
2012-06-19 03:03:06 +08:00
|
|
|
bool isSpriteSheetLoaded(CCString * pSpriteSheet);
|
|
|
|
void addLoadedSpriteSheet(CCString * pSpriteSheet);
|
2012-06-14 05:19:13 +08:00
|
|
|
|
|
|
|
/* Utility methods. */
|
2012-06-19 03:03:06 +08:00
|
|
|
static CCString * lastPathComponent(CCString * pString);
|
|
|
|
static CCString * deletePathExtension(CCString * pString);
|
|
|
|
static CCString * toLowerCase(CCString * pCCString);
|
|
|
|
static bool endsWith(CCString * pString, CCString * pEnding);
|
|
|
|
static CCString * concat(CCString * pStringA, CCString * pStringB);
|
2012-06-14 05:19:13 +08:00
|
|
|
|
|
|
|
/* Parse methods. */
|
2012-06-19 03:03:06 +08:00
|
|
|
int readInt(bool pSigned);
|
2012-06-14 05:19:13 +08:00
|
|
|
unsigned char readByte();
|
|
|
|
bool readBool();
|
|
|
|
float readFloat();
|
2012-06-14 15:01:01 +08:00
|
|
|
CCString * readCachedString();
|
2012-06-14 05:19:13 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool readHeader();
|
|
|
|
bool readStringCache();
|
|
|
|
void readStringCacheEntry();
|
|
|
|
CCNode * readNodeGraph();
|
2012-06-19 03:03:06 +08:00
|
|
|
CCNode * readNodeGraph(CCNode * pParent);
|
2012-06-14 05:19:13 +08:00
|
|
|
|
|
|
|
bool getBit();
|
|
|
|
void alignBits();
|
2012-06-14 15:01:01 +08:00
|
|
|
CCString * readUTF8();
|
2012-06-14 05:19:13 +08:00
|
|
|
};
|
2012-05-03 11:58:53 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of effects group
|
|
|
|
/// @}
|
|
|
|
|
2012-05-07 17:05:17 +08:00
|
|
|
NS_CC_EXT_END
|
2012-05-03 14:43:27 +08:00
|
|
|
|
2012-06-14 05:19:13 +08:00
|
|
|
#endif
|