fix actionNode studio 1.6 parser error

This commit is contained in:
zilongshanren 2016-05-26 17:20:51 +08:00
parent 33e34f6e1c
commit 3e941be0ce
6 changed files with 85 additions and 67 deletions

View File

@ -33,10 +33,10 @@ static ActionManagerEx* sharedActionManager = nullptr;
ActionManagerEx* ActionManagerEx::getInstance()
{
if (!sharedActionManager) {
sharedActionManager = new (std::nothrow) ActionManagerEx();
}
return sharedActionManager;
if (!sharedActionManager) {
sharedActionManager = new (std::nothrow) ActionManagerEx();
}
return sharedActionManager;
}
void ActionManagerEx::destroyInstance()
@ -55,30 +55,31 @@ ActionManagerEx::ActionManagerEx()
ActionManagerEx::~ActionManagerEx()
{
_actionDic.clear();
_actionDic.clear();
}
void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root)
void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root, int version)
{
std::string path = jsonName;
ssize_t pos = path.find_last_of("/");
std::string fileName = path.substr(pos+1,path.length());
cocos2d::Vector<ActionObject*> actionList;
int actionCount = DICTOOL->getArrayCount_json(dic, "actionlist");
for (int i=0; i<actionCount; i++) {
ActionObject* action = new (std::nothrow) ActionObject();
action->autorelease();
const rapidjson::Value &actionDic = DICTOOL->getDictionaryFromArray_json(dic, "actionlist", i);
action->initWithDictionary(actionDic,root);
actionList.pushBack(action);
}
_actionDic[fileName] = actionList;
std::string path = jsonName;
this->_studioVersionNumber = version;
ssize_t pos = path.find_last_of("/");
std::string fileName = path.substr(pos+1,path.length());
cocos2d::Vector<ActionObject*> actionList;
int actionCount = DICTOOL->getArrayCount_json(dic, "actionlist");
for (int i=0; i<actionCount; i++) {
ActionObject* action = new (std::nothrow) ActionObject();
action->autorelease();
const rapidjson::Value &actionDic = DICTOOL->getDictionaryFromArray_json(dic, "actionlist", i);
action->initWithDictionary(actionDic,root);
actionList.pushBack(action);
}
_actionDic[fileName] = actionList;
}
void ActionManagerEx::initWithBinary(const char* file,
cocos2d::Ref *root,
CocoLoader* cocoLoader,
stExpCocoNode* pCocoNode)
stExpCocoNode* pCocoNode)
{
std::string path = file;
ssize_t pos = path.find_last_of("/");
@ -113,54 +114,54 @@ void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::V
ActionObject* ActionManagerEx::getActionByName(const char* jsonName,const char* actionName)
{
std::string path = jsonName;
ssize_t pos = path.find_last_of("/");
std::string fileName = path.substr(pos+1,path.length());
auto iterator = _actionDic.find(fileName);
if (iterator == _actionDic.end())
{
return nullptr;
}
auto actionList = iterator->second;
for (int i = 0; i < actionList.size(); i++)
{
ActionObject* action = actionList.at(i);
if (strcmp(actionName, action->getName()) == 0)
{
return action;
}
}
return nullptr;
std::string path = jsonName;
ssize_t pos = path.find_last_of("/");
std::string fileName = path.substr(pos+1,path.length());
auto iterator = _actionDic.find(fileName);
if (iterator == _actionDic.end())
{
return nullptr;
}
auto actionList = iterator->second;
for (int i = 0; i < actionList.size(); i++)
{
ActionObject* action = actionList.at(i);
if (strcmp(actionName, action->getName()) == 0)
{
return action;
}
}
return nullptr;
}
ActionObject* ActionManagerEx::playActionByName(const char* jsonName,const char* actionName)
{
ActionObject* action = getActionByName(jsonName,actionName);
if (action)
{
action->play();
}
return action;
ActionObject* action = getActionByName(jsonName,actionName);
if (action)
{
action->play();
}
return action;
}
ActionObject* ActionManagerEx::playActionByName(const char* jsonName,const char* actionName, CallFunc* func)
{
ActionObject* action = getActionByName(jsonName,actionName);
if (action)
{
action->play(func);
}
return action;
ActionObject* action = getActionByName(jsonName,actionName);
if (action)
{
action->play(func);
}
return action;
}
ActionObject* ActionManagerEx::stopActionByName(const char* jsonName,const char* actionName)
{
ActionObject* action = getActionByName(jsonName,actionName);
if (action)
{
action->stop();
}
return action;
ActionObject* action = getActionByName(jsonName,actionName);
if (action)
{
action->stop();
}
return action;
}
void ActionManagerEx::releaseActions()
@ -182,4 +183,9 @@ void ActionManagerEx::releaseActions()
_actionDic.clear();
}
int ActionManagerEx::getStudioVersionNumber() const
{
return this->_studioVersionNumber;
}
}

View File

@ -110,7 +110,7 @@ public:
ActionObject* stopActionByName(const char* jsonName,const char* actionName);
/*init properties with json dictionary*/
void initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root);
void initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root, int version = 0);
void initWithBinary(const char* file, Ref* root, CocoLoader* cocoLoader, stExpCocoNode* pCocoNode);
/**
@ -119,8 +119,11 @@ public:
*/
void releaseActions();
int getStudioVersionNumber() const;
protected:
std::unordered_map<std::string, cocos2d::Vector<ActionObject*>> _actionDic;
int _studioVersionNumber;
};
}

View File

@ -29,6 +29,8 @@ THE SOFTWARE.
#include "ui/UILayout.h"
#include "editor-support/cocostudio/CocoLoader.h"
#include "base/ccUtils.h"
#include "cocostudio/CCActionManagerEx.h"
using namespace cocos2d;
using namespace ui;
@ -107,7 +109,7 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
{
float positionX = DICTOOL->getFloatValue_json(actionFrameDic, "positionx");
float positionY = DICTOOL->getFloatValue_json(actionFrameDic, "positiony");
if (positionOffset && (nullptr != node->getParent()))
if (positionOffset && (nullptr != node->getParent()) && ActionManagerEx::getInstance()->getStudioVersionNumber() < 1600)
{
Vec2 AnchorPointIn = node->getParent()->getAnchorPointInPoints();
positionX += AnchorPointIn.x;
@ -136,7 +138,7 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
actionFrame->setScaleY(scaleY);
auto cActionArray = _frameArray.at((int)kKeyframeScale);
cActionArray->pushBack(actionFrame);
actionFrame->release();
actionFrame->release();
}
bool existRotation = DICTOOL->checkObjectExist_json(actionFrameDic,"rotation");
@ -637,7 +639,7 @@ void ActionNode::easingToFrame(float duration,float delayTime,ActionFrame* srcFr
if (cAction == nullptr || cNode == nullptr)
{
return;
}
}
cAction->startWithTarget(cNode);
cAction->update(delayTime);
}

View File

@ -251,7 +251,12 @@ static bool js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx(JSContext *c
js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocostudio::ActionManagerEx* cobj = (cocostudio::ActionManagerEx *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx : Invalid Native Object");
if (argc == 3) {
int version = 0;
if (argc == 4) {
ok &= jsval_to_int(cx, args.get(3), &version);
}
if (argc >= 3) {
const char* arg0;
const char* arg1;
cocos2d::Ref* arg2;
@ -271,7 +276,7 @@ static bool js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx(JSContext *c
JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object");
} while (0);
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx : Error processing arguments");
cobj->initWithDictionary(arg0, arg1Jsondoc, arg2);
cobj->initWithDictionary(arg0, arg1Jsondoc, arg2, version);
args.rval().setUndefined();
return true;
}

View File

@ -40,8 +40,8 @@ ccs.actionManager = ccs.ActionManager.getInstance();
ccs.ActionManager.prototype.clear = function() {
this.releaseActions();
};
ccs.ActionManager.prototype.initWithDictionary = function(file, dic, node) {
ccs.actionManager.initWithDictionaryEx(file, JSON.stringify(dic), node);
ccs.ActionManager.prototype.initWithDictionary = function(file, dic, node, version) {
ccs.actionManager.initWithDictionaryEx(file, JSON.stringify(dic), node, version);
}
/**
@ -70,4 +70,4 @@ ccs.Component.extend = ccs.Component.extend || cc.Component.extend;
ccs.SkinNode = cc.Node;
ccs.BoneNode.extend = cc.Class.extend;
ccs.SkeletonNode.extend = cc.Class.extend;
ccs.SkeletonNode.extend = cc.Class.extend;

View File

@ -39,7 +39,9 @@
deferred: function(json, resourcePath, node, file){
if(node){
ccs.actionManager.initWithDictionary(file, json["animation"], node);
var version = json["Version"] || json["version"];
var versionNum = ccs.uiReader.getVersionInteger(version);
ccs.actionManager.initWithDictionary(file, json["animation"], node, versionNum);
node.setContentSize(cc.size(json["designWidth"], json["designHeight"]));
}
}
@ -702,4 +704,4 @@
load.registerParser("ccui", "*", parser);
})(ccs._load, ccs._parser);
})(ccs._load, ccs._parser);