1. add classname = "" log.

This commit is contained in:
zhangcheng 2014-06-25 14:32:38 +08:00
parent 644b61e261
commit bdf7be6fa0
3 changed files with 208 additions and 89 deletions

View File

@ -277,6 +277,7 @@ Node* SceneReader::createObject(const rapidjson::Value &dict, cocos2d::Node* par
}
const char *comName = DICTOOL->getStringValue_json(subDict, "classname");
Component *com = this->createComponent(comName);
CCLOG("classname = %s", comName);
SerData *data = new SerData();
if (com != nullptr)
{

View File

@ -106,7 +106,7 @@ void SceneEditorTestScene::MainMenuCallback(Ref *pSender)
removeAllChildren();
}
const char* SceneEditorTestLayer::m_loadtypeStr[2] = {"change to load \nwith binary file","change to load \nwith json file"};
void SceneEditorTestLayer::onEnter()
{
CCLayer::onEnter();
@ -127,6 +127,13 @@ void SceneEditorTestLayer::onEnter()
addChild(l, 1, 10001);
l->setPosition(Vec2(VisibleRect::center().x, VisibleRect::top().y - 60) );
}
m_isCsbLoad = false;
m_loadtypelb = cocos2d::Label::createWithSystemFont(m_loadtypeStr[0], "Arial", 12);
// #endif
MenuItemLabel* itemlb = CCMenuItemLabel::create(m_loadtypelb, CC_CALLBACK_1(SceneEditorTestLayer::changeLoadTypeCallback, this));
Menu* loadtypemenu = CCMenu::create(itemlb, NULL);
loadtypemenu->setPosition(Point(VisibleRect::rightTop().x -50,VisibleRect::rightTop().y -20));
addChild(loadtypemenu,100);
// add menu
backItem = MenuItemImage::create(s_pathB1, s_pathB2, CC_CALLBACK_1(SceneEditorTestLayer::backCallback, this) );
@ -199,6 +206,36 @@ void SceneEditorTestLayer::draw(Renderer *renderer, const Mat4 &transform, uint3
Layer::draw(renderer, transform, flags);
}
void SceneEditorTestLayer::changeLoadTypeCallback(cocos2d::Ref *pSender)
{
m_isCsbLoad = !m_isCsbLoad;
m_loadtypelb->setString(m_loadtypeStr[(int)m_isCsbLoad]);
loadFileChangeHelper(m_filePathName);
if(m_rootNode != NULL)
{
this->removeChild(m_rootNode);
m_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(m_filePathName.c_str());
if (m_rootNode == NULL)
{
return ;
}
defaultPlay();
this->addChild(m_rootNode);
}
}
void SceneEditorTestLayer::loadFileChangeHelper(std::string& filePathName)
{
std::string::size_type n = filePathName.find_last_of(".");
if(n == std::string::npos)
return;
filePathName = filePathName.substr(0,n);
if(m_isCsbLoad)
filePathName.append(".csb");
else
filePathName.append(".json");
}
LoadSceneEdtiorFileTest::LoadSceneEdtiorFileTest()
{
@ -238,12 +275,19 @@ void LoadSceneEdtiorFileTest::onExit()
cocos2d::Node* LoadSceneEdtiorFileTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/LoadSceneEdtiorFileTest/FishJoy2.csb");
if (node == nullptr)
m_filePathName = "scenetest/LoadSceneEdtiorFileTest/FishJoy2.json"; //default is json
m_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(m_filePathName.c_str());
if (m_rootNode == NULL)
{
return nullptr;
return NULL;
}
return node;
defaultPlay();
return m_rootNode;
}
void LoadSceneEdtiorFileTest::defaultPlay()
{
}
SpriteComponentTest::SpriteComponentTest()
@ -283,22 +327,29 @@ void SpriteComponentTest::onExit()
cocos2d::Node* SpriteComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/SpriteComponentTest/SpriteComponentTest.csb");
if (node == nullptr)
m_filePathName = "scenetest/SpriteComponentTest/SpriteComponentTest.json";
m_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(m_filePathName.c_str());
if (m_rootNode == NULL)
{
return nullptr;
return NULL;
}
defaultPlay();
return m_rootNode;
}
void SpriteComponentTest::defaultPlay()
{
ActionInterval* action1 = CCBlink::create(2, 10);
ActionInterval* action2 = CCBlink::create(2, 5);
ComRender *pSister1 = static_cast<ComRender*>(node->getChildByTag(10003)->getComponent("CCSprite"));
ComRender *pSister1 = static_cast<ComRender*>(m_rootNode->getChildByTag(10003)->getComponent("CCSprite"));
pSister1->getNode()->runAction(action1);
ComRender *pSister2 = static_cast<ComRender*>(node->getChildByTag(10004)->getComponent("CCSprite"));
ComRender *pSister2 = static_cast<ComRender*>(m_rootNode->getChildByTag(10004)->getComponent("CCSprite"));
pSister2->getNode()->runAction(action2);
return node;
}
ArmatureComponentTest::ArmatureComponentTest()
@ -338,22 +389,27 @@ void ArmatureComponentTest::onExit()
cocos2d::Node* ArmatureComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/ArmatureComponentTest/ArmatureComponentTest.csb");
if (node == nullptr)
m_filePathName = "scenetest/ArmatureComponentTest/ArmatureComponentTest.json";
m_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(m_filePathName.c_str());
if (m_rootNode == NULL)
{
return nullptr;
return NULL;
}
ComRender *pBlowFish = static_cast<ComRender*>(node->getChildByTag(10007)->getComponent("CCArmature"));
pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0)));
defaultPlay();
return m_rootNode;
}
ComRender *pButterflyfish = static_cast<ComRender*>(node->getChildByTag(10008)->getComponent("CCArmature"));
pButterflyfish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0)));
void ArmatureComponentTest::defaultPlay()
{
ComRender *pBlowFish = static_cast<ComRender*>(m_rootNode->getChildByTag(10007)->getComponent("CCArmature"));
pBlowFish->getNode()->runAction(MoveBy::create(10.0f, Point(-1000.0f, 0)));
ComRender *pButterflyfish = static_cast<ComRender*>(m_rootNode->getChildByTag(10008)->getComponent("CCArmature"));
pButterflyfish->getNode()->runAction(MoveBy::create(10.0f, Point(-1000.0f, 0)));
return node;
}
UIComponentTest::UIComponentTest()
: _node(nullptr)
{
}
@ -389,20 +445,15 @@ void UIComponentTest::onExit()
cocos2d::Node* UIComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/UIComponentTest/UIComponentTest.csb");
if (node == nullptr)
m_filePathName = "scenetest/UIComponentTest/UIComponentTest.json";
m_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(m_filePathName.c_str());
if (m_rootNode == NULL)
{
return nullptr;
return NULL;
}
_node = node;
ComRender *render = static_cast<ComRender*>(_node->getChildByTag(10025)->getComponent("GUIComponent"));
Widget* widget = static_cast<cocos2d::ui::Widget*>(render->getNode());
Button* button = static_cast<Button*>(widget->getChildByName("Button_156"));
// button->addTouchEventListener(this, toucheventselector(UIComponentTest::touchEvent));
button->addTouchEventListener(CC_CALLBACK_2(UIComponentTest::touchEvent, this));
return node;
defaultPlay();
return m_rootNode;
}
void UIComponentTest::touchEvent(Ref *pSender, ui::Widget::TouchEventType type)
@ -411,10 +462,10 @@ void UIComponentTest::touchEvent(Ref *pSender, ui::Widget::TouchEventType type)
{
case ui::Widget::TouchEventType::BEGAN:
{
ComRender *pBlowFish = static_cast<ComRender*>(_node->getChildByTag(10010)->getComponent("CCArmature"));
ComRender *pBlowFish = static_cast<ComRender*>(m_rootNode->getChildByTag(10010)->getComponent("CCArmature"));
pBlowFish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0)));
ComRender *pButterflyfish = static_cast<ComRender*>(_node->getChildByTag(10011)->getComponent("CCArmature"));
ComRender *pButterflyfish = static_cast<ComRender*>(m_rootNode->getChildByTag(10011)->getComponent("CCArmature"));
pButterflyfish->getNode()->runAction(CCMoveBy::create(10.0f, Vec2(-1000.0f, 0)));
}
break;
@ -423,6 +474,15 @@ void UIComponentTest::touchEvent(Ref *pSender, ui::Widget::TouchEventType type)
}
}
void UIComponentTest::defaultPlay()
{
ComRender *render = static_cast<ComRender*>(m_rootNode->getChildByTag(10025)->getComponent("GUIComponent"));
Widget* widget = static_cast<cocos2d::ui::Widget*>(render->getNode());
Button* button = static_cast<Button*>(widget->getChildByName("Button_156"));
button->addTouchEventListener(CC_CALLBACK_2(UIComponentTest::touchEvent, this));
}
TmxMapComponentTest::TmxMapComponentTest()
{
@ -460,24 +520,30 @@ void TmxMapComponentTest::onExit()
cocos2d::Node* TmxMapComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/TmxMapComponentTest/TmxMapComponentTest.csb");
if (node == nullptr)
m_filePathName = "scenetest/TmxMapComponentTest/TmxMapComponentTest.json";
m_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(m_filePathName.c_str());
if (m_rootNode == NULL)
{
return nullptr;
return NULL;
}
ComRender *tmxMap = static_cast<ComRender*>(node->getChildByTag(10015)->getComponent("CCTMXTiledMap"));
ActionInterval *actionTo = SkewTo::create(2, 0.f, 2.f);
ActionInterval *rotateTo = RotateTo::create(2, 61.0f);
ActionInterval *actionScaleTo = ScaleTo::create(2, -0.44f, 0.47f);
defaultPlay();
return m_rootNode;
}
ActionInterval *actionScaleToBack = ScaleTo::create(2, 1.0f, 1.0f);
ActionInterval *rotateToBack = RotateTo::create(2, 0);
ActionInterval *actionToBack = SkewTo::create(2, 0, 0);
void TmxMapComponentTest::defaultPlay()
{
ComRender *tmxMap = static_cast<ComRender*>(m_rootNode->getChildByTag(10015)->getComponent("CCTMXTiledMap"));
ActionInterval *actionTo = CCSkewTo::create(2, 0.f, 2.f);
ActionInterval *rotateTo = CCRotateTo::create(2, 61.0f);
ActionInterval *actionScaleTo = CCScaleTo::create(2, -0.44f, 0.47f);
tmxMap->getNode()->runAction(Sequence::create(actionTo, actionToBack, nullptr));
tmxMap->getNode()->runAction(Sequence::create(rotateTo, rotateToBack, nullptr));
tmxMap->getNode()->runAction(Sequence::create(actionScaleTo, actionScaleToBack, nullptr));
return node;
ActionInterval *actionScaleToBack = CCScaleTo::create(2, 1.0f, 1.0f);
ActionInterval *rotateToBack = CCRotateTo::create(2, 0);
ActionInterval *actionToBack = CCSkewTo::create(2, 0, 0);
tmxMap->getNode()->runAction(CCSequence::create(actionTo, actionToBack, NULL));
tmxMap->getNode()->runAction(CCSequence::create(rotateTo, rotateToBack, NULL));
tmxMap->getNode()->runAction(CCSequence::create(actionScaleTo, actionScaleToBack, NULL));
}
ParticleComponentTest::ParticleComponentTest()
@ -516,22 +582,26 @@ void ParticleComponentTest::onExit()
cocos2d::Node* ParticleComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/ParticleComponentTest/ParticleComponentTest.csb");
if (node == nullptr)
m_filePathName = "scenetest/ParticleComponentTest/ParticleComponentTest.json";
m_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(m_filePathName.c_str());
if (m_rootNode == NULL)
{
return nullptr;
return NULL;
}
defaultPlay();
return m_rootNode;
}
ComRender* Particle = static_cast<ComRender*>(node->getChildByTag(10020)->getComponent("CCParticleSystemQuad"));
ActionInterval* jump = JumpBy::create(5, Vec2(-500,0), 50, 4);
FiniteTimeAction* action = Sequence::create( jump, jump->reverse(), nullptr);
void ParticleComponentTest::defaultPlay()
{
ComRender* Particle = static_cast<ComRender*>(m_rootNode->getChildByTag(10020)->getComponent("CCParticleSystemQuad"));
ActionInterval* jump = CCJumpBy::create(5, Point(-500,0), 50, 4);
FiniteTimeAction* action = CCSequence::create( jump, jump->reverse(), NULL);
Particle->getNode()->runAction(action);
return node;
}
EffectComponentTest::EffectComponentTest()
: _node(nullptr)
{
}
@ -567,16 +637,14 @@ void EffectComponentTest::onExit()
cocos2d::Node* EffectComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/EffectComponentTest/EffectComponentTest.csb");
if (node == nullptr)
m_filePathName = "scenetest/EffectComponentTest/EffectComponentTest.json";
m_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(m_filePathName.c_str());
if (m_rootNode == NULL)
{
return nullptr;
return NULL;
}
_node = node;
ComRender *render = static_cast<ComRender*>(_node->getChildByTag(10015)->getComponent("CCArmature"));
Armature *pAr = static_cast<Armature*>(render->getNode());
pAr->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_0(EffectComponentTest::animationEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
return node;
defaultPlay();
return m_rootNode;
}
void EffectComponentTest::animationEvent(Armature *armature, MovementEventType movementType, const std::string& movementID)
@ -587,12 +655,19 @@ void EffectComponentTest::animationEvent(Armature *armature, MovementEventType m
{
if (id.compare("Fire") == 0)
{
ComAudio *pAudio = static_cast<ComAudio*>(_node->getChildByTag(10015)->getComponent("CCComAudio"));
ComAudio *pAudio = static_cast<ComAudio*>(m_rootNode->getChildByTag(10015)->getComponent("CCComAudio"));
pAudio->playEffect();
}
}
}
void EffectComponentTest::defaultPlay()
{
ComRender *render = static_cast<ComRender*>(m_rootNode->getChildByTag(10015)->getComponent("CCArmature"));
Armature *pAr = static_cast<Armature*>(render->getNode());
pAr->getAnimation()->setMovementEventCallFunc(CC_CALLBACK_0(EffectComponentTest::animationEvent, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));
}
BackgroundComponentTest::BackgroundComponentTest()
{
@ -629,20 +704,24 @@ void BackgroundComponentTest::onExit()
cocos2d::Node* BackgroundComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/BackgroundComponentTest/BackgroundComponentTest.csb");
if (node == nullptr)
m_filePathName = "scenetest/BackgroundComponentTest/BackgroundComponentTest.json";
m_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(m_filePathName.c_str());
if (m_rootNode == NULL)
{
return nullptr;
return NULL;
}
defaultPlay();
return m_rootNode;
}
ComAudio *Audio = static_cast<ComAudio*>(node->getComponent("CCBackgroundAudio"));
void BackgroundComponentTest::defaultPlay()
{
ComAudio *Audio = static_cast<ComAudio*>(m_rootNode->getComponent("CCBackgroundAudio"));
Audio->playBackgroundMusic();
return node;
}
AttributeComponentTest::AttributeComponentTest()
: _node(nullptr)
{
}
@ -663,7 +742,7 @@ void AttributeComponentTest::onEnter()
{
Node *root = createGameScene();
CC_BREAK_IF(!root);
initData();
defaultPlay();
this->addChild(root, 0, 1);
} while (0);
}
@ -682,8 +761,8 @@ bool AttributeComponentTest::initData()
bool bRet = false;
rapidjson::Document doc;
do {
CC_BREAK_IF(_node == nullptr);
ComAttribute *attribute = static_cast<ComAttribute*>(_node->getChildByTag(10015)->getComponent("CCComAttribute"));
CC_BREAK_IF(m_rootNode == nullptr);
ComAttribute *attribute = static_cast<ComAttribute*>(m_rootNode->getChildByTag(10015)->getComponent("CCComAttribute"));
CC_BREAK_IF(attribute == nullptr);
log("Name: %s, HP: %f, MP: %f", attribute->getString("name").c_str(), attribute->getFloat("maxHP"), attribute->getFloat("maxMP"));
@ -694,13 +773,18 @@ bool AttributeComponentTest::initData()
cocos2d::Node* AttributeComponentTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/AttributeComponentTest/AttributeComponentTest.csb");
if (node == nullptr)
m_filePathName = "scenetest/AttributeComponentTest/AttributeComponentTest.json";
m_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(m_filePathName.c_str());
if (m_rootNode == NULL)
{
return nullptr;
return NULL;
}
_node = node;
return node;
return m_rootNode;
}
void AttributeComponentTest::defaultPlay()
{
initData();
}
TriggerTest::TriggerTest()
@ -783,12 +867,16 @@ void TriggerTest::gameLogic(float dt)
cocos2d::Node* TriggerTest::createGameScene()
{
Node *node = SceneReader::getInstance()->createNodeWithSceneFile("scenetest/TriggerTest/TriggerTest.csb");
if (node == nullptr)
m_filePathName = "scenetest/TriggerTest/TriggerTest.json";
m_rootNode = SceneReader::getInstance()->createNodeWithSceneFile(m_filePathName.c_str());
if (m_rootNode == NULL)
{
return nullptr;
return NULL;
}
_node = node;
return node;
defaultPlay();
return m_rootNode;
}
void TriggerTest::defaultPlay()
{
}

View File

@ -49,6 +49,20 @@ protected:
MenuItemImage *restartItem;
MenuItemImage *nextItem;
MenuItemImage *backItem;
protected:
virtual void changeLoadTypeCallback(cocos2d::Ref *pSender);
virtual void defaultPlay() = 0; // must to be overrided
void loadFileChangeHelper(std::string& filePathName ); // switch json& csb
private:
bool m_isCsbLoad; // default is false
cocos2d::Label* m_loadtypelb;
static const char* m_loadtypeStr[2];
protected:
cocos2d::Node* m_rootNode;
std::string m_filePathName;
};
class LoadSceneEdtiorFileTest : public SceneEditorTestLayer
@ -61,6 +75,8 @@ public:
virtual void onEnter() override;
virtual void onExit() override;
cocos2d::Node* createGameScene();
private:
void defaultPlay();
};
@ -75,6 +91,8 @@ public:
virtual void onExit() override;
cocos2d::Node* createGameScene();
private:
void defaultPlay();
};
class ArmatureComponentTest : public SceneEditorTestLayer
@ -88,6 +106,8 @@ public:
virtual void onExit() override;
cocos2d::Node* createGameScene();
private:
void defaultPlay();
};
class UIComponentTest : public SceneEditorTestLayer
@ -102,7 +122,7 @@ public:
cocos2d::Node* createGameScene();
void touchEvent(cocos2d::Ref *pSender, ui::Widget::TouchEventType type);
private:
cocos2d::Node* _node;
void defaultPlay();
};
class TmxMapComponentTest : public SceneEditorTestLayer
@ -115,6 +135,8 @@ public:
virtual void onEnter() override;
virtual void onExit() override;
cocos2d::Node* createGameScene();
private:
void defaultPlay();
};
@ -128,6 +150,8 @@ public:
virtual void onEnter() override;
virtual void onExit() override;
cocos2d::Node* createGameScene();
protected:
void defaultPlay();
};
class EffectComponentTest : public SceneEditorTestLayer
@ -142,7 +166,8 @@ public:
cocos2d::Node* createGameScene();
void animationEvent(cocostudio::Armature *armature, cocostudio::MovementEventType movementType, const std::string& movementID);
private:
cocos2d::Node* _node;
void defaultPlay();
};
class BackgroundComponentTest : public SceneEditorTestLayer
@ -155,6 +180,8 @@ public:
virtual void onEnter() override;
virtual void onExit() override;
cocos2d::Node* createGameScene();
private:
void defaultPlay();
};
class AttributeComponentTest : public SceneEditorTestLayer
@ -168,8 +195,9 @@ public:
virtual void onExit() override;
bool initData();
cocos2d::Node* createGameScene();
private:
cocos2d::Node* _node;
void defaultPlay();
};
class TriggerTest : public SceneEditorTestLayer
@ -197,6 +225,8 @@ public:
private:
cocos2d::Node *_node;
cocos2d::EventListener* _touchListener;
private:
void defaultPlay();
};
#endif // __HELLOWORLD_SCENE_H__