2013-05-10 15:07:05 +08:00
|
|
|
#include "DataVisitorTest.h"
|
|
|
|
#include "../testResource.h"
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string PrettyPrinterDemo::title() const
|
2013-05-10 15:07:05 +08:00
|
|
|
{
|
|
|
|
return "PrettyPrinter Test";
|
|
|
|
}
|
|
|
|
|
2013-12-19 05:52:10 +08:00
|
|
|
std::string PrettyPrinterDemo::subtitle() const
|
2013-05-10 15:07:05 +08:00
|
|
|
{
|
|
|
|
return "Please see log!";
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrettyPrinterDemo::addSprite()
|
|
|
|
{
|
|
|
|
// create sprites
|
|
|
|
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s1 = Sprite::create("Images/grossini.png");
|
|
|
|
auto s2 = Sprite::create("Images/grossini_dance_01.png");
|
|
|
|
auto s3 = Sprite::create("Images/grossini_dance_02.png");
|
|
|
|
auto s4 = Sprite::create("Images/grossini_dance_03.png");
|
|
|
|
auto s5 = Sprite::create("Images/grossini_dance_04.png");
|
2013-05-10 15:07:05 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
s1->setPosition(Vec2(50, 50));
|
|
|
|
s2->setPosition(Vec2(60, 50));
|
|
|
|
s3->setPosition(Vec2(70, 50));
|
|
|
|
s4->setPosition(Vec2(80, 50));
|
|
|
|
s5->setPosition(Vec2(90, 50));
|
2013-05-10 15:07:05 +08:00
|
|
|
|
|
|
|
this->addChild(s1);
|
|
|
|
this->addChild(s2);
|
|
|
|
this->addChild(s3);
|
|
|
|
this->addChild(s4);
|
|
|
|
this->addChild(s5);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PrettyPrinterDemo::onEnter()
|
|
|
|
{
|
2013-06-20 14:17:10 +08:00
|
|
|
Layer::onEnter();
|
2013-08-16 16:05:27 +08:00
|
|
|
auto s = Director::getInstance()->getWinSize();
|
2013-05-10 15:07:05 +08:00
|
|
|
|
2014-04-09 23:31:05 +08:00
|
|
|
auto label = Label::createWithTTF(title().c_str(), "fonts/arial.ttf", 28);
|
2014-05-15 01:07:09 +08:00
|
|
|
label->setPosition( Vec2(s.width/2, s.height * 4/5) );
|
2013-05-10 15:07:05 +08:00
|
|
|
this->addChild(label, 1);
|
|
|
|
|
|
|
|
std::string strSubtitle = subtitle();
|
|
|
|
if(strSubtitle.empty() == false)
|
|
|
|
{
|
2014-04-09 23:31:05 +08:00
|
|
|
auto subLabel = Label::createWithTTF(strSubtitle.c_str(), "fonts/Thonburi.ttf", 16);
|
2014-05-15 01:07:09 +08:00
|
|
|
subLabel->setPosition( Vec2(s.width/2, s.height * 3/5) );
|
2013-05-10 15:07:05 +08:00
|
|
|
this->addChild(subLabel, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test code
|
2013-06-20 14:17:10 +08:00
|
|
|
PrettyPrinter vistor;
|
2013-05-10 15:07:05 +08:00
|
|
|
|
|
|
|
// print dictionary
|
2013-08-16 16:05:27 +08:00
|
|
|
auto dict = Dictionary::createWithContentsOfFile("animations/animations.plist");
|
2013-07-24 06:20:22 +08:00
|
|
|
dict->acceptVisitor(vistor);
|
|
|
|
log("%s", vistor.getResult().c_str());
|
|
|
|
log("-------------------------------");
|
2013-05-10 15:07:05 +08:00
|
|
|
|
2014-03-20 16:24:55 +08:00
|
|
|
__Set myset;
|
2013-05-10 15:07:05 +08:00
|
|
|
for (int i = 0; i < 30; ++i) {
|
2013-06-20 14:17:10 +08:00
|
|
|
myset.addObject(String::createWithFormat("str: %d", i));
|
2013-05-10 15:07:05 +08:00
|
|
|
}
|
|
|
|
vistor.clear();
|
|
|
|
myset.acceptVisitor(vistor);
|
2013-07-24 06:20:22 +08:00
|
|
|
log("%s", vistor.getResult().c_str());
|
|
|
|
log("-------------------------------");
|
2013-05-10 15:07:05 +08:00
|
|
|
|
|
|
|
vistor.clear();
|
|
|
|
addSprite();
|
2013-11-07 21:48:39 +08:00
|
|
|
// dict = Director::getInstance()->getTextureCache()->snapshotTextures();
|
2013-09-07 13:55:36 +08:00
|
|
|
// dict->acceptVisitor(vistor);
|
|
|
|
// log("%s", vistor.getResult().c_str());
|
2013-05-10 15:07:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void DataVisitorTestScene::runThisTest()
|
|
|
|
{
|
2013-08-16 16:05:27 +08:00
|
|
|
auto layer = new PrettyPrinterDemo();
|
2013-05-10 15:07:05 +08:00
|
|
|
layer->autorelease();
|
|
|
|
addChild(layer);
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Director::getInstance()->replaceScene(this);
|
2013-05-10 15:07:05 +08:00
|
|
|
}
|