2013-09-20 22:23:13 +08:00
|
|
|
/****************************************************************************
|
2019-11-25 01:35:26 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2013-12-26 16:29:59 +08:00
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2020-08-03 17:51:40 +08:00
|
|
|
#include "cocostudio/CCActionManagerEx.h"
|
|
|
|
#include "cocostudio/CocoLoader.h"
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2013-12-26 16:29:59 +08:00
|
|
|
using namespace cocos2d;
|
2013-10-15 18:00:03 +08:00
|
|
|
|
|
|
|
namespace cocostudio {
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2013-12-26 23:40:50 +08:00
|
|
|
static ActionManagerEx* sharedActionManager = nullptr;
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2013-12-27 10:43:49 +08:00
|
|
|
ActionManagerEx* ActionManagerEx::getInstance()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2016-05-26 17:20:51 +08:00
|
|
|
if (!sharedActionManager) {
|
|
|
|
sharedActionManager = new (std::nothrow) ActionManagerEx();
|
|
|
|
}
|
|
|
|
return sharedActionManager;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-27 17:21:13 +08:00
|
|
|
void ActionManagerEx::destroyInstance()
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2014-07-17 17:24:41 +08:00
|
|
|
if(sharedActionManager != nullptr)
|
|
|
|
{
|
|
|
|
sharedActionManager->releaseActions();
|
|
|
|
CC_SAFE_DELETE(sharedActionManager);
|
|
|
|
}
|
|
|
|
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ActionManagerEx::ActionManagerEx()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionManagerEx::~ActionManagerEx()
|
|
|
|
{
|
2016-05-26 17:20:51 +08:00
|
|
|
_actionDic.clear();
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2016-05-26 17:20:51 +08:00
|
|
|
void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::Value &dic, Ref* root, int version)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2016-05-26 17:20:51 +08:00
|
|
|
std::string path = jsonName;
|
|
|
|
this->_studioVersionNumber = version;
|
2019-11-25 01:35:26 +08:00
|
|
|
ssize_t pos = path.find_last_of('/');
|
2016-05-26 17:20:51 +08:00
|
|
|
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;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
2014-06-18 15:55:01 +08:00
|
|
|
|
|
|
|
void ActionManagerEx::initWithBinary(const char* file,
|
|
|
|
cocos2d::Ref *root,
|
2014-06-23 10:02:09 +08:00
|
|
|
CocoLoader* cocoLoader,
|
2016-05-26 17:20:51 +08:00
|
|
|
stExpCocoNode* pCocoNode)
|
2014-06-18 15:55:01 +08:00
|
|
|
{
|
|
|
|
std::string path = file;
|
2019-11-25 01:35:26 +08:00
|
|
|
ssize_t pos = path.find_last_of('/');
|
2014-06-18 15:55:01 +08:00
|
|
|
std::string fileName = path.substr(pos+1,path.length());
|
|
|
|
cocos2d::Vector<ActionObject*> actionList;
|
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *stChildArray = pCocoNode->GetChildArray(cocoLoader);
|
2014-06-23 10:12:54 +08:00
|
|
|
stExpCocoNode *actionNode = nullptr;
|
2014-06-18 15:55:01 +08:00
|
|
|
for (int i=0; i < pCocoNode->GetChildNum(); ++i) {
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string key = stChildArray[i].GetName(cocoLoader);
|
2014-06-18 15:55:01 +08:00
|
|
|
if (key == "actionlist") {
|
|
|
|
actionNode = &stChildArray[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-06-23 10:12:54 +08:00
|
|
|
if (nullptr != actionNode)
|
2014-06-18 15:55:01 +08:00
|
|
|
{
|
|
|
|
int actionCount = actionNode->GetChildNum();
|
|
|
|
for (int i = 0; i < actionCount; ++i) {
|
2014-08-28 07:31:57 +08:00
|
|
|
ActionObject* action = new (std::nothrow) ActionObject();
|
2014-06-18 15:55:01 +08:00
|
|
|
action->autorelease();
|
|
|
|
|
2014-10-12 08:58:28 +08:00
|
|
|
action->initWithBinary(cocoLoader, &actionNode->GetChildArray(cocoLoader)[i], root);
|
2014-06-18 15:55:01 +08:00
|
|
|
|
|
|
|
actionList.pushBack(action);
|
|
|
|
}
|
|
|
|
}
|
2014-09-26 11:29:48 +08:00
|
|
|
_actionDic[fileName] = actionList;
|
2014-06-18 15:55:01 +08:00
|
|
|
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
|
|
|
|
|
|
|
|
ActionObject* ActionManagerEx::getActionByName(const char* jsonName,const char* actionName)
|
|
|
|
{
|
2016-05-26 17:20:51 +08:00
|
|
|
std::string path = jsonName;
|
2019-11-25 01:35:26 +08:00
|
|
|
ssize_t pos = path.find_last_of('/');
|
2016-05-26 17:20:51 +08:00
|
|
|
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;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2013-11-19 00:57:22 +08:00
|
|
|
ActionObject* ActionManagerEx::playActionByName(const char* jsonName,const char* actionName)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2016-05-26 17:20:51 +08:00
|
|
|
ActionObject* action = getActionByName(jsonName,actionName);
|
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
action->play();
|
|
|
|
}
|
|
|
|
return action;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
ActionObject* ActionManagerEx::playActionByName(const char* jsonName,const char* actionName, CallFunc* func)
|
|
|
|
{
|
2016-05-26 17:20:51 +08:00
|
|
|
ActionObject* action = getActionByName(jsonName,actionName);
|
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
action->play(func);
|
|
|
|
}
|
|
|
|
return action;
|
2013-12-24 20:33:55 +08:00
|
|
|
}
|
2014-12-11 02:57:13 +08:00
|
|
|
|
|
|
|
ActionObject* ActionManagerEx::stopActionByName(const char* jsonName,const char* actionName)
|
|
|
|
{
|
2016-05-26 17:20:51 +08:00
|
|
|
ActionObject* action = getActionByName(jsonName,actionName);
|
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
action->stop();
|
|
|
|
}
|
|
|
|
return action;
|
2014-12-11 02:57:13 +08:00
|
|
|
}
|
2014-03-07 11:58:54 +08:00
|
|
|
|
2013-09-20 22:23:13 +08:00
|
|
|
void ActionManagerEx::releaseActions()
|
|
|
|
{
|
2016-10-12 01:59:44 +08:00
|
|
|
for (auto& iter : _actionDic)
|
2014-03-07 11:58:54 +08:00
|
|
|
{
|
2016-10-12 01:59:44 +08:00
|
|
|
cocos2d::Vector<ActionObject*> objList = iter.second;
|
2014-08-21 16:21:23 +08:00
|
|
|
ssize_t listCount = objList.size();
|
|
|
|
for (ssize_t i = 0; i < listCount; i++) {
|
2014-07-17 17:24:41 +08:00
|
|
|
ActionObject* action = objList.at(i);
|
|
|
|
if (action != nullptr) {
|
|
|
|
action->stop();
|
|
|
|
}
|
|
|
|
}
|
2014-03-07 11:58:54 +08:00
|
|
|
objList.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
_actionDic.clear();
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2016-05-26 17:20:51 +08:00
|
|
|
int ActionManagerEx::getStudioVersionNumber() const
|
|
|
|
{
|
|
|
|
return this->_studioVersionNumber;
|
|
|
|
}
|
|
|
|
|
2014-03-25 11:41:16 +08:00
|
|
|
}
|