2013-09-20 22:23:13 +08:00
|
|
|
/****************************************************************************
|
2013-12-26 16:29:59 +08:00
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
|
|
|
|
|
|
|
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
|
|
|
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "cocostudio/CCActionManagerEx.h"
|
|
|
|
#include "cocostudio/DictionaryHelper.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
|
|
|
|
|
|
|
static ActionManagerEx* sharedActionManager = NULL;
|
|
|
|
|
|
|
|
ActionManagerEx* ActionManagerEx::shareManager()
|
|
|
|
{
|
2013-12-26 16:29:59 +08:00
|
|
|
if (!sharedActionManager) {
|
|
|
|
sharedActionManager = new ActionManagerEx();
|
|
|
|
}
|
|
|
|
return sharedActionManager;
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void ActionManagerEx::purgeActionManager()
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(sharedActionManager);
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionManagerEx::ActionManagerEx()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
ActionManagerEx::~ActionManagerEx()
|
|
|
|
{
|
2013-12-25 19:46:09 +08:00
|
|
|
_pActionDic.clear();
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
void ActionManagerEx::initWithDictionary(const char* jsonName,const rapidjson::Value &dic,Object* root)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
std::string path = jsonName;
|
2013-12-25 19:46:09 +08:00
|
|
|
ssize_t pos = path.find_last_of("/");
|
2013-09-20 22:23:13 +08:00
|
|
|
std::string fileName = path.substr(pos+1,path.length());
|
|
|
|
CCLOG("filename == %s",fileName.c_str());
|
2013-12-25 19:46:09 +08:00
|
|
|
cocos2d::Vector<ActionObject*> actionList;
|
2013-09-20 22:23:13 +08:00
|
|
|
int actionCount = DICTOOL->getArrayCount_json(dic, "actionlist");
|
2013-12-26 16:29:59 +08:00
|
|
|
for (int i=0; i<actionCount; i++) {
|
|
|
|
ActionObject* action = new ActionObject();
|
2013-09-20 22:23:13 +08:00
|
|
|
action->autorelease();
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &actionDic = DICTOOL->getDictionaryFromArray_json(dic, "actionlist", i);
|
2013-12-26 16:29:59 +08:00
|
|
|
action->initWithDictionary(actionDic,root);
|
|
|
|
actionList.pushBack(action);
|
|
|
|
}
|
2013-12-25 19:46:09 +08:00
|
|
|
_pActionDic.insert(std::pair<std::string, cocos2d::Vector<ActionObject*>>(fileName, actionList));
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ActionObject* ActionManagerEx::getActionByName(const char* jsonName,const char* actionName)
|
|
|
|
{
|
2013-12-25 19:46:09 +08:00
|
|
|
auto iterator = _pActionDic.find(jsonName);
|
|
|
|
if (iterator == _pActionDic.end())
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-12-26 16:29:59 +08:00
|
|
|
auto actionList = iterator->second;
|
2013-12-25 19:46:09 +08:00
|
|
|
for (int i = 0; i < actionList.size(); i++)
|
2013-09-20 22:23:13 +08:00
|
|
|
{
|
2013-12-25 19:46:09 +08:00
|
|
|
ActionObject* action = actionList.at(i);
|
2013-09-20 22:23:13 +08:00
|
|
|
if (strcmp(actionName, action->getName()) == 0)
|
|
|
|
{
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
|
|
|
ActionObject* action = getActionByName(jsonName,actionName);
|
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
action->play();
|
|
|
|
}
|
2013-11-19 00:57:22 +08:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
ActionObject* action = getActionByName(jsonName,actionName);
|
|
|
|
if (action)
|
|
|
|
{
|
|
|
|
action->play(func);
|
|
|
|
}
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2013-09-20 22:23:13 +08:00
|
|
|
void ActionManagerEx::releaseActions()
|
|
|
|
{
|
2013-12-26 16:29:59 +08:00
|
|
|
_pActionDic.clear();
|
2013-09-20 22:23:13 +08:00
|
|
|
}
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|