#ifndef _CCB_READER_H_ #define _CCB_READER_H_ #include "cocos2d.h" #include "CCBMemberVariableAssigner.h" #include "CCBSelectorResolver.h" #define STATIC_NEW_AUTORELEASE_OBJECT_METHOD(T, METHOD) static T * METHOD() { \ T * t = new T(); \ t->autorelease(); \ return t; \ } #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 NS_CC_EXT_BEGIN /* Forward declaration. */ class CCNodeLoader; class CCNodeLoaderLibrary; /** * @brief Parse CCBI file which is generated by CocosBuilder */ class CC_DLL CCBReader : public CCObject { private: bool mRootCCBReader; unsigned char * mBytes; int mCurrentByte; int mCurrentBit; CCObject * mOwner; CCNode * mRootNode; CCSize mRootContainerSize; float mResolutionScale; CCNodeLoaderLibrary * mCCNodeLoaderLibrary; CCBMemberVariableAssigner * mCCBMemberVariableAssigner; CCBSelectorResolver * mCCBSelectorResolver; std::vector mStringCache; std::set mLoadedSpriteSheets; public: /* Constructor. */ CCBReader(CCNodeLoaderLibrary *, CCBMemberVariableAssigner * = NULL, CCBSelectorResolver * = NULL); CCBReader(CCBReader *); /* Destructor. */ ~CCBReader(); CCNode * readNodeGraphFromFile(const char * pCCBFileName, CCObject * pOwner = NULL); CCNode * readNodeGraphFromFile(const char * pCCBFileName, CCObject * pOwner, CCSize pRootContainerSize); CCBMemberVariableAssigner * getCCBMemberVariableAssigner(); CCBSelectorResolver * getCCBSelectorResolver(); CCObject * getOwner(); CCNode * getRootNode(); CCSize getContainerSize(CCNode *); float getResolutionScale(); bool isSpriteSheetLoaded(const char *); void addLoadedSpriteSheet(const char *); /* Utility methods. */ const char * lastPathComponent(const char *); const char * deletePathExtension(const char *); const char * toLowerCase(const char *); bool endsWith(const char *, const char *); /* Parse methods. */ int readInt(bool pSign); unsigned char readByte(); bool readBool(); float readFloat(); const char * readCachedString(); private: bool readHeader(); bool readStringCache(); void readStringCacheEntry(); CCNode * readNodeGraph(); CCNode * readNodeGraph(CCNode *); bool getBit(); void alignBits(); const char * readUTF8(); }; NS_CC_EXT_END #endif