Merge pull request #15732 from zilongshanren/fix-actionNode-studio

fix actionNode studio 1.6 parser error
This commit is contained in:
zilongshanren 2016-05-26 18:17:25 +08:00
commit f9415734f2
6 changed files with 85 additions and 67 deletions

View File

@ -58,9 +58,10 @@ ActionManagerEx::~ActionManagerEx()
_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;
this->_studioVersionNumber = version;
ssize_t pos = path.find_last_of("/");
std::string fileName = path.substr(pos+1,path.length());
cocos2d::Vector<ActionObject*> actionList;
@ -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 = 1600);
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 "editor-support/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;

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);
}
/**

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"]));
}
}