Permalink
Browse files

strength cocosbuilder for lua

  • Loading branch information...
Jennal committed Jan 30, 2015
1 parent fb0fffb commit a25e42267450a1c04223b7ab688d6a7a58bc7d51
@@ -27,7 +27,12 @@ namespace cocosbuilder {
Implementation of CCBFile
*************************************************************************/
CCBFile::CCBFile():_CCBFileNode(nullptr) {}
CCBFile::CCBFile():_CCBFileNode(nullptr), _CCBReader(nullptr) {}
CCBFile::~CCBFile()
{
CC_SAFE_RELEASE(_CCBFileNode);
CC_SAFE_RELEASE(_CCBReader);
}
CCBFile* CCBFile::create()
{
@@ -40,7 +45,7 @@ CCBFile* CCBFile::create()
return ret;
}
Node* CCBFile::getCCBFileNode()
{
return _CCBFileNode;
@@ -53,6 +58,18 @@ void CCBFile::setCCBFileNode(Node *pNode)
CC_SAFE_RETAIN(_CCBFileNode);
}
CCBReader* CCBFile::getCCBReader()
{
return _CCBReader;
}
void CCBFile::setCCBReader(CCBReader *pReader)
{
CC_SAFE_RELEASE(_CCBReader);
_CCBReader = pReader;
CC_SAFE_RETAIN(_CCBReader);
}
/*************************************************************************
Implementation of CCBReader
*************************************************************************/
@@ -119,6 +136,7 @@ CCBReader::~CCBReader()
_ownerOutletNames.clear();
_ownerCallbackNames.clear();
_subCCBFiles.clear();
// Clear string cache.
this->_stringCache.clear();
@@ -608,6 +626,12 @@ Node * CCBReader::readNodeGraph(Node * pParent)
_animationManager->moveAnimationsFromNode(ccbFileNode, embeddedNode);
//Jennal added
CCBReader* reader = ccbFileNode->getCCBReader();
// reader->setMemberName(memberVarAssignmentName);
if (reader != nullptr)
this->addSubCCBFile(reader);
ccbFileNode->setCCBReader(nullptr);
ccbFileNode->setCCBFileNode(nullptr);
node = embeddedNode;
@@ -1067,6 +1091,24 @@ void CCBReader::addOwnerOutletNode(Node *node)
_ownerOutletNodes.pushBack(node);
}
/*
Jennal added
*/
void CCBReader::addSubCCBFile(CCBReader* v)
{
_subCCBFiles.pushBack(v);
}
cocos2d::Vector<CCBReader*>& CCBReader::getSubCCBFiles()
{
return _subCCBFiles;
}
std::string CCBReader::getDocumentControllerName()
{
return _animationManager->getDocumentControllerName();
}
/************************************************************************
Static functions
************************************************************************/
@@ -38,18 +38,25 @@ namespace cocosbuilder {
* @{
*/
class CCBReader;
class CCBFile : public cocos2d::Node
{
private:
cocos2d::Node *_CCBFileNode;
CCBReader *_CCBReader;
public:
CCBFile();
~CCBFile();
static CCBFile* create();
cocos2d::Node* getCCBFileNode();
void setCCBFileNode(Node *pNode); // retain
CCBReader* getCCBReader();
void setCCBReader(CCBReader *pReader); // retain
};
/* Forward declaration. */
@@ -301,6 +308,11 @@ class CCBReader : public cocos2d::Ref
typedef cocos2d::Map<cocos2d::Node*, CCBAnimationManager*> CCBAnimationManagerMap;
typedef std::shared_ptr<CCBAnimationManagerMap> CCBAnimationManagerMapPtr;
/* Jennal added */
std::string getDocumentControllerName();
void addSubCCBFile(CCBReader*);
cocos2d::Vector<CCBReader*>& getSubCCBFiles();
/**
* @js NA
* @lua NA
@@ -395,6 +407,10 @@ class CCBReader : public cocos2d::Ref
std::vector<std::string> _ownerCallbackNames;
cocos2d::Vector<cocos2d::Node*> _ownerCallbackNodes;
cocos2d::ValueVector _ownerOwnerCallbackControlEvents;
/* Jennal added */
cocos2d::Vector<CCBReader*> _subCCBFiles;
std::string _CCBRootPath;
bool _jsControlled;
@@ -960,37 +960,48 @@ Node * NodeLoader::parsePropTypeCCBFile(Node * pNode, Node * pParent, CCBReader
reader->getAnimationManager()->runAnimationsForSequenceIdTweenDuration(reader->getAnimationManager()->getAutoPlaySequenceId(), 0);
}
if (reader->isJSControlled() && pCCBReader->isJSControlled() && nullptr == reader->_owner)
if (reader->isJSControlled() && pCCBReader->isJSControlled())
{
//set variables and callback to owner
//set callback
auto ownerCallbackNames = reader->getOwnerCallbackNames();
auto& ownerCallbackNodes = reader->getOwnerCallbackNodes();
if (!ownerCallbackNames.empty() && !ownerCallbackNodes.empty())
//Jennal Modified: need to check this??
if (reader->_owner == nullptr)
{
CCASSERT(ownerCallbackNames.size() == ownerCallbackNodes.size(), "");
ssize_t nCount = ownerCallbackNames.size();
for (ssize_t i = 0 ; i < nCount; i++)
//set variables and callback to owner
//set callback
auto ownerCallbackNames = reader->getOwnerCallbackNames();
auto& ownerCallbackNodes = reader->getOwnerCallbackNodes();
if (!ownerCallbackNames.empty() && !ownerCallbackNodes.empty())
{
pCCBReader->addOwnerCallbackName(ownerCallbackNames[i].asString());
pCCBReader->addOwnerCallbackNode(ownerCallbackNodes.at(i));
CCASSERT(ownerCallbackNames.size() == ownerCallbackNodes.size(), "");
ssize_t nCount = ownerCallbackNames.size();
for (ssize_t i = 0 ; i < nCount; i++)
{
pCCBReader->addOwnerCallbackName(ownerCallbackNames[i].asString());
pCCBReader->addOwnerCallbackNode(ownerCallbackNodes.at(i));
}
}
}
//set variables
auto ownerOutletNames = reader->getOwnerOutletNames();
auto ownerOutletNodes = reader->getOwnerOutletNodes();
if (!ownerOutletNames.empty() && !ownerOutletNodes.empty())
{
CCASSERT(ownerOutletNames.size() == ownerOutletNodes.size(), "");
ssize_t nCount = ownerOutletNames.size();
for (ssize_t i = 0 ; i < nCount; i++)
//set variables
auto ownerOutletNames = reader->getOwnerOutletNames();
auto ownerOutletNodes = reader->getOwnerOutletNodes();
if (!ownerOutletNames.empty() && !ownerOutletNodes.empty())
{
pCCBReader->addOwnerOutletName(ownerOutletNames.at(i).asString());
pCCBReader->addOwnerOutletNode(ownerOutletNodes.at(i));
CCASSERT(ownerOutletNames.size() == ownerOutletNodes.size(), "");
ssize_t nCount = ownerOutletNames.size();
for (ssize_t i = 0 ; i < nCount; i++)
{
pCCBReader->addOwnerOutletName(ownerOutletNames.at(i).asString());
pCCBReader->addOwnerOutletNode(ownerOutletNodes.at(i));
}
}
}
//Jennal added
CCBFile* ccbFile = dynamic_cast<CCBFile*>(pNode);
if (ccbFile != nullptr) ccbFile->setCCBReader(reader);
// auto subFiles = reader->getSubCCBFiles();
// pCCBReader->addSubCCBFiles(subFiles);
}
return ccbFileNode;
}
@@ -795,14 +795,122 @@ static int tolua_cocos2d_CCBReader_load(lua_State* tolua_S)
#endif
}
static int tolua_cocos2d_CCBReader_getSubReaders(lua_State* tolua_S)
{
if (nullptr == tolua_S)
return 0;
int argc = 0;
CCBReader* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"cc.CCBReader",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast<CCBReader*>(tolua_tousertype(tolua_S,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self) {
tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_CCBReader_getSubReaders'\n", NULL);
return 0;
}
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 0)
{
auto tolua_ret = self->getSubCCBFiles();
if (tolua_ret.empty()) {
return 0;
}
int i = 1;
lua_newtable(tolua_S);
for(auto item : tolua_ret)
{
auto reader = item;
int ID = (reader) ? (int)reader->_ID : -1;
int* luaID = (reader) ? &reader->_luaID : NULL;
toluafix_pushusertype_ccobject(tolua_S, ID, luaID, (void*)reader,"cc.CCBReader");
lua_rawseti(tolua_S, -2, i);
++i;
}
return 1;
}
CCLOG("'getSubReaders' function of CCBReader has wrong number of arguments: %d, was expecting %d\n", argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'getSubReaders'.",&tolua_err);
return 0;
#endif
}
static int tolua_cocos2d_CCBReader_getDocumentControllerName(lua_State* tolua_S)
{
if (nullptr == tolua_S)
return 0;
int argc = 0;
CCBReader* self = nullptr;
#if COCOS2D_DEBUG >= 1
tolua_Error tolua_err;
if (!tolua_isusertype(tolua_S,1,"cc.CCBReader",0,&tolua_err)) goto tolua_lerror;
#endif
self = static_cast<CCBReader*>(tolua_tousertype(tolua_S,1,0));
#if COCOS2D_DEBUG >= 1
if (nullptr == self) {
tolua_error(tolua_S,"invalid 'self' in function 'tolua_cocos2d_CCBReader_getSubReaders'\n", NULL);
return 0;
}
#endif
argc = lua_gettop(tolua_S) - 1;
if (argc == 0)
{
auto tolua_ret = self->getDocumentControllerName();
if (tolua_ret.empty()) {
return 0;
}
lua_pushstring(tolua_S, tolua_ret.c_str());
return 1;
}
CCLOG("'getDocumentControllerName' function of CCBReader has wrong number of arguments: %d, was expecting %d\n", argc, 0);
return 0;
#if COCOS2D_DEBUG >= 1
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'getDocumentControllerName'.",&tolua_err);
return 0;
#endif
}
static void extendCCBReader(lua_State* tolua_S)
{
lua_pushstring(tolua_S, "cc.CCBReader");
lua_rawget(tolua_S, LUA_REGISTRYINDEX);
if (lua_istable(tolua_S,-1))
{
lua_pushstring(tolua_S,"load");
lua_pushcfunction(tolua_S,tolua_cocos2d_CCBReader_load );
lua_pushcfunction(tolua_S,tolua_cocos2d_CCBReader_load);
lua_rawset(tolua_S,-3);
lua_pushstring(tolua_S,"getSubReaders");
lua_pushcfunction(tolua_S,tolua_cocos2d_CCBReader_getSubReaders);
lua_rawset(tolua_S,-3);
lua_pushstring(tolua_S,"getDocumentControllerName");
lua_pushcfunction(tolua_S,tolua_cocos2d_CCBReader_getDocumentControllerName);
lua_rawset(tolua_S,-3);
}
lua_pop(tolua_S, 1);

0 comments on commit a25e422

Please sign in to comment.