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
cocostudio binary parser #7123
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 8690122
add version 300 parsing code in widget reader
zilongshanren 3dc6e86
add binary file parsing into ui tests
zilongshanren c96a608
improve parsing code
zilongshanren 6bbf5a1
tests
zilongshanren 48f7743
Merge branch 'v3' into cleanupBinaryLoader
zilongshanren b895018
update parser
zilongshanren 7a8f27e
remove unused parser code
zilongshanren 2f6f1b7
improve binary format
zilongshanren f502634
improve parser
zilongshanren 5515c43
improve lasers
zilongshanren 1d01fe8
refactor
zilongshanren 9ab4574
Merge branch 'v3' into cleanupBinaryLoader
zilongshanren ca24ad6
Merge branch 'v3' into cleanupBinaryLoader
zilongshanren 2cef0cb
update ccs-res
zilongshanren 95f1bd7
update loader
zilongshanren 615995a
add base property parser for WidgetReader
zilongshanren 12bb756
fix cannot compile in windows
geron-cn 63475a6
refactor Loader
zilongshanren 0b677a8
Merge pull request #8 from geron-cn/guagnhuiv3
zilongshanren f614e9a
fix tests
zilongshanren aa5df68
Merge branch 'v3' into cleanupBinaryLoader
zilongshanren 1533374
add ui animation for binary parsing
zilongshanren 9398395
fix custom property
zilongshanren 5cfbd3a
add binary decode to armature
geron-cn d2746f6
cpp-tests
geron-cn 20b41d2
fix android compile error
zilongshanren b55b95a
fix linux compile error
zilongshanren 6abc9ab
add binary read to test-cpp
geron-cn 7970855
add binary read to test-cpp
geron-cn e1095c4
Merge pull request #9 from geron-cn/guanghuiv3
zilongshanren 515de9e
remove magic string of widget json reader
zilongshanren a26ef87
cleanup reader code
zilongshanren 4d64b16
refactor - replace magic string with const string
zilongshanren 5624da5
Merge branch 'v3' into cleanupBinaryLoader
zilongshanren 8a463e7
remove Hungry style
zilongshanren 87455b0
add constness to some function
zilongshanren ce58c2d
remove unused header file
zilongshanren 3e5ab0e
fix linux compile error
zilongshanren d2680f2
fix windows compile error
zilongshanren 7eae762
Merge branch 'v3' into cleanupBinaryLoader
zilongshanren File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -167,6 +168,149 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root) | |
} | ||
initActionNodeFromRoot(root); | ||
} | ||
|
||
int ActionNode::valueToInt(std::string& value) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NULL -> nullptr