Merge pull request #2194 from rohankuruvilla/ccbreader

fixed #1838: Latest CCBReader changes.
This commit is contained in:
James Chen 2013-03-18 21:56:13 -07:00
commit deb739f13b
16 changed files with 594 additions and 107 deletions

View File

@ -54,6 +54,7 @@ physics_nodes/CCPhysicsSprite.cpp \
LocalStorage/LocalStorageAndroid.cpp
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos_curl_static
LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static
LOCAL_WHOLE_STATIC_LIBRARIES += chipmunk_static
@ -68,6 +69,7 @@ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) \
include $(BUILD_STATIC_LIBRARY)
$(call import-module,cocos2dx)
$(call import-module,CocosDenshion/android)
$(call import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)
$(call import-module,external/Box2D)
$(call import-module,external/chipmunk)

View File

@ -6,6 +6,8 @@
#include "CCNode+CCBRelativePositioning.h"
#include <string>
#include <set>
#include "SimpleAudioEngine.h"
#include "CCBSelectorResolver.h"
using namespace cocos2d;
using namespace std;
@ -21,6 +23,8 @@ CCBAnimationManager::CCBAnimationManager()
, mAutoPlaySequenceId(0)
, mRootNode(NULL)
, mRootContainerSize(CCSizeZero)
, mOwner(NULL)
, jsControlled(false)
, mDelegate(NULL)
, mRunningSequence(NULL)
{
@ -37,7 +41,9 @@ bool CCBAnimationManager::init()
mDocumentOutletNodes = new CCArray();
mDocumentCallbackNames = new CCArray();
mDocumentCallbackNodes = new CCArray();
mKeyframeCallbacks = new CCArray();
mKeyframeCallFuncs = new CCDictionary();
mTarget = NULL;
mAnimationCompleteCallbackFunc = NULL;
@ -69,7 +75,9 @@ CCBAnimationManager::~CCBAnimationManager()
CC_SAFE_RELEASE(mDocumentOutletNodes);
CC_SAFE_RELEASE(mDocumentCallbackNames);
CC_SAFE_RELEASE(mDocumentCallbackNodes);
CC_SAFE_RELEASE(mKeyframeCallFuncs);
CC_SAFE_RELEASE(mKeyframeCallbacks);
CC_SAFE_RELEASE(mTarget);
}
@ -149,6 +157,10 @@ std::string CCBAnimationManager::getLastCompletedSequenceName() {
return lastCompletedSequenceName;
}
CCArray* CCBAnimationManager::getKeyframeCallbacks() {
return mKeyframeCallbacks;
}
const CCSize& CCBAnimationManager::getRootContainerSize()
{
return mRootContainerSize;
@ -345,6 +357,15 @@ CCActionInterval* CCBAnimationManager::getAction(CCBKeyframe *pKeyframe0, CCBKey
return CCScaleTo::create(duration, x, y);
}
else if(strcmp(pPropName, "skew") == 0)
{
// Get relative skew
CCArray *value = (CCArray*)pKeyframe1->getValue();
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
return CCSkewTo::create(duration, x, y);
}
else
{
CCLog("CCBReader: Failed to create animation for property: %s", pPropName);
@ -398,6 +419,17 @@ void CCBAnimationManager::setAnimatedProperty(const char *pPropName, CCNode *pNo
setRelativeScale(pNode, x, y, type, pPropName);
}
else if(strcmp(pPropName, "skew") == 0)
{
// Get relative scale
CCArray *value = (CCArray*)pValue;
float x = ((CCBValue*)value->objectAtIndex(0))->getFloatValue();
float y = ((CCBValue*)value->objectAtIndex(1))->getFloatValue();
pNode->setSkewX(x);
pNode->setSkewY(y);
}
else
{
// [node setValue:value forKey:name];
@ -525,6 +557,109 @@ CCActionInterval* CCBAnimationManager::getEaseAction(CCActionInterval *pAction,
}
}
CCObject* CCBAnimationManager::actionForCallbackChannel(CCBSequenceProperty* channel) {
float lastKeyframeTime = 0;
CCArray *actions = CCArray::create();
CCArray *keyframes = channel->getKeyframes();
int numKeyframes = keyframes->count();
for (int i = 0; i < numKeyframes - 1; ++i) {
CCBKeyframe *keyframe = (CCBKeyframe*)keyframes->objectAtIndex(i);
float timeSinceLastKeyframe = keyframe->getTime() - lastKeyframeTime;
if(timeSinceLastKeyframe > 0) {
actions->addObject(CCDelayTime::create(timeSinceLastKeyframe));
}
CCArray* keyVal = (CCArray *)keyframe->getValue();
std::string selectorName = ((CCString *)keyVal->objectAtIndex(0))->getCString();
int selectorTarget = atoi(((CCString *)keyVal->objectAtIndex(0))->getCString());
if(jsControlled) {
stringstream ss;//create a stringstream
ss << selectorTarget;//add number to the stream
std::string callbackName = ss.str() + ":" + selectorName;
CCCallFuncN *callback = (CCCallFuncN*)mKeyframeCallFuncs->objectForKey(callbackName.c_str());
if(callback != NULL) {
actions->addObject(callback);
}
} else {
CCObject *target;
if(selectorTarget == kCCBTargetTypeDocumentRoot) target = mRootNode;
else if (selectorTarget == kCCBTargetTypeOwner) target = mOwner;
if(target != NULL) {
if(selectorName.length() > 0) {
SEL_CallFuncN selCallFunc = 0;
CCBSelectorResolver* targetAsCCBSelectorResolver = dynamic_cast<CCBSelectorResolver *>(target);
if(targetAsCCBSelectorResolver != NULL) {
selCallFunc = targetAsCCBSelectorResolver->onResolveCCBCCCallFuncSelector(target, selectorName.c_str ());
}
if(selCallFunc == 0) {
CCLOG("Skipping selector '%s' since no CCBSelectorResolver is present.", selectorName.c_str());
} else {
CCCallFuncN *callback = CCCallFuncN::create(target, selCallFunc);
actions->addObject(callback);
}
} else {
CCLOG("Unexpected empty selector.");
}
}
}
}
if(actions->count() < 1) return NULL;
return (CCObject *) CCSequence::create(actions);
}
CCObject* CCBAnimationManager::actionForSoundChannel(CCBSequenceProperty* channel) {
float lastKeyframeTime = 0;
CCArray *actions = CCArray::create();
CCArray *keyframes = channel->getKeyframes();
int numKeyframes = keyframes->count();
for (int i = 0; i < numKeyframes - 1; ++i) {
CCBKeyframe *keyframe = (CCBKeyframe*)keyframes->objectAtIndex(i);
float timeSinceLastKeyframe = keyframe->getTime() - lastKeyframeTime;
if(timeSinceLastKeyframe > 0) {
actions->addObject(CCDelayTime::create(timeSinceLastKeyframe));
}
stringstream ss (stringstream::in | stringstream::out);
CCArray* keyVal = (CCArray*)keyframe->getValue();
std::string soundFile = ((CCString *)keyVal->objectAtIndex(0))->getCString();
float pitch, pan, gain;
ss << ((CCString *)keyVal->objectAtIndex(1))->getCString();
ss >> pitch;
ss.flush();
ss << ((CCString *)keyVal->objectAtIndex(2))->getCString();
ss >> pan;
ss.flush();
ss << ((CCString *)keyVal->objectAtIndex(3))->getCString();
ss >> gain;
ss.flush();
actions->addObject(CCBSoundEffect::actionWithSoundFile(soundFile, pitch, pan, gain));
}
if(actions->count() < 1) return NULL;
return (CCObject *) CCSequence::create(actions);
}
void CCBAnimationManager::runAction(CCNode *pNode, CCBSequenceProperty *pSeqProp, float fTweenDuration)
{
CCArray *keyframes = pSeqProp->getKeyframes();
@ -638,6 +773,21 @@ void CCBAnimationManager::runAnimationsForSequenceIdTweenDuration(int nSeqId, fl
mRootNode->runAction(completeAction);
// Set the running scene
if(seq->getCallbackChannel() != NULL) {
CCAction* action = (CCAction *)actionForCallbackChannel(seq->getCallbackChannel());
if(action != NULL) {
mRootNode->runAction(action);
}
}
if(seq->getSoundChannel() != NULL) {
CCAction* action = (CCAction *)actionForSoundChannel(seq->getSoundChannel());
if(action != NULL) {
mRootNode->runAction(action);
}
}
mRunningSequence = getSequence(nSeqId);
}
@ -672,6 +822,10 @@ void CCBAnimationManager::setAnimationCompletedCallback(CCObject *target, SEL_Ca
mAnimationCompleteCallbackFunc = callbackFunc;
}
void CCBAnimationManager::setCallFunc(CCCallFuncN* callFunc, const std::string &callbackNamed) {
mKeyframeCallFuncs->setObject((CCObject*)callFunc, callbackNamed);
}
void CCBAnimationManager::sequenceCompleted()
{
const char *runningSequenceName = mRunningSequence->getName();
@ -759,6 +913,63 @@ void CCBSetSpriteFrame::update(float time)
((CCSprite*)m_pTarget)->setDisplayFrame(mSpriteFrame);
}
/************************************************************
CCBSoundEffect
************************************************************/
CCBSoundEffect* CCBSoundEffect::actionWithSoundFile(const std::string &filename, float pitch, float pan, float gain) {
CCBSoundEffect* pRet = new CCBSoundEffect();
if (pRet != NULL && pRet->initWithSoundFile(filename, pitch, pan, gain))
{
pRet->autorelease();
}
else
{
CC_SAFE_DELETE(pRet);
}
return pRet;
}
CCBSoundEffect::~CCBSoundEffect()
{
}
bool CCBSoundEffect::initWithSoundFile(const std::string &filename, float pitch, float pan, float gain) {
mSoundFile = filename;
mPitch = pitch;
mPan = pan;
mGain = gain;
return true;
}
CCObject* CCBSoundEffect::copyWithZone(CCZone *pZone)
{
CCZone *pNewZone = NULL;
CCBSoundEffect *pRet = NULL;
if (pZone && pZone->m_pCopyObject) {
pRet = (CCBSoundEffect*) (pZone->m_pCopyObject);
} else {
pRet = new CCBSoundEffect();
pZone = pNewZone = new CCZone(pRet);
}
pRet->initWithSoundFile(mSoundFile, mPitch, mPan, mGain);
CCActionInstant::copyWithZone(pZone);
CC_SAFE_DELETE(pNewZone);
return pRet;
}
void CCBSoundEffect::update(float time)
{
CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect(mSoundFile.c_str());
}
/************************************************************
CCBRotateTo
************************************************************/

View File

@ -24,6 +24,7 @@ private:
int mAutoPlaySequenceId;
CCNode *mRootNode;
CCSize mRootContainerSize;
CCBAnimationManagerDelegate *mDelegate;
@ -33,6 +34,9 @@ private:
CCArray *mDocumentOutletNodes;
CCArray *mDocumentCallbackNames;
CCArray *mDocumentCallbackNodes;
CCArray *mKeyframeCallbacks;
CCDictionary *mKeyframeCallFuncs;
std::string mDocumentControllerName;
std::string lastCompletedSequenceName;
@ -41,8 +45,12 @@ private:
public:
bool jsControlled;
CCBAnimationManager();
~CCBAnimationManager();
CCObject *mOwner;
virtual bool init();
@ -71,6 +79,7 @@ public:
CCArray* getDocumentOutletNodes();
std::string getLastCompletedSequenceName();
CCArray* getKeyframeCallbacks();
const CCSize& getRootContainerSize();
void setRootContainerSize(const CCSize &rootContainerSize);
@ -101,6 +110,11 @@ public:
void debug();
void setCallFunc(CCCallFuncN *callFunc, const std::string &callbackNamed);
CCObject* actionForCallbackChannel(CCBSequenceProperty* channel);
CCObject* actionForSoundChannel(CCBSequenceProperty* channel);
private:
CCObject* getBaseValue(CCNode *pNode, const char* pPropName);
int getSequenceId(const char* pSequenceName);
@ -128,6 +142,23 @@ public:
virtual CCObject* copyWithZone(CCZone *pZone);
};
class CCBSoundEffect : public CCActionInstant
{
private:
std::string mSoundFile;
float mPitch, mPan, mGain;
public:
~CCBSoundEffect();
static CCBSoundEffect* actionWithSoundFile(const std::string &file, float pitch, float pan, float gain);
bool initWithSoundFile(const std::string &file, float pitch, float pan, float gain);
virtual void update(float time);
virtual CCObject* copyWithZone(CCZone *pZone);
};
class CCBRotateTo : public CCActionInterval
{
private:
@ -151,6 +182,7 @@ public:
virtual void update(float dt);
};
NS_CC_EXT_END
#endif // __CCB_CCBANIMATION_MANAGER_H__

View File

@ -270,14 +270,14 @@ CCNode* CCBReader::readNodeGraphFromData(CCData *pData, CCObject *pOwner, const
CC_SAFE_RETAIN(mOwner);
mActionManager->setRootContainerSize(parentSize);
mActionManager->mOwner = mOwner;
mOwnerOutletNodes = new CCArray();
mOwnerCallbackNodes = new CCArray();
CCDictionary* animationManagers = CCDictionary::create();
CCNode *pNodeGraph = readFileWithCleanUp(true, animationManagers);
if (pNodeGraph && mActionManager->getAutoPlaySequenceId() != -1)
if (pNodeGraph && mActionManager->getAutoPlaySequenceId() != -1 && !jsControlled)
{
// Auto play animations
mActionManager->runAnimationsForSequenceIdTweenDuration(mActionManager->getAutoPlaySequenceId(), 0);
@ -400,6 +400,7 @@ bool CCBReader::readHeader()
// Read JS check
jsControlled = this->readBool();
mActionManager->jsControlled = jsControlled;
return true;
}
@ -787,7 +788,8 @@ CCBKeyframe* CCBReader::readKeyframe(int type)
{
value = CCBValue::create(readFloat());
}
else if (type == kCCBPropTypeScaleLock || type == kCCBPropTypePosition)
else if (type == kCCBPropTypeScaleLock || type == kCCBPropTypePosition
|| type == kCCBPropTypeFloatXY)
{
float a = readFloat();
float b = readFloat();
@ -832,6 +834,89 @@ CCBKeyframe* CCBReader::readKeyframe(int type)
return keyframe;
}
bool CCBReader::readCallbackKeyframesForSeq(CCBSequence* seq) {
int numKeyframes = readInt(false);
if(!numKeyframes) return true;
CCBSequenceProperty* channel = new CCBSequenceProperty();
for(int i = 0; i < numKeyframes; ++i) {
float time = readFloat();
std::string callbackName = readCachedString();
int callbackType = readInt(false);
CCArray* value = CCArray::create();
value->addObject(CCString::create(callbackName));
stringstream ss;//create a stringstream
ss << callbackType;//add number to the stream
value->addObject(CCString::create(ss.str()));
CCBKeyframe* keyframe = new CCBKeyframe();
keyframe->setTime(time);
keyframe->setValue(value);
if(jsControlled) {
string callbackIdentifier;
mActionManager->getKeyframeCallbacks()->addObject(CCString::create(ss.str()+":"+callbackName));
}
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();
for(int i = 0; i < numKeyframes; ++i) {
float time = readFloat();
std::string soundFile = readCachedString();
float pitch = readFloat();
float pan = readFloat();
float gain = readFloat();
int callbackType = readInt(false);
CCArray* value = CCArray::create();
value->addObject(CCString::create(soundFile));
stringstream ss;//create a stringstream
ss << pitch;//add number to the stream
value->addObject(CCString::create(ss.str()));
ss.flush();
ss << pan;
value->addObject(CCString::create(ss.str()));
ss.flush();
ss << gain;
value->addObject(CCString::create(ss.str()));
CCBKeyframe* keyframe = new CCBKeyframe();
keyframe->setTime(time);
keyframe->setValue(value);
channel->getKeyframes()->addObject(keyframe);
}
seq->setCallbackChannel(channel);
return true;
}
CCNode * CCBReader::readNodeGraph() {
return this->readNodeGraph(NULL);
}
@ -852,6 +937,9 @@ bool CCBReader::readSequences()
seq->setSequenceId(readInt(false));
seq->setChainedSequenceId(readInt(true));
if(!readCallbackKeyframesForSeq(seq)) return false;
if(!readSoundKeyframesForSeq(seq)) return false;
sequences->addObject(seq);
}

View File

@ -5,6 +5,8 @@
#include "ExtensionMacros.h"
#include <string>
#include <vector>
#include "CCBSequence.h"
#define CCB_STATIC_NEW_AUTORELEASE_OBJECT_METHOD(T, METHOD) static T * METHOD() { \
T * ptr = new T(); \
@ -26,7 +28,7 @@
return NULL; \
}
#define kCCBVersion 4
#define kCCBVersion 5
enum {
kCCBPropTypePosition = 0,
@ -55,7 +57,8 @@ enum {
kCCBPropTypeCCBFile,
kCCBPropTypeString,
kCCBPropTypeBlockCCControl,
kCCBPropTypeFloatScale
kCCBPropTypeFloatScale,
kCCBPropTypeFloatXY
};
enum {
@ -167,7 +170,6 @@ class CCBReader : public CCObject
{
private:
bool jsControlled;
CCData *mData;
unsigned char *mBytes;
int mCurrentByte;
@ -199,6 +201,8 @@ private:
bool hasScriptingOwner;
bool init();
public:
bool jsControlled;
CCBReader(CCNodeLoaderLibrary *pCCNodeLoaderLibrary, CCBMemberVariableAssigner *pCCBMemberVariableAssigner = NULL, CCBSelectorResolver *pCCBSelectorResolver = NULL, CCNodeLoaderListener *pCCNodeLoaderListener = NULL);
CCBReader(CCBReader *pCCBReader);
virtual ~CCBReader();
@ -244,6 +248,11 @@ public:
bool isJSControlled();
bool readCallbackKeyframesForSeq(CCBSequence* seq);
bool readSoundKeyframesForSeq(CCBSequence* seq);
CCArray* getOwnerCallbackNames();
CCArray* getOwnerCallbackNodes();
CCArray* getOwnerOutletNames();

View File

@ -20,7 +20,7 @@ class CCBSelectorResolver {
public:
virtual ~CCBSelectorResolver() {};
virtual SEL_MenuHandler onResolveCCBCCMenuItemSelector(CCObject * pTarget, const char* pSelectorName) = 0;
virtual SEL_CallFuncN onResolveCCBCCCallFuncSelector(CCObject * pTarget, const char* pSelectorName) = 0;
virtual SEL_CCControlHandler onResolveCCBCCControlSelector(CCObject * pTarget, const char* pSelectorName) = 0;
};

View File

@ -11,8 +11,15 @@ CCBSequence::CCBSequence()
, mName("")
, mSequenceId(0)
, mChainedSequenceId(0)
, mCallbackChannel(NULL)
, mSoundChannel(NULL)
{}
CCBSequence::~CCBSequence() {
CC_SAFE_RELEASE(mCallbackChannel);
CC_SAFE_RELEASE(mSoundChannel);
}
float CCBSequence::getDuration()
{
return mDuration;
@ -43,6 +50,32 @@ void CCBSequence::setSequenceId(int nSequenceId)
mSequenceId = nSequenceId;
}
CCBSequenceProperty* CCBSequence::getCallbackChannel()
{
return mCallbackChannel;
}
void CCBSequence::setCallbackChannel(CCBSequenceProperty* callbackChannel)
{
CC_SAFE_RELEASE(mCallbackChannel);
mCallbackChannel = callbackChannel;
CC_SAFE_RETAIN(mCallbackChannel);
}
CCBSequenceProperty* CCBSequence::getSoundChannel()
{
return mSoundChannel;
}
void CCBSequence::setSoundChannel(CCBSequenceProperty* soundChannel)
{
CC_SAFE_RELEASE(mSoundChannel);
mSoundChannel = soundChannel;
CC_SAFE_RETAIN(mSoundChannel);
}
int CCBSequence::getChainedSequenceId()
{
return mChainedSequenceId;

View File

@ -4,6 +4,7 @@
#include <string>
#include "cocos2d.h"
#include "ExtensionMacros.h"
#include "CCBSequenceProperty.h"
NS_CC_EXT_BEGIN
@ -14,13 +15,21 @@ private:
std::string mName;
int mSequenceId;
int mChainedSequenceId;
CCBSequenceProperty* mCallbackChannel;
CCBSequenceProperty* mSoundChannel;
public:
CCBSequence();
~CCBSequence();
float getDuration();
void setDuration(float fDuration);
CCBSequenceProperty* getCallbackChannel();
void setCallbackChannel(CCBSequenceProperty* callbackChannel);
CCBSequenceProperty* getSoundChannel();
void setSoundChannel(CCBSequenceProperty* soundChannel);
const char* getName();
void setName(const char *pName);

View File

@ -93,6 +93,21 @@ CCBValue* CCBValue::create(const char *pStringValue)
return ret;
}
CCBValue* CCBValue::create(CCArray *pArrValue)
{
CCBValue *ret = new CCBValue();
if (ret)
{
ret->m_arrValue = pArrValue;
ret->mType = kArrayValue;
ret->autorelease();
}
return ret;
}
int CCBValue::getIntValue()
{
assert(mType == kIntValue);
@ -121,6 +136,13 @@ unsigned char CCBValue::getByteValue()
return (unsigned char)(mValue.nValue);
}
CCArray* CCBValue::getArrayValue() {
assert(mType == kArrayValue);
return m_arrValue;
}
const char* CCBValue::getStringValue()
{
assert(mType == kStringValue);

View File

@ -27,7 +27,8 @@ enum
kFloatValue,
kBoolValue,
kUnsignedCharValue,
kStringValue
kStringValue,
kArrayValue
};
class CCBValue : public CCObject
@ -40,6 +41,7 @@ private:
} mValue;
std::string m_strValue;
CCArray* m_arrValue;
int mType;
public:
@ -48,12 +50,15 @@ public:
static CCBValue* create(float fValue);
static CCBValue* create(unsigned char byte);
static CCBValue* create(const char* pStr);
static CCBValue* create(CCArray* pArr);
int getIntValue();
float getFloatValue();
bool getBoolValue();
unsigned char getByteValue();
const char* getStringValue();
CCArray *getArrayValue();
int getType();
};

View File

@ -156,6 +156,16 @@ void CCNodeLoader::parseProperties(CCNode * pNode, CCNode * pParent, CCBReader *
}
break;
}
case kCCBPropTypeFloatXY:
{
float * xy = this->parsePropTypeFloatXY(pNode, pParent, pCCBReader);
if(setProp)
{
this->onHandlePropTypeFloatXY(pNode, pParent, propertyName.c_str(), xy, pCCBReader);
}
break;
}
case kCCBPropTypeDegrees:
{
float degrees = this->parsePropTypeDegrees(pNode, pParent, pCCBReader, propertyName.c_str());
@ -435,6 +445,21 @@ CCSize CCNodeLoader::parsePropTypeSize(CCNode * pNode, CCNode * pParent, CCBRead
return CCSize(width, height);
}
float * CCNodeLoader::parsePropTypeFloatXY(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader) {
float x = pCCBReader->readFloat();
float y = pCCBReader->readFloat();
int type = pCCBReader->readInt(false);
float * floatXY = new float[2];
floatXY[0] = x;
floatXY[1] = y;
return floatXY;
}
float * CCNodeLoader::parsePropTypeScaleLock(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader, const char *pPropertyName) {
float x = pCCBReader->readFloat();
float y = pCCBReader->readFloat();
@ -858,6 +883,8 @@ CCNode * CCNodeLoader::parsePropTypeCCBFile(CCNode * pNode, CCNode * pParent, CC
ccbReader->mCurrentBit = 0;
CC_SAFE_RETAIN(pCCBReader->mOwner);
ccbReader->mOwner = pCCBReader->mOwner;
ccbReader->getAnimationManager()->mOwner = ccbReader->mOwner;
// The assignments below are done in the CCBReader constructor.
// ccbReader->mOwnerOutletNames = pCCBReader->mOwnerOutletNames;
@ -910,6 +937,16 @@ void CCNodeLoader::onHandlePropTypeSize(CCNode * pNode, CCNode * pParent, const
}
}
void CCNodeLoader::onHandlePropTypeFloatXY(CCNode * pNode, CCNode * pParent, const char* pPropertyName, float * pFloat, CCBReader * pCCBReader) {
if(strcmp(pPropertyName, PROPERTY_SKEW) == 0) {
pNode->setSkewX(pFloat[0]);
pNode->setSkewY(pFloat[1]);
} else {
ASSERT_FAIL_UNEXPECTED_PROPERTY(pPropertyName);
}
}
void CCNodeLoader::onHandlePropTypeScaleLock(CCNode * pNode, CCNode * pParent, const char* pPropertyName, float * pScaleLock, CCBReader * pCCBReader) {
if(strcmp(pPropertyName, PROPERTY_SCALE) == 0) {
pNode->setScaleX(pScaleLock[0]);
@ -925,6 +962,7 @@ void CCNodeLoader::onHandlePropTypeFloat(CCNode * pNode, CCNode * pParent, const
m_pCustomProperties->setObject(CCBValue::create(pFloat), pPropertyName);
}
void CCNodeLoader::onHandlePropTypeDegrees(CCNode * pNode, CCNode * pParent, const char* pPropertyName, float pDegrees, CCBReader * pCCBReader) {
if(strcmp(pPropertyName, PROPERTY_ROTATION) == 0) {
pNode->setRotation(pDegrees);

View File

@ -10,6 +10,7 @@ NS_CC_EXT_BEGIN
#define PROPERTY_POSITION "position"
#define PROPERTY_CONTENTSIZE "contentSize"
#define PROPERTY_SKEW "skew"
#define PROPERTY_ANCHORPOINT "anchorPoint"
#define PROPERTY_SCALE "scale"
#define PROPERTY_ROTATION "rotation"
@ -80,6 +81,7 @@ class CCNodeLoader : public CCObject {
virtual BlockData * parsePropTypeBlock(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
virtual BlockCCControlData * parsePropTypeBlockCCControl(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
virtual CCNode * parsePropTypeCCBFile(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
virtual float * parsePropTypeFloatXY(CCNode * pNode, CCNode * pParent, CCBReader * pCCBReader);
virtual void onHandlePropTypePosition(CCNode * pNode, CCNode * pParent, const char* pPropertyName, CCPoint pPosition, CCBReader * pCCBReader);
@ -93,6 +95,8 @@ class CCNodeLoader : public CCObject {
virtual void onHandlePropTypeInteger(CCNode * pNode, CCNode * pParent, const char* pPropertyName, int pInteger, CCBReader * pCCBReader);
virtual void onHandlePropTypeIntegerLabeled(CCNode * pNode, CCNode * pParent, const char* pPropertyName, int pIntegerLabeled, CCBReader * pCCBReader);
virtual void onHandlePropTypeFloatVar(CCNode * pNode, CCNode * pParent, const char* pPropertyName, float * pFoatVar, CCBReader * pCCBReader);
virtual void onHandlePropTypeFloatXY(CCNode * pNode, CCNode * pParent, const char* pPropertyName, float * pFoatVar, CCBReader * pCCBReader);
virtual void onHandlePropTypeCheck(CCNode * pNode, CCNode * pParent, const char* pPropertyName, bool pCheck, CCBReader * pCCBReader);
virtual void onHandlePropTypeSpriteFrame(CCNode * pNode, CCNode * pParent, const char* pPropertyName, CCSpriteFrame * pCCSpriteFrame, CCBReader * pCCBReader);
virtual void onHandlePropTypeAnimation(CCNode * pNode, CCNode * pParent, const char* pPropertyName, CCAnimation * pCCAnimation, CCBReader * pCCBReader);

View File

@ -3,115 +3,141 @@
//
cc.BuilderReader = cc.BuilderReader || {};
cc.BuilderReader._resourcePath = "";
var _ccbGlobalContext = this;
cc.BuilderReader.setResourcePath = function (rootPath) {
cc.BuilderReader._resourcePath = rootPath;
// Added for CCB HTML5 compatibility
cc.BuilderReader.setResourcePath = function(path){
cc._Reader.setResourcePath(path);
};
cc.BuilderReader.load = function(file, owner, parentSize)
{
// Load the node graph using the correct function
var reader = cc._Reader.create();
reader.setCCBRootPath(cc.BuilderReader._resourcePath);
var reader = cc._Reader.create();
var node;
if (owner && parentSize)
{
node = reader.load(file, owner, parentSize);
}
else if (owner)
{
node = reader.load(file,owner);
}
if (parentSize)
{
node = reader.load(file, null, parentSize);
}
else
{
node = reader.load(file);
}
{
node = reader.load(file);
}
// Assign owner callbacks & member variables
if (owner)
{
// Callbacks
var ownerCallbackNames = reader.getOwnerCallbackNames();
var ownerCallbackNodes = reader.getOwnerCallbackNodes();
for (var i = 0; i < ownerCallbackNames.length; i++)
{
var callbackName = ownerCallbackNames[i];
var callbackNode = ownerCallbackNodes[i];
callbackNode.setCallback(owner[callbackName], owner);
}
// Variables
var ownerOutletNames = reader.getOwnerOutletNames();
var ownerOutletNodes = reader.getOwnerOutletNodes();
for (var i = 0; i < ownerOutletNames.length; i++)
{
var outletName = ownerOutletNames[i];
var outletNode = ownerOutletNodes[i];
owner[outletName] = outletNode;
}
}
{
// Callbacks
var ownerCallbackNames = reader.getOwnerCallbackNames();
var ownerCallbackNodes = reader.getOwnerCallbackNodes();
for (var i = 0; i < ownerCallbackNames.length; i++)
{
var callbackName = ownerCallbackNames[i];
var callbackNode = ownerCallbackNodes[i];
callbackNode.setCallback(owner[callbackName], owner);
}
// Variables
var ownerOutletNames = reader.getOwnerOutletNames();
var ownerOutletNodes = reader.getOwnerOutletNodes();
for (var i = 0; i < ownerOutletNames.length; i++)
{
var outletName = ownerOutletNames[i];
var outletNode = ownerOutletNodes[i];
owner[outletName] = outletNode;
}
}
var nodesWithAnimationManagers = reader.getNodesWithAnimationManagers();
var animationManagersForNodes = reader.getAnimationManagersForNodes();
log(nodesWithAnimationManagers.length);
// Attach animation managers to nodes and assign root node callbacks and member variables
for (var i = 0; i < nodesWithAnimationManagers.length; i++)
{
var innerNode = nodesWithAnimationManagers[i];
var animationManager = animationManagersForNodes[i];
innerNode.animationManager = animationManager;
var documentControllerName = animationManager.getDocumentControllerName();
if (!documentControllerName) continue;
// Create a document controller
var controller = new _ccbGlobalContext[documentControllerName]();
controller.controllerName = documentControllerName;
innerNode.controller = controller;
controller.rootNode = innerNode;
// Callbacks
var documentCallbackNames = animationManager.getDocumentCallbackNames();
var documentCallbackNodes = animationManager.getDocumentCallbackNodes();
for (var j = 0; j < documentCallbackNames.length; j++)
{
var callbackName = documentCallbackNames[j];
var callbackNode = documentCallbackNodes[j];
callbackNode.setCallback(controller[callbackName], controller);
}
// Variables
var documentOutletNames = animationManager.getDocumentOutletNames();
var documentOutletNodes = animationManager.getDocumentOutletNodes();
for (var j = 0; j < documentOutletNames.length; j++)
{
var outletName = documentOutletNames[j];
var outletNode = documentOutletNodes[j];
controller[outletName] = outletNode;
}
if (typeof(controller.onDidLoadFromCCB) == "function")
{
controller.onDidLoadFromCCB();
}
}
{
var innerNode = nodesWithAnimationManagers[i];
var animationManager = animationManagersForNodes[i];
innerNode.animationManager = animationManager;
var documentControllerName = animationManager.getDocumentControllerName();
if (!documentControllerName) continue;
// Create a document controller
var controller = new _ccbGlobalContext[documentControllerName]();
controller.controllerName = documentControllerName;
innerNode.controller = controller;
controller.rootNode = innerNode;
// Callbacks
var documentCallbackNames = animationManager.getDocumentCallbackNames();
var documentCallbackNodes = animationManager.getDocumentCallbackNodes();
for (var j = 0; j < documentCallbackNames.length; j++)
{
var callbackName = documentCallbackNames[j];
var callbackNode = documentCallbackNodes[j];
callbackNode.setCallback(controller[callbackName], controller);
}
// Variables
var documentOutletNames = animationManager.getDocumentOutletNames();
var documentOutletNodes = animationManager.getDocumentOutletNodes();
for (var j = 0; j < documentOutletNames.length; j++)
{
var outletName = documentOutletNames[j];
var outletNode = documentOutletNodes[j];
controller[outletName] = outletNode;
}
if (typeof(controller.onDidLoadFromCCB) == "function")
{
controller.onDidLoadFromCCB();
}
// Setup timeline callbacks
var keyframeCallbacks = animationManager.getKeyframeCallbacks();
for (var j = 0; j < keyframeCallbacks.length; j++)
{
var callbackSplit = keyframeCallbacks[j].split(":");
var callbackType = callbackSplit[0];
var callbackName = callbackSplit[1];
if (callbackType == 1) // Document callback
{
var callfunc = cc.CallFunc.create(controller[callbackName], controller);
animationManager.setCallFuncForJSCallbackNamed(callfunc, keyframeCallbacks[j]);
}
else if (callbackType == 2 && owner) // Owner callback
{
var callfunc = cc.CallFunc.create(owner[callbackName], owner);
animationManager.setCallFuncForJSCallbackNamed(callfunc, keyframeCallbacks[j]);
}
}
// Start animation
var autoPlaySeqId = animationManager.getAutoPlaySequenceId();
if (autoPlaySeqId != -1)
{
animationManager.runAnimationsForSequenceIdTweenDuration(autoPlaySeqId, 0);
}
}
return node;
};
@ -120,6 +146,6 @@ cc.BuilderReader.loadAsScene = function(file, owner, parentSize)
var node = cc.BuilderReader.load(file, owner, parentSize);
var scene = cc.Scene.create();
scene.addChild( node );
return scene;
};

View File

@ -29,6 +29,11 @@ SEL_MenuHandler CCBScriptCallbackProxy::onResolveCCBCCMenuItemSelector(cocos2d::
return menu_selector(CCBScriptCallbackProxy::menuItemCallback);
}
SEL_CallFuncN CCBScriptCallbackProxy::onResolveCCBCCCallFuncSelector(cocos2d::CCObject * pTarget,
const char * pSelectorName) {
}
SEL_CCControlHandler CCBScriptCallbackProxy::onResolveCCBCCControlSelector(CCObject * pTarget,
const char * pSelectorName) {

View File

@ -29,7 +29,9 @@ public:
CCB_STATIC_NEW_AUTORELEASE_OBJECT_WITH_INIT_METHOD(CCBScriptCallbackProxy, create);
virtual cocos2d::SEL_MenuHandler onResolveCCBCCMenuItemSelector(cocos2d::CCObject * pTarget,
const char * pSelectorName);
virtual cocos2d::SEL_CallFuncN onResolveCCBCCCallFuncSelector(cocos2d::CCObject * pTarget,
const char * pSelectorName);
virtual cocos2d::extension::SEL_CCControlHandler onResolveCCBCCControlSelector(cocos2d::CCObject * pTarget,
const char * pSelectorName);
virtual bool onAssignCCBMemberVariable(cocos2d::CCObject * pTarget, const char * pMemberVariableName,

View File

@ -44,7 +44,8 @@ skip = CCBReader::[^CCBReader$ addOwnerCallbackName isJSControlled readByte getC
CCEditBox::[setDelegate ^keyboard.* touchDownAction],
CCTableView::[create (g|s)etDataSource$ (g|s)etDelegate]
rename_functions = CCBReader::[getAnimationManager=getActionManager setAnimationManager=setActionManager]
rename_functions = CCBReader::[getAnimationManager=getActionManager setAnimationManager=setActionManager],
CCBAnimationManager::[setCallFunc=setCallFuncForJSCallbackNamed]
rename_classes = CCBReader::CC_Reader,
CCBAnimationManager::CCAnimationManager