Skip to content

Commit

Permalink
Merge pull request #7123 from andyque/cleanupBinaryLoader
Browse files Browse the repository at this point in the history
cocostudio binary parser
  • Loading branch information
minggo committed Jun 23, 2014
2 parents 9a88a65 + 7eae762 commit a2ebf31
Show file tree
Hide file tree
Showing 71 changed files with 3,692 additions and 1,651 deletions.
12 changes: 12 additions & 0 deletions build/cocos2d_libs.xcodeproj/project.pbxproj
Expand Up @@ -999,6 +999,10 @@
29CB8F4D1929D1BB00C841D6 /* UILayoutManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29CB8F4A1929D1BB00C841D6 /* UILayoutManager.cpp */; };
29CB8F4E1929D1BB00C841D6 /* UILayoutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */; };
29CB8F4F1929D1BB00C841D6 /* UILayoutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */; };
29E99D1E1957BA7000046604 /* CocoLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29E99D1C1957BA7000046604 /* CocoLoader.cpp */; };
29E99D1F1957BA7000046604 /* CocoLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 29E99D1C1957BA7000046604 /* CocoLoader.cpp */; };
29E99D201957BA7000046604 /* CocoLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 29E99D1D1957BA7000046604 /* CocoLoader.h */; };
29E99D211957BA7000046604 /* CocoLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 29E99D1D1957BA7000046604 /* CocoLoader.h */; };
2AC795DB1862870F005EC8E1 /* SkeletonBounds.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D918628689005EC8E1 /* SkeletonBounds.cpp */; };
2AC795DC1862870F005EC8E1 /* Event.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D51862867D005EC8E1 /* Event.cpp */; };
2AC795DD1862870F005EC8E1 /* EventData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2AC795D71862867D005EC8E1 /* EventData.cpp */; };
Expand Down Expand Up @@ -2309,6 +2313,8 @@
299754F3193EC95400A54AC3 /* ObjectFactory.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ObjectFactory.h; path = ../base/ObjectFactory.h; sourceTree = "<group>"; };
29CB8F4A1929D1BB00C841D6 /* UILayoutManager.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UILayoutManager.cpp; sourceTree = "<group>"; };
29CB8F4B1929D1BB00C841D6 /* UILayoutManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UILayoutManager.h; sourceTree = "<group>"; };
29E99D1C1957BA7000046604 /* CocoLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocoLoader.cpp; sourceTree = "<group>"; };
29E99D1D1957BA7000046604 /* CocoLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocoLoader.h; sourceTree = "<group>"; };
2AC795D318628672005EC8E1 /* BoundingBoxAttachment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = BoundingBoxAttachment.cpp; sourceTree = "<group>"; };
2AC795D418628672005EC8E1 /* BoundingBoxAttachment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BoundingBoxAttachment.h; sourceTree = "<group>"; };
2AC795D51862867D005EC8E1 /* Event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Event.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3641,6 +3647,8 @@
1A8C5946180E930E00EF57C3 /* cocostudio */ = {
isa = PBXGroup;
children = (
29E99D1C1957BA7000046604 /* CocoLoader.cpp */,
29E99D1D1957BA7000046604 /* CocoLoader.h */,
0634A4C4194B19E400E608AF /* ActionTimeline */,
50FCEB6818C72017004AD434 /* WidgetReader */,
06CAAAC1186AD63B0012A414 /* TriggerObj.h */,
Expand Down Expand Up @@ -5162,6 +5170,7 @@
1AD71E0D180E26E600808F54 /* CocosBuilder.h in Headers */,
1AD71E97180E26E600808F54 /* Animation.h in Headers */,
1AD71E9B180E26E600808F54 /* AnimationState.h in Headers */,
29E99D201957BA7000046604 /* CocoLoader.h in Headers */,
1A01C69218F57BE800EFE3A6 /* CCDouble.h in Headers */,
50ABBE251925AB6F00A911A9 /* base64.h in Headers */,
50ABBEC91925AB6F00A911A9 /* firePngData.h in Headers */,
Expand Down Expand Up @@ -5469,6 +5478,7 @@
06CAAACE186AD7FA0012A414 /* TriggerBase.h in Headers */,
503DD8EC1926736A00CD74DD /* CCGLView.h in Headers */,
50FCEBC218C72017004AD434 /* TextFieldReader.h in Headers */,
29E99D211957BA7000046604 /* CocoLoader.h in Headers */,
50ABBEBA1925AB6F00A911A9 /* ccUTF8.h in Headers */,
1A570068180BC5A10088DEC7 /* CCActionCamera.h in Headers */,
1A57006C180BC5A10088DEC7 /* CCActionCatmullRom.h in Headers */,
Expand Down Expand Up @@ -6173,6 +6183,7 @@
ED9C6A9418599AD8000A5232 /* CCNodeGrid.cpp in Sources */,
06CAAACB186AD7F20012A414 /* TriggerMng.cpp in Sources */,
46A170E61807CECA005B8026 /* CCPhysicsBody.cpp in Sources */,
29E99D1E1957BA7000046604 /* CocoLoader.cpp in Sources */,
50ABBDA71925AB4100A911A9 /* CCRenderCommand.cpp in Sources */,
50ABBD501925AB0000A911A9 /* Quaternion.cpp in Sources */,
50ABBEBB1925AB6F00A911A9 /* ccUtils.cpp in Sources */,
Expand Down Expand Up @@ -6633,6 +6644,7 @@
50ABBE621925AB6F00A911A9 /* CCEventListenerAcceleration.cpp in Sources */,
B37510811823ACA100B3BA6A /* CCPhysicsJointInfo_chipmunk.cpp in Sources */,
2905FA8D18CF08D100240AA3 /* UIWidget.cpp in Sources */,
29E99D1F1957BA7000046604 /* CocoLoader.cpp in Sources */,
B29594B51926D5EC003EEF37 /* CCMeshCommand.cpp in Sources */,
0634A4D5194B19E400E608AF /* CCActionTimelineCache.cpp in Sources */,
50ABBE7E1925AB6F00A911A9 /* CCEventTouch.cpp in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions build/cocos2d_tests.xcodeproj/project.pbxproj
Expand Up @@ -5476,6 +5476,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
CC_TARGET_OS_IPHONE,
Expand All @@ -5492,6 +5493,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
CC_TARGET_OS_IPHONE,
Expand Down
Expand Up @@ -332,7 +332,7 @@ Frame* ActionTimelineCache::loadTextureFrame(const rapidjson::Value& json)

const char* texture = DICTOOL->getStringValue_json(json, Value);

if(texture != NULL)
if(texture != nullptr)
{
std::string path = texture;

Expand All @@ -354,7 +354,7 @@ Frame* ActionTimelineCache::loadEventFrame(const rapidjson::Value& json)

const char* evnt = DICTOOL->getStringValue_json(json, Value);

if(evnt != NULL)
if(evnt != nullptr)
frame->setEvent(evnt);

return frame;
Expand Down
Expand Up @@ -26,7 +26,7 @@ THE SOFTWARE.
#include "CCActionTimelineCache.h"
#include "CCActionTimeline.h"

#include "../CCSGUIReader.h"
#include "cocostudio/CCSGUIReader.h"

using namespace cocos2d;
using namespace ui;
Expand Down Expand Up @@ -150,7 +150,6 @@ void NodeReader::init()
_funcs.insert(Pair(ClassName_Widget, std::bind(&NodeReader::loadWidget, this, _1)));
_funcs.insert(Pair(ClassName_Label, std::bind(&NodeReader::loadWidget, this, _1)));

_guiReader = new WidgetPropertiesReader0300();
}

Node* NodeReader::createNode(const std::string& filename)
Expand Down Expand Up @@ -445,7 +444,9 @@ Node* NodeReader::loadWidget(const rapidjson::Value& json)

WidgetReaderProtocol* reader = dynamic_cast<WidgetReaderProtocol*>(ObjectFactory::getInstance()->createObject(readerName));

_guiReader->setPropsForAllWidgetFromJsonDictionary(reader, widget, json);
WidgetPropertiesReader0300* guiReader = new WidgetPropertiesReader0300();
guiReader->setPropsForAllWidgetFromJsonDictionary(reader, widget, json);
CC_SAFE_DELETE(guiReader);

int actionTag = DICTOOL->getIntValue_json(json, ACTION_TAG);
widget->setUserObject(ActionTimelineData::create(actionTag));
Expand Down
2 changes: 0 additions & 2 deletions cocos/editor-support/cocostudio/ActionTimeline/CCNodeReader.h
Expand Up @@ -30,7 +30,6 @@ THE SOFTWARE.

namespace cocostudio {

class WidgetPropertiesReader0300;

namespace timeline{

Expand Down Expand Up @@ -78,7 +77,6 @@ class NodeReader

std::unordered_map<std::string, NodeCreateFunc> _funcs;

WidgetPropertiesReader0300* _guiReader;
bool _recordJsonPath;

std::string _jsonPath;
Expand Down
1 change: 1 addition & 0 deletions cocos/editor-support/cocostudio/Android.mk
Expand Up @@ -39,6 +39,7 @@ CCSSceneReader.cpp \
TriggerBase.cpp \
TriggerMng.cpp \
TriggerObj.cpp \
CocoLoader.cpp \
WidgetReader/WidgetReader.cpp \
WidgetReader/ButtonReader/ButtonReader.cpp \
WidgetReader/CheckBoxReader/CheckBoxReader.cpp \
Expand Down
37 changes: 37 additions & 0 deletions cocos/editor-support/cocostudio/CCActionManagerEx.cpp
Expand Up @@ -24,6 +24,7 @@ THE SOFTWARE.

#include "cocostudio/CCActionManagerEx.h"
#include "cocostudio/DictionaryHelper.h"
#include "cocostudio/CocoLoader.h"

using namespace cocos2d;

Expand Down Expand Up @@ -70,6 +71,42 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
}
_actionDic.insert(std::pair<std::string, cocos2d::Vector<ActionObject*>>(fileName, actionList));
}

void ActionManagerEx::initWithBinary(const char* file,
cocos2d::Ref *root,
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode)
{
std::string path = file;
ssize_t pos = path.find_last_of("/");
std::string fileName = path.substr(pos+1,path.length());
CCLOG("filename == %s",fileName.c_str());
cocos2d::Vector<ActionObject*> actionList;

stExpCocoNode *stChildArray = pCocoNode->GetChildArray();
stExpCocoNode *actionNode = nullptr;
for (int i=0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(cocoLoader);
if (key == "actionlist") {
actionNode = &stChildArray[i];
break;
}
}
if (nullptr != actionNode)
{
int actionCount = actionNode->GetChildNum();
for (int i = 0; i < actionCount; ++i) {
ActionObject* action = new ActionObject();
action->autorelease();

action->initWithBinary(cocoLoader, actionNode->GetChildArray(), root);

actionList.pushBack(action);
}
}
_actionDic.insert(std::pair<std::string, cocos2d::Vector<ActionObject*>>(fileName, actionList));

}


ActionObject* ActionManagerEx::getActionByName(const char* jsonName,const char* actionName)
Expand Down
5 changes: 5 additions & 0 deletions cocos/editor-support/cocostudio/CCActionManagerEx.h
Expand Up @@ -29,6 +29,9 @@ THE SOFTWARE.
#include "cocostudio/DictionaryHelper.h"

namespace cocostudio {

class CocoLoader;
struct stExpCocoNode;

class ActionManagerEx:public cocos2d::Ref
{
Expand Down Expand Up @@ -96,6 +99,8 @@ class ActionManagerEx:public cocos2d::Ref

/*init properties with json dictionay*/
void initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root);
void initWithBinary(const char* file, Ref* root, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);

/**
* Release all actions.
*
Expand Down
144 changes: 144 additions & 0 deletions cocos/editor-support/cocostudio/CCActionNode.cpp
Expand Up @@ -27,6 +27,7 @@ THE SOFTWARE.
#include "cocostudio/DictionaryHelper.h"
#include "ui/UIWidget.h"
#include "ui/UIHelper.h"
#include "cocostudio/CocoLoader.h"

using namespace cocos2d;
using namespace ui;
Expand Down Expand Up @@ -167,6 +168,149 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
}
initActionNodeFromRoot(root);
}

int ActionNode::valueToInt(const std::string& value)
{
return atoi(value.c_str());
}
bool ActionNode::valueToBool(const std::string& value)
{
int intValue = valueToInt(value);
if (1 == intValue) {
return true;
}else{
return false;
}
}
float ActionNode::valueToFloat(const std::string& value)
{
return atof(value.c_str());
}

void ActionNode::initWithBinary(CocoLoader *cocoLoader,
stExpCocoNode *cocoNode,
cocos2d::Ref *root)
{

stExpCocoNode *stChildNode = cocoNode;

int actionNodeCount = stChildNode->GetChildNum();
stChildNode = stChildNode[0].GetChildArray();
stExpCocoNode *frameListNode = nullptr;
for (int i = 0; i < actionNodeCount; ++i) {
std::string key = stChildNode[i].GetName(cocoLoader);
std::string value = stChildNode[i].GetValue();
if (key == "ActionTag") {
setActionTag(valueToInt(value));
}else if (key == "actionframelist"){
frameListNode = &stChildNode[i];
}
}

int actionFrameCount = frameListNode->GetChildNum();
stExpCocoNode *stFrameChildNode = frameListNode->GetChildArray();
for (int i=0; i<actionFrameCount; i++) {

int frameIndex;
int frameTweenType;
float positionX;
float positionY;
float scaleX;
float scaleY;
float rotation;
int opacity;
int colorR = -1;
int colorG = -1;
int colorB = -1;
std::vector<float> frameTweenParameter;

int framesCount = stFrameChildNode[i].GetChildNum();
stExpCocoNode *innerFrameNode = stFrameChildNode[i].GetChildArray();
for (int j = 0; j < framesCount; j++) {
std::string key = innerFrameNode[j].GetName(cocoLoader);
std::string value = innerFrameNode[j].GetValue();

if (key == "frameid") {
frameIndex = valueToInt(value);
}else if(key == "tweenType"){
frameTweenType = valueToInt(value);
}else if (key == "tweenParameter"){
// There are no tweenParameter args in the json file
int tweenParameterCount = innerFrameNode[j].GetChildNum();
stExpCocoNode *tweenParameterArray = innerFrameNode[j].GetChildArray();
for (int k = 0; k < tweenParameterCount; ++k) {
std::string t_key = tweenParameterArray[j].GetName(cocoLoader);
std::string t_value = tweenParameterArray[j].GetValue();
frameTweenParameter.push_back(valueToFloat(t_value));
}
}else if (key == "positionx"){
positionX = valueToFloat(value);
}else if (key == "positiony"){
positionY = valueToFloat(value);
ActionMoveFrame* actionFrame = new ActionMoveFrame();
actionFrame->autorelease();
actionFrame->setEasingType(frameTweenType);
actionFrame->setEasingParameter(frameTweenParameter);
actionFrame->setFrameIndex(frameIndex);
actionFrame->setPosition(Vec2(positionX, positionY));
auto cActionArray = _frameArray.at((int)kKeyframeMove);
cActionArray->pushBack(actionFrame);
}else if(key == "scalex"){
scaleX = valueToFloat(value);
}else if(key == "scaley"){
scaleY = valueToFloat(value);
ActionScaleFrame* actionFrame = new ActionScaleFrame();
actionFrame->autorelease();
actionFrame->setEasingType(frameTweenType);
actionFrame->setEasingParameter(frameTweenParameter);
actionFrame->setFrameIndex(frameIndex);
actionFrame->setScaleX(scaleX);
actionFrame->setScaleY(scaleY);
auto cActionArray = _frameArray.at((int)kKeyframeScale);
cActionArray->pushBack(actionFrame);
}else if (key == "rotation"){
rotation = valueToFloat(value);
ActionRotationFrame* actionFrame = new ActionRotationFrame();
actionFrame->autorelease();
actionFrame->setEasingType(frameTweenType);
actionFrame->setEasingParameter(frameTweenParameter);
actionFrame->setFrameIndex(frameIndex);
actionFrame->setRotation(rotation);
auto cActionArray = _frameArray.at((int)kKeyframeRotate);
cActionArray->pushBack(actionFrame);
}else if (key == "opacity"){
opacity = valueToInt(value);
ActionFadeFrame* actionFrame = new ActionFadeFrame();
actionFrame->autorelease();
actionFrame->setEasingType(frameTweenType);
actionFrame->setEasingParameter(frameTweenParameter);
actionFrame->setFrameIndex(frameIndex);
actionFrame->setOpacity(opacity);
auto cActionArray = _frameArray.at((int)kKeyframeFade);
cActionArray->pushBack(actionFrame);
}else if (key == "colorb"){
colorB = valueToInt(value);
}else if(key == "colorg"){
colorG = valueToInt(value);
}else if(key == "colorr"){
colorR = valueToInt(value);

ActionTintFrame* actionFrame = new ActionTintFrame();
actionFrame->autorelease();
actionFrame->setEasingType(frameTweenType);
actionFrame->setEasingParameter(frameTweenParameter);
actionFrame->setFrameIndex(frameIndex);
actionFrame->setColor(Color3B(colorR,colorG,colorB));
auto cActionArray = _frameArray.at((int)kKeyframeTint);
cActionArray->pushBack(actionFrame);
}


}

}
initActionNodeFromRoot(root);
}

void ActionNode::initActionNodeFromRoot(Ref* root)
{
Expand Down

0 comments on commit a2ebf31

Please sign in to comment.