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

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

View File

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

View File

@ -29,6 +29,8 @@ THE SOFTWARE.
#include "ui/UILayout.h" #include "ui/UILayout.h"
#include "editor-support/cocostudio/CocoLoader.h" #include "editor-support/cocostudio/CocoLoader.h"
#include "base/ccUtils.h" #include "base/ccUtils.h"
#include "editor-support/cocostudio/CCActionManagerEx.h"
using namespace cocos2d; using namespace cocos2d;
using namespace ui; using namespace ui;
@ -107,7 +109,7 @@ void ActionNode::initWithDictionary(const rapidjson::Value& dic, Ref* root)
{ {
float positionX = DICTOOL->getFloatValue_json(actionFrameDic, "positionx"); float positionX = DICTOOL->getFloatValue_json(actionFrameDic, "positionx");
float positionY = DICTOOL->getFloatValue_json(actionFrameDic, "positiony"); 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(); Vec2 AnchorPointIn = node->getParent()->getAnchorPointInPoints();
positionX += AnchorPointIn.x; 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); js_proxy_t *proxy = jsb_get_js_proxy(obj);
cocostudio::ActionManagerEx* cobj = (cocostudio::ActionManagerEx *)(proxy ? proxy->ptr : NULL); cocostudio::ActionManagerEx* cobj = (cocostudio::ActionManagerEx *)(proxy ? proxy->ptr : NULL);
JSB_PRECONDITION2( cobj, cx, false, "js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx : Invalid Native Object"); 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* arg0;
const char* arg1; const char* arg1;
cocos2d::Ref* arg2; cocos2d::Ref* arg2;
@ -271,7 +276,7 @@ static bool js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx(JSContext *c
JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object"); JSB_PRECONDITION2( arg2, cx, false, "Invalid Native Object");
} while (0); } while (0);
JSB_PRECONDITION2(ok, cx, false, "js_cocos2dx_studio_ActionManagerEx_initWithDictionaryEx : Error processing arguments"); 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(); args.rval().setUndefined();
return true; return true;
} }

View File

@ -40,8 +40,8 @@ ccs.actionManager = ccs.ActionManager.getInstance();
ccs.ActionManager.prototype.clear = function() { ccs.ActionManager.prototype.clear = function() {
this.releaseActions(); this.releaseActions();
}; };
ccs.ActionManager.prototype.initWithDictionary = function(file, dic, node) { ccs.ActionManager.prototype.initWithDictionary = function(file, dic, node, version) {
ccs.actionManager.initWithDictionaryEx(file, JSON.stringify(dic), node); ccs.actionManager.initWithDictionaryEx(file, JSON.stringify(dic), node, version);
} }
/** /**

View File

@ -39,7 +39,9 @@
deferred: function(json, resourcePath, node, file){ deferred: function(json, resourcePath, node, file){
if(node){ 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"])); node.setContentSize(cc.size(json["designWidth"], json["designHeight"]));
} }
} }