2013-09-20 22:23:13 +08:00
|
|
|
/****************************************************************************
|
2020-10-17 16:32:16 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2013-12-26 16:29:59 +08:00
|
|
|
|
2022-02-24 18:51:36 +08:00
|
|
|
https://adxeproject.github.io/
|
2013-12-26 16:29:59 +08:00
|
|
|
|
|
|
|
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-10-21 10:12:00 +08:00
|
|
|
#include "CCActionManagerEx.h"
|
|
|
|
#include "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
|
|
|
|
2021-12-25 10:04:45 +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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!sharedActionManager)
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
sharedActionManager = new ActionManagerEx();
|
2016-05-26 17:20:51 +08:00
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (sharedActionManager != nullptr)
|
2014-07-17 17:24:41 +08:00
|
|
|
{
|
|
|
|
sharedActionManager->releaseActions();
|
|
|
|
CC_SAFE_DELETE(sharedActionManager);
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionManagerEx::ActionManagerEx() {}
|
2013-09-20 22:23:13 +08:00
|
|
|
|
|
|
|
ActionManagerEx::~ActionManagerEx()
|
|
|
|
{
|
2016-05-26 17:20:51 +08:00
|
|
|
_actionDic.clear();
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionManagerEx::initWithDictionary(const char* jsonName, const rapidjson::Value& dic, Ref* root, int version)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string path = jsonName;
|
2016-05-26 17:20:51 +08:00
|
|
|
this->_studioVersionNumber = version;
|
2021-12-25 10:04:45 +08:00
|
|
|
ssize_t pos = path.find_last_of("/");
|
|
|
|
std::string fileName = path.substr(pos + 1, path.length());
|
2016-05-26 17:20:51 +08:00
|
|
|
cocos2d::Vector<ActionObject*> actionList;
|
|
|
|
int actionCount = DICTOOL->getArrayCount_json(dic, "actionlist");
|
2021-12-25 10:04:45 +08:00
|
|
|
for (int i = 0; i < actionCount; i++)
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
ActionObject* action = new ActionObject();
|
2016-05-26 17:20:51 +08:00
|
|
|
action->autorelease();
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& actionDic = DICTOOL->getDictionaryFromArray_json(dic, "actionlist", i);
|
|
|
|
action->initWithDictionary(actionDic, root);
|
2016-05-26 17:20:51 +08:00
|
|
|
actionList.pushBack(action);
|
|
|
|
}
|
|
|
|
_actionDic[fileName] = actionList;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
void ActionManagerEx::initWithBinary(const char* file,
|
|
|
|
cocos2d::Ref* root,
|
|
|
|
CocoLoader* cocoLoader,
|
|
|
|
stExpCocoNode* pCocoNode)
|
|
|
|
{
|
|
|
|
std::string path = file;
|
|
|
|
ssize_t pos = path.find_last_of("/");
|
|
|
|
std::string fileName = path.substr(pos + 1, path.length());
|
|
|
|
cocos2d::Vector<ActionObject*> actionList;
|
|
|
|
|
|
|
|
stExpCocoNode* stChildArray = pCocoNode->GetChildArray(cocoLoader);
|
|
|
|
stExpCocoNode* actionNode = nullptr;
|
|
|
|
for (int i = 0; i < pCocoNode->GetChildNum(); ++i)
|
2014-06-18 15:55:01 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string key = stChildArray[i].GetName(cocoLoader);
|
|
|
|
if (key == "actionlist")
|
2014-06-18 15:55:01 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
actionNode = &stChildArray[i];
|
|
|
|
break;
|
2014-06-18 15:55:01 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
if (nullptr != actionNode)
|
|
|
|
{
|
|
|
|
int actionCount = actionNode->GetChildNum();
|
|
|
|
for (int i = 0; i < actionCount; ++i)
|
|
|
|
{
|
|
|
|
ActionObject* action = new ActionObject();
|
|
|
|
action->autorelease();
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
action->initWithBinary(cocoLoader, &actionNode->GetChildArray(cocoLoader)[i], root);
|
|
|
|
|
|
|
|
actionList.pushBack(action);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_actionDic[fileName] = actionList;
|
|
|
|
}
|
2013-09-20 22:23:13 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionObject* ActionManagerEx::getActionByName(const char* jsonName, const char* actionName)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
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);
|
2016-05-26 17:20:51 +08:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionObject* ActionManagerEx::playActionByName(const char* jsonName, const char* actionName)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionObject* action = getActionByName(jsonName, actionName);
|
2016-05-26 17:20:51 +08:00
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
action->play();
|
|
|
|
}
|
|
|
|
return action;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionObject* ActionManagerEx::playActionByName(const char* jsonName, const char* actionName, CallFunc* func)
|
2013-12-24 20:33:55 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionObject* action = getActionByName(jsonName, actionName);
|
2016-05-26 17:20:51 +08:00
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
action->play(func);
|
|
|
|
}
|
|
|
|
return action;
|
2013-12-24 20:33:55 +08:00
|
|
|
}
|
2014-12-11 02:57:13 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionObject* ActionManagerEx::stopActionByName(const char* jsonName, const char* actionName)
|
2014-12-11 02:57:13 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ActionObject* action = getActionByName(jsonName, actionName);
|
2016-05-26 17:20:51 +08:00
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
action->stop();
|
|
|
|
}
|
|
|
|
return action;
|
2014-12-11 02:57:13 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +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;
|
2021-12-25 10:04:45 +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);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (action != nullptr)
|
|
|
|
{
|
2014-07-17 17:24:41 +08:00
|
|
|
action->stop();
|
|
|
|
}
|
|
|
|
}
|
2014-03-07 11:58:54 +08:00
|
|
|
objList.clear();
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-03-07 11:58:54 +08:00
|
|
|
_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;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|