Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cocostudio binary parser #7123

Merged
merged 41 commits into from Jun 23, 2014
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b570487
add cocostudio binary file parser
zilongshanren Jun 5, 2014
8690122
add version 300 parsing code in widget reader
zilongshanren Jun 5, 2014
3dc6e86
add binary file parsing into ui tests
zilongshanren Jun 5, 2014
c96a608
improve parsing code
zilongshanren Jun 5, 2014
6bbf5a1
tests
zilongshanren Jun 6, 2014
48f7743
Merge branch 'v3' into cleanupBinaryLoader
zilongshanren Jun 10, 2014
b895018
update parser
zilongshanren Jun 11, 2014
7a8f27e
remove unused parser code
zilongshanren Jun 11, 2014
2f6f1b7
improve binary format
zilongshanren Jun 11, 2014
f502634
improve parser
zilongshanren Jun 11, 2014
5515c43
improve lasers
zilongshanren Jun 11, 2014
1d01fe8
refactor
zilongshanren Jun 15, 2014
9ab4574
Merge branch 'v3' into cleanupBinaryLoader
zilongshanren Jun 17, 2014
ca24ad6
Merge branch 'v3' into cleanupBinaryLoader
zilongshanren Jun 18, 2014
2cef0cb
update ccs-res
zilongshanren Jun 18, 2014
95f1bd7
update loader
zilongshanren Jun 18, 2014
615995a
add base property parser for WidgetReader
zilongshanren Jun 18, 2014
12bb756
fix cannot compile in windows
geron-cn Jun 18, 2014
63475a6
refactor Loader
zilongshanren Jun 18, 2014
0b677a8
Merge pull request #8 from geron-cn/guagnhuiv3
zilongshanren Jun 18, 2014
f614e9a
fix tests
zilongshanren Jun 18, 2014
aa5df68
Merge branch 'v3' into cleanupBinaryLoader
zilongshanren Jun 18, 2014
1533374
add ui animation for binary parsing
zilongshanren Jun 18, 2014
9398395
fix custom property
zilongshanren Jun 18, 2014
5cfbd3a
add binary decode to armature
geron-cn Jun 18, 2014
d2746f6
cpp-tests
geron-cn Jun 18, 2014
20b41d2
fix android compile error
zilongshanren Jun 18, 2014
b55b95a
fix linux compile error
zilongshanren Jun 18, 2014
6abc9ab
add binary read to test-cpp
geron-cn Jun 18, 2014
7970855
add binary read to test-cpp
geron-cn Jun 18, 2014
e1095c4
Merge pull request #9 from geron-cn/guanghuiv3
zilongshanren Jun 19, 2014
515de9e
remove magic string of widget json reader
zilongshanren Jun 19, 2014
a26ef87
cleanup reader code
zilongshanren Jun 19, 2014
4d64b16
refactor - replace magic string with const string
zilongshanren Jun 19, 2014
5624da5
Merge branch 'v3' into cleanupBinaryLoader
zilongshanren Jun 23, 2014
8a463e7
remove Hungry style
zilongshanren Jun 23, 2014
87455b0
add constness to some function
zilongshanren Jun 23, 2014
ce58c2d
remove unused header file
zilongshanren Jun 23, 2014
3e5ab0e
fix linux compile error
zilongshanren Jun 23, 2014
d2680f2
fix windows compile error
zilongshanren Jun 23, 2014
7eae762
Merge branch 'v3' into cleanupBinaryLoader
zilongshanren Jun 23, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions build/cocos2d_libs.xcodeproj/project.pbxproj
Expand Up @@ -968,6 +968,10 @@
2905FA8D18CF08D100240AA3 /* UIWidget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2905FA1318CF08D100240AA3 /* UIWidget.cpp */; };
2905FA8E18CF08D100240AA3 /* UIWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA1418CF08D100240AA3 /* UIWidget.h */; };
2905FA8F18CF08D100240AA3 /* UIWidget.h in Headers */ = {isa = PBXBuildFile; fileRef = 2905FA1418CF08D100240AA3 /* UIWidget.h */; };
2939A2911946ED770064B6A1 /* CocoLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2939A28F1946ED770064B6A1 /* CocoLoader.cpp */; };
2939A2921946ED770064B6A1 /* CocoLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2939A28F1946ED770064B6A1 /* CocoLoader.cpp */; };
2939A2931946ED770064B6A1 /* CocoLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 2939A2901946ED770064B6A1 /* CocoLoader.h */; };
2939A2941946ED770064B6A1 /* CocoLoader.h in Headers */ = {isa = PBXBuildFile; fileRef = 2939A2901946ED770064B6A1 /* CocoLoader.h */; };
2986667F18B1B246000E39CA /* CCTweenFunction.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2986667818B1B079000E39CA /* CCTweenFunction.cpp */; };
299754F4193EC95400A54AC3 /* ObjectFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299754F2193EC95400A54AC3 /* ObjectFactory.cpp */; };
299754F5193EC95400A54AC3 /* ObjectFactory.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 299754F2193EC95400A54AC3 /* ObjectFactory.cpp */; };
Expand Down Expand Up @@ -2270,6 +2274,8 @@
2905FA1318CF08D100240AA3 /* UIWidget.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UIWidget.cpp; sourceTree = "<group>"; };
2905FA1418CF08D100240AA3 /* UIWidget.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UIWidget.h; sourceTree = "<group>"; };
29080DEB191B82CE0066F8DF /* UIDeprecated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = UIDeprecated.h; sourceTree = "<group>"; };
2939A28F1946ED770064B6A1 /* CocoLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CocoLoader.cpp; sourceTree = "<group>"; };
2939A2901946ED770064B6A1 /* CocoLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CocoLoader.h; sourceTree = "<group>"; };
2986667818B1B079000E39CA /* CCTweenFunction.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CCTweenFunction.cpp; sourceTree = "<group>"; };
2986667918B1B079000E39CA /* CCTweenFunction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTweenFunction.h; sourceTree = "<group>"; };
299754F2193EC95400A54AC3 /* ObjectFactory.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ObjectFactory.cpp; path = ../base/ObjectFactory.cpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3590,6 +3596,8 @@
1A8C5946180E930E00EF57C3 /* cocostudio */ = {
isa = PBXGroup;
children = (
2939A28F1946ED770064B6A1 /* CocoLoader.cpp */,
2939A2901946ED770064B6A1 /* CocoLoader.h */,
50FCEB6818C72017004AD434 /* WidgetReader */,
06CAAAC1186AD63B0012A414 /* TriggerObj.h */,
06CAAABC186AD63B0012A414 /* TriggerBase.cpp */,
Expand Down Expand Up @@ -5038,6 +5046,7 @@
50FCEBAD18C72017004AD434 /* PageViewReader.h in Headers */,
1A5702F4180BCE750088DEC7 /* CCTMXObjectGroup.h in Headers */,
50ABBDAF1925AB4100A911A9 /* CCRenderer.h in Headers */,
2939A2931946ED770064B6A1 /* CocoLoader.h in Headers */,
1A5702F8180BCE750088DEC7 /* CCTMXTiledMap.h in Headers */,
5034CA21191D591100CE6051 /* ccShader_PositionTextureColorAlphaTest.frag in Headers */,
50ABBDA11925AB4100A911A9 /* CCGroupCommand.h in Headers */,
Expand Down Expand Up @@ -5535,6 +5544,7 @@
1A5702ED180BCE750088DEC7 /* CCTileMapAtlas.h in Headers */,
1A5702F1180BCE750088DEC7 /* CCTMXLayer.h in Headers */,
5034CA44191D591100CE6051 /* ccShader_Label.vert in Headers */,
2939A2941946ED770064B6A1 /* CocoLoader.h in Headers */,
1A5702F5180BCE750088DEC7 /* CCTMXObjectGroup.h in Headers */,
1A5702F9180BCE750088DEC7 /* CCTMXTiledMap.h in Headers */,
1AC0269D1914068200FA920D /* ConvertUTF.h in Headers */,
Expand Down Expand Up @@ -6118,6 +6128,7 @@
1A570061180BC5A10088DEC7 /* CCAction.cpp in Sources */,
50ABBEC51925AB6F00A911A9 /* etc1.cpp in Sources */,
50FCEB9718C72017004AD434 /* CheckBoxReader.cpp in Sources */,
2939A2911946ED770064B6A1 /* CocoLoader.cpp in Sources */,
1A570065180BC5A10088DEC7 /* CCActionCamera.cpp in Sources */,
50ABBEAB1925AB6F00A911A9 /* ccTypes.cpp in Sources */,
1A570069180BC5A10088DEC7 /* CCActionCatmullRom.cpp in Sources */,
Expand Down Expand Up @@ -6773,6 +6784,7 @@
50FCEBAC18C72017004AD434 /* PageViewReader.cpp in Sources */,
1A8C598C180E930E00EF57C3 /* CCActionFrame.cpp in Sources */,
1A8C5990180E930E00EF57C3 /* CCActionFrameEasing.cpp in Sources */,
2939A2921946ED770064B6A1 /* CocoLoader.cpp in Sources */,
29CB8F4D1929D1BB00C841D6 /* UILayoutManager.cpp in Sources */,
50FCEBA418C72017004AD434 /* ListViewReader.cpp in Sources */,
1A8C5994180E930E00EF57C3 /* CCActionManagerEx.cpp in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions build/cocos2d_tests.xcodeproj/project.pbxproj
Expand Up @@ -5454,6 +5454,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
CC_TARGET_OS_IPHONE,
Expand All @@ -5470,6 +5471,7 @@
isa = XCBuildConfiguration;
buildSettings = {
CODE_SIGN_IDENTITY = "iPhone Developer";
DEBUG_INFORMATION_FORMAT = dwarf;
GCC_PREPROCESSOR_DEFINITIONS = (
"$(inherited)",
CC_TARGET_OS_IPHONE,
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* pCocoLoader,
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 = NULL;
for (int i=0; i < pCocoNode->GetChildNum(); ++i) {
std::string key = stChildArray[i].GetName(pCocoLoader);
if (key == "actionlist") {
actionNode = &stChildArray[i];
break;
}
}
if (NULL != actionNode)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NULL -> nullptr

{
int actionCount = actionNode->GetChildNum();
for (int i = 0; i < actionCount; ++i) {
ActionObject* action = new ActionObject();
action->autorelease();

action->initWithBinary(pCocoLoader, 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* pCocoLoader, 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(std::string& value)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::string& value -> const std::string& value?

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

void ActionNode::initWithBinary(CocoLoader *pCocoLoader,
stExpCocoNode *pCocoNode,
cocos2d::Ref *root)
{

stExpCocoNode *stChildNode = pCocoNode;

int actionNodeCount = stChildNode->GetChildNum();
stChildNode = stChildNode[0].GetChildArray();
stExpCocoNode *frameListNode = NULL;
for (int i = 0; i < actionNodeCount; ++i) {
std::string key = stChildNode[i].GetName(pCocoLoader);
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(pCocoLoader);
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(pCocoLoader);
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
9 changes: 8 additions & 1 deletion cocos/editor-support/cocostudio/CCActionNode.h
Expand Up @@ -29,7 +29,9 @@ THE SOFTWARE.
#include "cocostudio/DictionaryHelper.h"

namespace cocostudio {


class CocoLoader;
struct stExpCocoNode;
/**
* @js NA
* @lua NA
Expand Down Expand Up @@ -149,6 +151,7 @@ class ActionNode : public cocos2d::Ref

/*init properties with a json dictionary*/
virtual void initWithDictionary(const rapidjson::Value& dic, cocos2d::Ref* root);
virtual void initWithBinary(CocoLoader* pCocoLoader, stExpCocoNode* pCocoNode, Ref* root);

/**
* Gets if the action is done once time.
Expand All @@ -157,6 +160,10 @@ class ActionNode : public cocos2d::Ref
*/
virtual bool isActionDoneOnce();
protected:
int valueToInt(std::string& value);
bool valueToBool(std::string& value);
float valueToFloat(std::string& value);

int _currentFrameIndex;
int _destFrameIndex;

Expand Down