2013-06-06 12:02:54 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:47:11 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2013-06-06 12:02:54 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "platform/CCFileUtils.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "base/CCScheduler.h"
|
2014-01-17 13:35:58 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
#include "tinyxml2.h"
|
2014-01-17 13:35:58 +08:00
|
|
|
|
2013-10-16 16:48:39 +08:00
|
|
|
#include "cocostudio/CCDataReaderHelper.h"
|
|
|
|
#include "cocostudio/CCArmatureDataManager.h"
|
|
|
|
#include "cocostudio/CCTransformHelp.h"
|
|
|
|
#include "cocostudio/CCUtilMath.h"
|
|
|
|
#include "cocostudio/CCArmatureDefine.h"
|
|
|
|
#include "cocostudio/CCDatas.h"
|
2013-10-15 18:00:03 +08:00
|
|
|
|
2014-06-23 17:09:54 +08:00
|
|
|
#include "cocostudio/CocoLoader.h"
|
|
|
|
|
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
using namespace cocos2d;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
|
2013-06-07 14:47:08 +08:00
|
|
|
static const char *VERSION = "version";
|
|
|
|
static const float VERSION_2_0 = 2.0f;
|
|
|
|
|
|
|
|
static const char *ARMATURES = "armatures";
|
|
|
|
static const char *ARMATURE = "armature";
|
|
|
|
static const char *BONE = "b";
|
|
|
|
static const char *DISPLAY = "d";
|
|
|
|
|
|
|
|
static const char *ANIMATIONS = "animations";
|
|
|
|
static const char *ANIMATION = "animation";
|
|
|
|
static const char *MOVEMENT = "mov";
|
|
|
|
static const char *FRAME = "f";
|
|
|
|
|
|
|
|
static const char *TEXTURE_ATLAS = "TextureAtlas";
|
|
|
|
static const char *SUB_TEXTURE = "SubTexture";
|
|
|
|
|
|
|
|
static const char *A_NAME = "name";
|
|
|
|
static const char *A_DURATION = "dr";
|
2013-09-13 18:07:37 +08:00
|
|
|
static const char *A_FRAME_INDEX = "fi";
|
2013-06-07 14:47:08 +08:00
|
|
|
static const char *A_DURATION_TO = "to";
|
|
|
|
static const char *A_DURATION_TWEEN = "drTW";
|
|
|
|
static const char *A_LOOP = "lp";
|
|
|
|
static const char *A_MOVEMENT_SCALE = "sc";
|
|
|
|
static const char *A_MOVEMENT_DELAY = "dl";
|
|
|
|
static const char *A_DISPLAY_INDEX = "dI";
|
|
|
|
|
|
|
|
static const char *A_PLIST = "plist";
|
|
|
|
|
|
|
|
static const char *A_PARENT = "parent";
|
|
|
|
static const char *A_SKEW_X = "kX";
|
|
|
|
static const char *A_SKEW_Y = "kY";
|
|
|
|
static const char *A_SCALE_X = "cX";
|
|
|
|
static const char *A_SCALE_Y = "cY";
|
|
|
|
static const char *A_Z = "z";
|
|
|
|
static const char *A_EVENT = "evt";
|
|
|
|
static const char *A_SOUND = "sd";
|
|
|
|
static const char *A_SOUND_EFFECT = "sdE";
|
|
|
|
static const char *A_TWEEN_EASING = "twE";
|
2013-12-13 15:02:09 +08:00
|
|
|
static const char *A_EASING_PARAM = "twEP";
|
2013-12-19 21:12:25 +08:00
|
|
|
static const char *A_TWEEN_ROTATE = "twR";
|
2013-06-07 14:47:08 +08:00
|
|
|
static const char *A_IS_ARMATURE = "isArmature";
|
|
|
|
static const char *A_DISPLAY_TYPE = "displayType";
|
|
|
|
static const char *A_MOVEMENT = "mov";
|
|
|
|
|
|
|
|
static const char *A_X = "x";
|
|
|
|
static const char *A_Y = "y";
|
|
|
|
|
|
|
|
static const char *A_COCOS2DX_X = "cocos2d_x";
|
|
|
|
static const char *A_COCOS2DX_Y = "cocos2d_y";
|
|
|
|
|
|
|
|
static const char *A_WIDTH = "width";
|
|
|
|
static const char *A_HEIGHT = "height";
|
|
|
|
static const char *A_PIVOT_X = "pX";
|
|
|
|
static const char *A_PIVOT_Y = "pY";
|
|
|
|
|
|
|
|
static const char *A_COCOS2D_PIVOT_X = "cocos2d_pX";
|
|
|
|
static const char *A_COCOS2D_PIVOT_Y = "cocos2d_pY";
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
static const char *A_BLEND_TYPE = "bd";
|
2013-12-13 15:02:09 +08:00
|
|
|
static const char *A_BLEND_SRC = "bd_src";
|
|
|
|
static const char *A_BLEND_DST = "bd_dst";
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-06-07 14:47:08 +08:00
|
|
|
static const char *A_ALPHA = "a";
|
|
|
|
static const char *A_RED = "r";
|
|
|
|
static const char *A_GREEN = "g";
|
|
|
|
static const char *A_BLUE = "b";
|
|
|
|
static const char *A_ALPHA_OFFSET = "aM";
|
|
|
|
static const char *A_RED_OFFSET = "rM";
|
|
|
|
static const char *A_GREEN_OFFSET = "gM";
|
|
|
|
static const char *A_BLUE_OFFSET = "bM";
|
|
|
|
static const char *A_COLOR_TRANSFORM = "colorTransform";
|
2013-09-17 20:14:08 +08:00
|
|
|
static const char *A_TWEEN_FRAME = "tweenFrame";
|
2013-06-07 14:47:08 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static const char *CONTOUR = "con";
|
|
|
|
static const char *CONTOUR_VERTEX = "con_vt";
|
|
|
|
|
|
|
|
|
|
|
|
static const char *FL_NAN = "NaN";
|
|
|
|
|
|
|
|
|
|
|
|
static const char *FRAME_DATA = "frame_data";
|
|
|
|
static const char *MOVEMENT_BONE_DATA = "mov_bone_data";
|
|
|
|
static const char *MOVEMENT_DATA = "mov_data";
|
|
|
|
static const char *ANIMATION_DATA = "animation_data";
|
|
|
|
static const char *DISPLAY_DATA = "display_data";
|
2013-09-13 18:07:37 +08:00
|
|
|
static const char *SKIN_DATA = "skin_data";
|
2013-06-07 14:47:08 +08:00
|
|
|
static const char *BONE_DATA = "bone_data";
|
|
|
|
static const char *ARMATURE_DATA = "armature_data";
|
|
|
|
static const char *CONTOUR_DATA = "contour_data";
|
|
|
|
static const char *TEXTURE_DATA = "texture_data";
|
|
|
|
static const char *VERTEX_POINT = "vertex";
|
|
|
|
static const char *COLOR_INFO = "color";
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
static const char *CONFIG_FILE_PATH = "config_file_path";
|
2013-10-30 09:41:40 +08:00
|
|
|
static const char *CONTENT_SCALE = "content_scale";
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
namespace cocostudio {
|
2013-06-07 14:47:08 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-10-31 17:28:14 +08:00
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
float s_PositionReadScale = 1;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-10-31 17:28:14 +08:00
|
|
|
std::vector<std::string> DataReaderHelper::_configFileList;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
DataReaderHelper *DataReaderHelper::_dataReaderHelper = nullptr;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
//! Async load
|
2013-09-15 19:08:45 +08:00
|
|
|
void DataReaderHelper::loadData()
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-11-05 15:32:13 +08:00
|
|
|
AsyncStruct *pAsyncStruct = nullptr;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
std::queue<AsyncStruct *> *pQueue = _asyncStructQueue;
|
|
|
|
_asyncStructQueueMutex.lock(); // get async struct from queue
|
2013-09-13 18:07:37 +08:00
|
|
|
if (pQueue->empty())
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_asyncStructQueueMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
if (need_quit)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
std::unique_lock<std::mutex> lk(_sleepMutex);
|
|
|
|
_sleepCondition.wait(lk);
|
2013-09-13 18:07:37 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pAsyncStruct = pQueue->front();
|
|
|
|
pQueue->pop();
|
2013-09-15 20:24:25 +08:00
|
|
|
_asyncStructQueueMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2013-10-31 17:28:14 +08:00
|
|
|
// generate data info
|
2013-09-13 18:07:37 +08:00
|
|
|
DataInfo *pDataInfo = new DataInfo();
|
|
|
|
pDataInfo->asyncStruct = pAsyncStruct;
|
2013-11-05 11:57:20 +08:00
|
|
|
pDataInfo->filename = pAsyncStruct->filename;
|
|
|
|
pDataInfo->baseFilePath = pAsyncStruct->baseFilePath;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
if (pAsyncStruct->configType == DragonBone_XML)
|
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
DataReaderHelper::addDataFromCache(pAsyncStruct->fileContent.c_str(), pDataInfo);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
else if(pAsyncStruct->configType == CocoStudio_JSON)
|
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
DataReaderHelper::addDataFromJsonCache(pAsyncStruct->fileContent.c_str(), pDataInfo);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2014-06-18 20:09:12 +08:00
|
|
|
else if(pAsyncStruct->configType == CocoStudio_Binary)
|
|
|
|
{
|
|
|
|
DataReaderHelper::addDataFromBinaryCache(pAsyncStruct->fileContent.c_str(),pDataInfo);
|
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
// put the image info into the queue
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataInfoMutex.lock();
|
|
|
|
_dataQueue->push(pDataInfo);
|
|
|
|
_dataInfoMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
if( _asyncStructQueue != nullptr )
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
delete _asyncStructQueue;
|
2013-11-05 15:32:13 +08:00
|
|
|
_asyncStructQueue = nullptr;
|
2013-09-15 20:24:25 +08:00
|
|
|
delete _dataQueue;
|
2013-11-05 15:32:13 +08:00
|
|
|
_dataQueue = nullptr;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-16 15:16:05 +08:00
|
|
|
DataReaderHelper *DataReaderHelper::getInstance()
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
if(!_dataReaderHelper)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper = new DataReaderHelper();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
return _dataReaderHelper;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void DataReaderHelper::setPositionReadScale(float scale)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
s_PositionReadScale = scale;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
float DataReaderHelper::getPositionReadScale()
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
return s_PositionReadScale;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void DataReaderHelper::purge()
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-10-31 17:28:14 +08:00
|
|
|
_configFileList.clear();
|
2013-09-15 20:24:25 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(_dataReaderHelper);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
DataReaderHelper::DataReaderHelper()
|
2013-09-15 20:24:25 +08:00
|
|
|
: _loadingThread(nullptr)
|
|
|
|
, _asyncRefCount(0)
|
|
|
|
, _asyncRefTotalCount(0)
|
2013-11-13 11:22:34 +08:00
|
|
|
, need_quit(false)
|
|
|
|
, _asyncStructQueue(nullptr)
|
|
|
|
, _dataQueue(nullptr)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
DataReaderHelper::~DataReaderHelper()
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
|
|
|
need_quit = true;
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_sleepCondition.notify_one();
|
|
|
|
if (_loadingThread) _loadingThread->join();
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
CC_SAFE_DELETE(_loadingThread);
|
2013-11-05 15:32:13 +08:00
|
|
|
_dataReaderHelper = nullptr;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2013-12-23 14:05:46 +08:00
|
|
|
void DataReaderHelper::addDataFromFile(const std::string& filePath)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
/*
|
2013-09-15 19:08:45 +08:00
|
|
|
* Check if file is already added to ArmatureDataManager, if then return.
|
2013-06-07 10:52:32 +08:00
|
|
|
*/
|
2013-10-31 17:28:14 +08:00
|
|
|
for(unsigned int i = 0; i < _configFileList.size(); i++)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-12-24 14:21:25 +08:00
|
|
|
if (_configFileList[i] == filePath)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-10-31 17:28:14 +08:00
|
|
|
_configFileList.push_back(filePath);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
//! find the base file path
|
2013-11-05 11:57:20 +08:00
|
|
|
std::string basefilePath = filePath;
|
|
|
|
size_t pos = basefilePath.find_last_of("/");
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
2013-11-05 11:57:20 +08:00
|
|
|
basefilePath = basefilePath.substr(0, pos + 1);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-05 11:57:20 +08:00
|
|
|
basefilePath = "";
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string filePathStr = filePath;
|
2013-06-07 10:52:32 +08:00
|
|
|
size_t startPos = filePathStr.find_last_of(".");
|
|
|
|
std::string str = &filePathStr[startPos];
|
|
|
|
|
2013-12-24 13:35:46 +08:00
|
|
|
// Read content from file
|
2014-01-17 13:35:58 +08:00
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
2014-07-01 19:06:51 +08:00
|
|
|
bool isbinaryfilesrc = str==".csb";
|
2014-06-18 20:09:12 +08:00
|
|
|
std::string filemode("r");
|
2014-07-01 19:06:51 +08:00
|
|
|
if(isbinaryfilesrc)
|
2014-06-18 20:09:12 +08:00
|
|
|
filemode += "b";
|
|
|
|
ssize_t filesize;
|
|
|
|
|
|
|
|
_dataReaderHelper->_getFileMutex.lock();
|
|
|
|
unsigned char *pBytes = FileUtils::getInstance()->getFileData(filePath, filemode.c_str(), &filesize);
|
|
|
|
std::string contentStr((const char*)pBytes,filesize);
|
|
|
|
_dataReaderHelper->_getFileMutex.unlock();
|
|
|
|
|
2013-10-31 17:28:14 +08:00
|
|
|
DataInfo dataInfo;
|
|
|
|
dataInfo.filename = filePathStr;
|
2013-11-05 15:32:13 +08:00
|
|
|
dataInfo.asyncStruct = nullptr;
|
2013-11-05 11:57:20 +08:00
|
|
|
dataInfo.baseFilePath = basefilePath;
|
2013-12-24 14:21:25 +08:00
|
|
|
if (str == ".xml")
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-12-24 13:35:46 +08:00
|
|
|
DataReaderHelper::addDataFromCache(contentStr, &dataInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-12-24 14:21:25 +08:00
|
|
|
else if(str == ".json" || str == ".ExportJson")
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-12-24 13:35:46 +08:00
|
|
|
DataReaderHelper::addDataFromJsonCache(contentStr, &dataInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2014-07-01 19:06:51 +08:00
|
|
|
else if(isbinaryfilesrc)
|
2014-06-18 20:09:12 +08:00
|
|
|
{
|
|
|
|
DataReaderHelper::addDataFromBinaryCache(contentStr.c_str(),&dataInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
CC_SAFE_DELETE_ARRAY(pBytes);
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
void DataReaderHelper::addDataFromFileAsync(const std::string& imagePath, const std::string& plistPath, const std::string& filePath, Ref *target, SEL_SCHEDULE selector)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
/*
|
2013-09-15 19:08:45 +08:00
|
|
|
* Check if file is already added to ArmatureDataManager, if then return.
|
2013-06-07 10:52:32 +08:00
|
|
|
*/
|
2013-10-31 17:28:14 +08:00
|
|
|
for(unsigned int i = 0; i < _configFileList.size(); i++)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-12-24 14:21:25 +08:00
|
|
|
if (_configFileList[i] == filePath)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
|
|
|
if (target && selector)
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
if (_asyncRefTotalCount == 0 && _asyncRefCount == 0)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
|
|
|
(target->*selector)(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
(target->*selector)((_asyncRefTotalCount - _asyncRefCount) / (float)_asyncRefTotalCount);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-10-31 17:28:14 +08:00
|
|
|
_configFileList.push_back(filePath);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
//! find the base file path
|
2013-10-30 09:41:40 +08:00
|
|
|
std::string basefilePath = filePath;
|
|
|
|
size_t pos = basefilePath.find_last_of("/");
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
2013-10-30 11:34:16 +08:00
|
|
|
basefilePath = basefilePath.substr(0, pos + 1);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-10-30 09:41:40 +08:00
|
|
|
basefilePath = "";
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// lazy init
|
2013-11-05 15:32:13 +08:00
|
|
|
if (_asyncStructQueue == nullptr)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_asyncStructQueue = new std::queue<AsyncStruct *>();
|
|
|
|
_dataQueue = new std::queue<DataInfo *>();
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
// create a new thread to load images
|
2013-09-15 20:24:25 +08:00
|
|
|
_loadingThread = new std::thread(&DataReaderHelper::loadData, this);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
need_quit = false;
|
|
|
|
}
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
if (0 == _asyncRefCount)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2014-03-03 11:00:30 +08:00
|
|
|
Director::getInstance()->getScheduler()->schedule(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this, 0, false);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
++_asyncRefCount;
|
|
|
|
++_asyncRefTotalCount;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
target->retain();
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate async struct
|
|
|
|
AsyncStruct *data = new AsyncStruct();
|
|
|
|
data->filename = filePath;
|
2013-10-30 09:41:40 +08:00
|
|
|
data->baseFilePath = basefilePath;
|
2013-09-13 18:07:37 +08:00
|
|
|
data->target = target;
|
|
|
|
data->selector = selector;
|
2013-09-16 15:16:05 +08:00
|
|
|
data->autoLoadSpriteFile = ArmatureDataManager::getInstance()->isAutoLoadSpriteFile();
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-10-30 09:41:40 +08:00
|
|
|
data->imagePath = imagePath;
|
|
|
|
data->plistPath = plistPath;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
std::string filePathStr = filePath;
|
|
|
|
size_t startPos = filePathStr.find_last_of(".");
|
|
|
|
std::string str = &filePathStr[startPos];
|
|
|
|
|
2014-01-17 13:35:58 +08:00
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
2013-11-12 10:09:47 +08:00
|
|
|
|
2014-06-18 20:09:12 +08:00
|
|
|
bool isbinaryfilesrc = str==".csb";
|
|
|
|
std::string filereadmode("r");
|
|
|
|
if (isbinaryfilesrc) {
|
|
|
|
filereadmode += "b";
|
|
|
|
}
|
|
|
|
ssize_t size;
|
2013-11-12 10:09:47 +08:00
|
|
|
// XXX fileContent is being leaked
|
2014-06-18 20:09:12 +08:00
|
|
|
|
|
|
|
_dataReaderHelper->_getFileMutex.lock();
|
|
|
|
unsigned char *pBytes = FileUtils::getInstance()->getFileData(fullPath.c_str() , filereadmode.c_str(), &size);
|
|
|
|
_dataReaderHelper->_getFileMutex.unlock();
|
|
|
|
|
|
|
|
Data bytecpy;
|
|
|
|
bytecpy.copy(pBytes, size);
|
|
|
|
data->fileContent = std::string((const char*)bytecpy.getBytes(), size);
|
|
|
|
CC_SAFE_DELETE_ARRAY(pBytes);
|
|
|
|
|
2013-12-24 14:21:25 +08:00
|
|
|
if (str == ".xml")
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
data->configType = DragonBone_XML;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-12-24 14:21:25 +08:00
|
|
|
else if(str == ".json" || str == ".ExportJson")
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
|
|
|
data->configType = CocoStudio_JSON;
|
|
|
|
}
|
2014-07-01 19:06:51 +08:00
|
|
|
else if(isbinaryfilesrc)
|
2014-06-18 20:09:12 +08:00
|
|
|
{
|
|
|
|
data->configType = CocoStudio_Binary;
|
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
// add async struct into queue
|
2013-09-15 20:24:25 +08:00
|
|
|
_asyncStructQueueMutex.lock();
|
|
|
|
_asyncStructQueue->push(data);
|
|
|
|
_asyncStructQueueMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_sleepCondition.notify_one();
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
void DataReaderHelper::addDataAsyncCallBack(float dt)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
// the data is generated in loading thread
|
2013-09-15 20:24:25 +08:00
|
|
|
std::queue<DataInfo *> *dataQueue = _dataQueue;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataInfoMutex.lock();
|
2013-09-13 18:07:37 +08:00
|
|
|
if (dataQueue->empty())
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataInfoMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DataInfo *pDataInfo = dataQueue->front();
|
|
|
|
dataQueue->pop();
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataInfoMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
AsyncStruct *pAsyncStruct = pDataInfo->asyncStruct;
|
|
|
|
|
2013-10-30 09:41:40 +08:00
|
|
|
|
|
|
|
if (pAsyncStruct->imagePath != "" && pAsyncStruct->plistPath != "")
|
|
|
|
{
|
|
|
|
_getFileMutex.lock();
|
2014-07-01 16:24:59 +08:00
|
|
|
ArmatureDataManager::getInstance()->addSpriteFrameFromFile(pAsyncStruct->plistPath.c_str(), pAsyncStruct->imagePath.c_str(), pDataInfo->filename.c_str());
|
2013-10-30 09:41:40 +08:00
|
|
|
_getFileMutex.unlock();
|
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
while (!pDataInfo->configFileQueue.empty())
|
|
|
|
{
|
|
|
|
std::string configPath = pDataInfo->configFileQueue.front();
|
2013-10-30 09:41:40 +08:00
|
|
|
_getFileMutex.lock();
|
2014-07-01 16:24:59 +08:00
|
|
|
ArmatureDataManager::getInstance()->addSpriteFrameFromFile((pAsyncStruct->baseFilePath + configPath + ".plist").c_str(), (pAsyncStruct->baseFilePath + configPath + ".png").c_str(),pDataInfo->filename.c_str());
|
2013-10-30 09:41:40 +08:00
|
|
|
_getFileMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
pDataInfo->configFileQueue.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-02-20 10:53:49 +08:00
|
|
|
Ref* target = pAsyncStruct->target;
|
2013-09-13 18:07:37 +08:00
|
|
|
SEL_SCHEDULE selector = pAsyncStruct->selector;
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
--_asyncRefCount;
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
if (target && selector)
|
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
(target->*selector)((_asyncRefTotalCount - _asyncRefCount) / (float)_asyncRefTotalCount);
|
2013-09-13 18:07:37 +08:00
|
|
|
target->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
delete pAsyncStruct;
|
|
|
|
delete pDataInfo;
|
|
|
|
|
2013-09-15 20:24:25 +08:00
|
|
|
if (0 == _asyncRefCount)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_asyncRefTotalCount = 0;
|
2014-03-03 11:00:30 +08:00
|
|
|
Director::getInstance()->getScheduler()->unschedule(schedule_selector(DataReaderHelper::addDataAsyncCallBack), this);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-12-23 14:05:46 +08:00
|
|
|
void DataReaderHelper::removeConfigFile(const std::string& configFile)
|
2013-10-31 17:28:14 +08:00
|
|
|
{
|
|
|
|
std::vector<std::string>::iterator it = _configFileList.end();
|
|
|
|
for (std::vector<std::string>::iterator i = _configFileList.begin(); i != _configFileList.end(); i++)
|
|
|
|
{
|
|
|
|
if (*i == configFile)
|
|
|
|
{
|
|
|
|
it = i;
|
|
|
|
}
|
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-10-31 17:28:14 +08:00
|
|
|
if (it != _configFileList.end())
|
|
|
|
{
|
|
|
|
_configFileList.erase(it);
|
|
|
|
}
|
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-24 13:35:46 +08:00
|
|
|
void DataReaderHelper::addDataFromCache(const std::string& pFileContent, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
tinyxml2::XMLDocument document;
|
2013-12-24 13:35:46 +08:00
|
|
|
document.Parse(pFileContent.c_str());
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
tinyxml2::XMLElement *root = document.RootElement();
|
2013-09-16 12:02:57 +08:00
|
|
|
CCASSERT(root, "XML error or XML is empty.");
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
root->QueryFloatAttribute(VERSION, &dataInfo->flashToolVersion);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
/*
|
|
|
|
* Begin decode armature data from xml
|
|
|
|
*/
|
|
|
|
tinyxml2::XMLElement *armaturesXML = root->FirstChildElement(ARMATURES);
|
|
|
|
tinyxml2::XMLElement *armatureXML = armaturesXML->FirstChildElement(ARMATURE);
|
|
|
|
while(armatureXML)
|
|
|
|
{
|
2013-11-05 11:57:20 +08:00
|
|
|
ArmatureData *armatureData = DataReaderHelper::decodeArmature(armatureXML, dataInfo);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-10-31 17:28:14 +08:00
|
|
|
ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData, dataInfo->filename.c_str());
|
2013-09-13 18:07:37 +08:00
|
|
|
armatureData->release();
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
armatureXML = armatureXML->NextSiblingElement(ARMATURE);
|
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
/*
|
|
|
|
* Begin decode animation data from xml
|
|
|
|
*/
|
|
|
|
tinyxml2::XMLElement *animationsXML = root->FirstChildElement(ANIMATIONS);
|
|
|
|
tinyxml2::XMLElement *animationXML = animationsXML->FirstChildElement(ANIMATION);
|
|
|
|
while(animationXML)
|
|
|
|
{
|
2013-11-05 11:57:20 +08:00
|
|
|
AnimationData *animationData = DataReaderHelper::decodeAnimation(animationXML, dataInfo);
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-10-31 17:28:14 +08:00
|
|
|
ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData, dataInfo->filename.c_str());
|
2013-09-13 18:07:37 +08:00
|
|
|
animationData->release();
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
animationXML = animationXML->NextSiblingElement(ANIMATION);
|
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
/*
|
|
|
|
* Begin decode texture data from xml
|
|
|
|
*/
|
|
|
|
tinyxml2::XMLElement *texturesXML = root->FirstChildElement(TEXTURE_ATLAS);
|
|
|
|
tinyxml2::XMLElement *textureXML = texturesXML->FirstChildElement(SUB_TEXTURE);
|
|
|
|
while(textureXML)
|
|
|
|
{
|
2013-11-05 11:57:20 +08:00
|
|
|
TextureData *textureData = DataReaderHelper::decodeTexture(textureXML, dataInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-10-31 17:28:14 +08:00
|
|
|
ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData, dataInfo->filename.c_str());
|
2013-09-13 18:07:37 +08:00
|
|
|
textureData->release();
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
textureXML = textureXML->NextSiblingElement(SUB_TEXTURE);
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
ArmatureData *DataReaderHelper::decodeArmature(tinyxml2::XMLElement *armatureXML, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
ArmatureData *armatureData = new ArmatureData();
|
2013-09-13 18:07:37 +08:00
|
|
|
armatureData->init();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-11-11 12:49:38 +08:00
|
|
|
armatureData->name = armatureXML->Attribute(A_NAME);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
|
|
|
|
tinyxml2::XMLElement *boneXML = armatureXML->FirstChildElement(BONE);
|
|
|
|
|
|
|
|
while( boneXML )
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* If this bone have parent, then get the parent bone xml
|
|
|
|
*/
|
|
|
|
const char *parentName = boneXML->Attribute(A_PARENT);
|
2013-11-05 15:32:13 +08:00
|
|
|
tinyxml2::XMLElement *parentXML = nullptr;
|
2013-06-07 10:52:32 +08:00
|
|
|
if (parentName)
|
|
|
|
{
|
|
|
|
parentXML = armatureXML->FirstChildElement(BONE);
|
2013-11-11 14:50:30 +08:00
|
|
|
std::string parentNameStr = parentName;
|
2013-06-07 10:52:32 +08:00
|
|
|
while (parentXML)
|
|
|
|
{
|
2013-12-24 14:21:25 +08:00
|
|
|
if (parentNameStr == parentXML->Attribute(A_NAME))
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parentXML = parentXML->NextSiblingElement(BONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
BoneData *boneData = decodeBone(boneXML, parentXML, dataInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
armatureData->addBoneData(boneData);
|
2013-09-13 18:07:37 +08:00
|
|
|
boneData->release();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
boneXML = boneXML->NextSiblingElement(BONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return armatureData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
BoneData *DataReaderHelper::decodeBone(tinyxml2::XMLElement *boneXML, tinyxml2::XMLElement *parentXml, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
BoneData *boneData = new BoneData();
|
2013-09-13 18:07:37 +08:00
|
|
|
boneData->init();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
std::string name = boneXML->Attribute(A_NAME);
|
|
|
|
boneData->name = name;
|
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
if( boneXML->Attribute(A_PARENT) != nullptr )
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
boneData->parentName = boneXML->Attribute(A_PARENT);
|
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
boneXML->QueryIntAttribute(A_Z, &boneData->zOrder);
|
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
tinyxml2::XMLElement *displayXML = boneXML->FirstChildElement(DISPLAY);
|
|
|
|
while(displayXML)
|
|
|
|
{
|
2013-11-05 11:57:20 +08:00
|
|
|
DisplayData *displayData = decodeBoneDisplay(displayXML, dataInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
boneData->addDisplayData(displayData);
|
2013-09-13 18:07:37 +08:00
|
|
|
displayData->release();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
displayXML = displayXML->NextSiblingElement(DISPLAY);
|
|
|
|
}
|
|
|
|
|
|
|
|
return boneData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
DisplayData *DataReaderHelper::decodeBoneDisplay(tinyxml2::XMLElement *displayXML, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-06-07 10:52:32 +08:00
|
|
|
int _isArmature = 0;
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
DisplayData *displayData;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
if( displayXML->QueryIntAttribute(A_IS_ARMATURE, &(_isArmature)) == tinyxml2::XML_SUCCESS )
|
|
|
|
{
|
|
|
|
if(!_isArmature)
|
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
displayData = new SpriteDisplayData();
|
2013-06-07 10:52:32 +08:00
|
|
|
displayData->displayType = CS_DISPLAY_SPRITE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
displayData = new ArmatureDisplayData();
|
2013-06-07 10:52:32 +08:00
|
|
|
displayData->displayType = CS_DISPLAY_ARMATURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
displayData = new SpriteDisplayData();
|
2013-06-07 10:52:32 +08:00
|
|
|
displayData->displayType = CS_DISPLAY_SPRITE;
|
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
if(displayXML->Attribute(A_NAME) != nullptr )
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
if(!_isArmature)
|
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
((SpriteDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
((ArmatureDisplayData *)displayData)->displayName = displayXML->Attribute(A_NAME);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return displayData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
AnimationData *DataReaderHelper::decodeAnimation(tinyxml2::XMLElement *animationXML, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
AnimationData *aniData = new AnimationData();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
const char *name = animationXML->Attribute(A_NAME);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-16 15:16:05 +08:00
|
|
|
ArmatureData *armatureData = ArmatureDataManager::getInstance()->getArmatureData(name);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
aniData->name = name;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
tinyxml2::XMLElement *movementXML = animationXML->FirstChildElement(MOVEMENT);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
while( movementXML )
|
|
|
|
{
|
2013-11-05 11:57:20 +08:00
|
|
|
MovementData *movementData = decodeMovement(movementXML, armatureData, dataInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
aniData->addMovement(movementData);
|
2013-09-13 18:07:37 +08:00
|
|
|
movementData->release();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
movementXML = movementXML->NextSiblingElement(MOVEMENT);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
return aniData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
MovementData *DataReaderHelper::decodeMovement(tinyxml2::XMLElement *movementXML, ArmatureData *armatureData, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
MovementData *movementData = new MovementData();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
const char *movName = movementXML->Attribute(A_NAME);
|
2013-06-07 10:52:32 +08:00
|
|
|
movementData->name = movName;
|
|
|
|
|
|
|
|
|
|
|
|
int duration, durationTo, durationTween, loop, tweenEasing = 0;
|
|
|
|
|
|
|
|
if( movementXML->QueryIntAttribute(A_DURATION, &(duration)) == tinyxml2::XML_SUCCESS)
|
|
|
|
{
|
|
|
|
movementData->duration = duration;
|
|
|
|
}
|
|
|
|
if( movementXML->QueryIntAttribute(A_DURATION_TO, &(durationTo)) == tinyxml2::XML_SUCCESS)
|
|
|
|
{
|
|
|
|
movementData->durationTo = durationTo;
|
|
|
|
}
|
|
|
|
if( movementXML->QueryIntAttribute(A_DURATION_TWEEN, &(durationTween)) == tinyxml2::XML_SUCCESS)
|
|
|
|
{
|
|
|
|
movementData->durationTween = durationTween;
|
|
|
|
}
|
|
|
|
if( movementXML->QueryIntAttribute(A_LOOP, &(loop)) == tinyxml2::XML_SUCCESS)
|
|
|
|
{
|
2013-09-23 04:50:54 +08:00
|
|
|
movementData->loop = (loop != 0);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *_easing = movementXML->Attribute(A_TWEEN_EASING);
|
2013-11-05 15:32:13 +08:00
|
|
|
if(_easing != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
std::string str = _easing;
|
2013-12-24 14:21:25 +08:00
|
|
|
if(str != FL_NAN)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
if( movementXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS)
|
|
|
|
{
|
2014-02-17 14:30:17 +08:00
|
|
|
movementData->tweenEasing = tweenEasing == 2 ? cocos2d::tweenfunc::Sine_EaseInOut : (TweenType)tweenEasing;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-17 14:30:17 +08:00
|
|
|
movementData->tweenEasing = cocos2d::tweenfunc::Linear;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tinyxml2::XMLElement *movBoneXml = movementXML->FirstChildElement(BONE);
|
|
|
|
while(movBoneXml)
|
|
|
|
{
|
2013-06-07 14:01:03 +08:00
|
|
|
const char *boneName = movBoneXml->Attribute(A_NAME);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-07 14:01:03 +08:00
|
|
|
if (movementData->getMovementBoneData(boneName))
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
movBoneXml = movBoneXml->NextSiblingElement();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
BoneData *boneData = (BoneData *)armatureData->getBoneData(boneName);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-06-07 14:01:03 +08:00
|
|
|
std::string parentName = boneData->parentName;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
tinyxml2::XMLElement *parentXml = nullptr;
|
2013-06-07 14:01:03 +08:00
|
|
|
if (parentName.length() != 0)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
parentXml = movementXML->FirstChildElement(BONE);
|
|
|
|
|
|
|
|
while (parentXml)
|
|
|
|
{
|
2013-12-24 14:21:25 +08:00
|
|
|
if (parentName == parentXml->Attribute(A_NAME))
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
parentXml = parentXml->NextSiblingElement(BONE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
MovementBoneData *moveBoneData = decodeMovementBone(movBoneXml, parentXml, boneData, dataInfo);
|
2013-09-13 18:07:37 +08:00
|
|
|
movementData->addMovementBoneData(moveBoneData);
|
|
|
|
moveBoneData->release();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
movBoneXml = movBoneXml->NextSiblingElement(BONE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return movementData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
MovementBoneData *DataReaderHelper::decodeMovementBone(tinyxml2::XMLElement *movBoneXml, tinyxml2::XMLElement *parentXml, BoneData *boneData, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
MovementBoneData *movBoneData = new MovementBoneData();
|
2013-09-13 18:07:37 +08:00
|
|
|
movBoneData->init();
|
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
float scale, delay;
|
|
|
|
|
|
|
|
if( movBoneXml )
|
|
|
|
{
|
|
|
|
if( movBoneXml->QueryFloatAttribute(A_MOVEMENT_SCALE, &scale) == tinyxml2::XML_SUCCESS )
|
|
|
|
{
|
|
|
|
movBoneData->scale = scale;
|
|
|
|
}
|
|
|
|
if( movBoneXml->QueryFloatAttribute(A_MOVEMENT_DELAY, &delay) == tinyxml2::XML_SUCCESS )
|
|
|
|
{
|
|
|
|
if(delay > 0)
|
|
|
|
{
|
|
|
|
delay -= 1;
|
|
|
|
}
|
|
|
|
movBoneData->delay = delay;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-17 19:32:16 +08:00
|
|
|
unsigned long length = 0;
|
|
|
|
unsigned long index = 0;
|
2013-06-07 10:52:32 +08:00
|
|
|
int parentTotalDuration = 0;
|
|
|
|
int currentDuration = 0;
|
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
tinyxml2::XMLElement *parentFrameXML = nullptr;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
std::vector<tinyxml2::XMLElement *> parentXmlList;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* get the parent frame xml list, we need get the origin data
|
|
|
|
*/
|
2013-11-05 15:32:13 +08:00
|
|
|
if( parentXml != nullptr )
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
parentFrameXML = parentXml->FirstChildElement(FRAME);
|
|
|
|
while (parentFrameXML)
|
|
|
|
{
|
|
|
|
parentXmlList.push_back(parentFrameXML);
|
|
|
|
parentFrameXML = parentFrameXML->NextSiblingElement(FRAME);
|
|
|
|
}
|
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
parentFrameXML = nullptr;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
length = parentXmlList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int totalDuration = 0;
|
|
|
|
|
|
|
|
std::string name = movBoneXml->Attribute(A_NAME);
|
|
|
|
|
|
|
|
movBoneData->name = name;
|
|
|
|
|
|
|
|
tinyxml2::XMLElement *frameXML = movBoneXml->FirstChildElement(FRAME);
|
|
|
|
|
|
|
|
while( frameXML )
|
|
|
|
{
|
|
|
|
if(parentXml)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* in this loop we get the corresponding parent frame xml
|
|
|
|
*/
|
2013-11-11 14:50:30 +08:00
|
|
|
while(index < length && (parentFrameXML ? (totalDuration < parentTotalDuration || totalDuration >= parentTotalDuration + currentDuration) : true))
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-11-11 14:50:30 +08:00
|
|
|
parentFrameXML = parentXmlList[index];
|
2013-06-07 10:52:32 +08:00
|
|
|
parentTotalDuration += currentDuration;
|
|
|
|
parentFrameXML->QueryIntAttribute(A_DURATION, ¤tDuration);
|
2013-11-11 14:50:30 +08:00
|
|
|
index++;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
FrameData *frameData = decodeFrame( frameXML, parentFrameXML, boneData, dataInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
movBoneData->addFrameData(frameData);
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->release();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->frameID = totalDuration;
|
2013-06-07 10:52:32 +08:00
|
|
|
totalDuration += frameData->duration;
|
2013-09-13 18:07:37 +08:00
|
|
|
movBoneData->duration = totalDuration;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
frameXML = frameXML->NextSiblingElement(FRAME);
|
|
|
|
}
|
|
|
|
|
2013-12-13 19:40:38 +08:00
|
|
|
|
2013-09-17 16:40:47 +08:00
|
|
|
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
|
2013-12-18 22:36:10 +08:00
|
|
|
auto frames = movBoneData->frameList;
|
2013-12-17 19:32:16 +08:00
|
|
|
for (long j = movBoneData->frameList.size() - 1; j >= 0; j--)
|
2013-09-17 16:40:47 +08:00
|
|
|
{
|
2013-11-11 12:49:38 +08:00
|
|
|
if (j > 0)
|
2013-09-17 16:40:47 +08:00
|
|
|
{
|
2013-12-13 19:40:38 +08:00
|
|
|
float difSkewX = frames.at(j)->skewX - frames.at(j-1)->skewX;
|
|
|
|
float difSkewY = frames.at(j)->skewY - frames.at(j-1)->skewY;
|
2013-09-17 16:40:47 +08:00
|
|
|
|
|
|
|
if (difSkewX < -M_PI || difSkewX > M_PI)
|
|
|
|
{
|
2013-12-13 19:40:38 +08:00
|
|
|
frames.at(j-1)->skewX = difSkewX < 0 ? frames.at(j-1)->skewX - 2 * M_PI : frames.at(j-1)->skewX + 2 * M_PI;
|
2013-09-17 16:40:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (difSkewY < -M_PI || difSkewY > M_PI)
|
|
|
|
{
|
2013-12-13 19:40:38 +08:00
|
|
|
frames.at(j-1)->skewY = difSkewY < 0 ? frames.at(j-1)->skewY - 2 * M_PI : frames.at(j-1)->skewY + 2 * M_PI;
|
2013-09-17 16:40:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
//
|
2013-09-15 19:08:45 +08:00
|
|
|
FrameData *frameData = new FrameData();
|
2013-12-13 19:40:38 +08:00
|
|
|
frameData->copy((FrameData *)movBoneData->frameList.back());
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->frameID = movBoneData->duration;
|
|
|
|
movBoneData->addFrameData(frameData);
|
|
|
|
frameData->release();
|
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
return movBoneData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
FrameData *DataReaderHelper::decodeFrame(tinyxml2::XMLElement *frameXML, tinyxml2::XMLElement *parentFrameXml, BoneData *boneData, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-12-19 21:12:25 +08:00
|
|
|
float x = 0, y = 0, scale_x = 0, scale_y = 0, skew_x = 0, skew_y = 0, tweenRotate = 0;
|
|
|
|
int duration = 0, displayIndex = 0, zOrder = 0, tweenEasing = 0, blendType = 0;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
FrameData *frameData = new FrameData();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
if(frameXML->Attribute(A_MOVEMENT) != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->strMovement = frameXML->Attribute(A_MOVEMENT);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-11-05 15:32:13 +08:00
|
|
|
if(frameXML->Attribute(A_EVENT) != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->strEvent = frameXML->Attribute(A_EVENT);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-11-05 15:32:13 +08:00
|
|
|
if(frameXML->Attribute(A_SOUND) != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->strSound = frameXML->Attribute(A_SOUND);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-11-05 15:32:13 +08:00
|
|
|
if(frameXML->Attribute(A_SOUND_EFFECT) != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->strSoundEffect = frameXML->Attribute(A_SOUND_EFFECT);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
2013-12-13 15:02:09 +08:00
|
|
|
bool tweenFrame = false;
|
|
|
|
if (frameXML->QueryBoolAttribute(A_TWEEN_FRAME, &tweenFrame) == tinyxml2::XML_SUCCESS)
|
|
|
|
{
|
|
|
|
frameData->isTween = tweenFrame;
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
if (dataInfo->flashToolVersion >= VERSION_2_0)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
if(frameXML->QueryFloatAttribute(A_COCOS2DX_X, &x) == tinyxml2::XML_SUCCESS)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->x = x;
|
2013-06-07 10:52:32 +08:00
|
|
|
frameData->x *= s_PositionReadScale;
|
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
if(frameXML->QueryFloatAttribute(A_COCOS2DX_Y, &y) == tinyxml2::XML_SUCCESS)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->y = -y;
|
2013-06-07 10:52:32 +08:00
|
|
|
frameData->y *= s_PositionReadScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
if(frameXML->QueryFloatAttribute(A_X, &x) == tinyxml2::XML_SUCCESS)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->x = x;
|
2013-06-07 10:52:32 +08:00
|
|
|
frameData->x *= s_PositionReadScale;
|
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
if(frameXML->QueryFloatAttribute(A_Y, &y) == tinyxml2::XML_SUCCESS)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->y = -y;
|
2013-06-07 10:52:32 +08:00
|
|
|
frameData->y *= s_PositionReadScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
if( frameXML->QueryFloatAttribute(A_SCALE_X, &scale_x) == tinyxml2::XML_SUCCESS )
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->scaleX = scale_x;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
if( frameXML->QueryFloatAttribute(A_SCALE_Y, &scale_y) == tinyxml2::XML_SUCCESS )
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->scaleY = scale_y;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
if( frameXML->QueryFloatAttribute(A_SKEW_X, &skew_x) == tinyxml2::XML_SUCCESS )
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->skewX = CC_DEGREES_TO_RADIANS(skew_x);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
if( frameXML->QueryFloatAttribute(A_SKEW_Y, &skew_y) == tinyxml2::XML_SUCCESS )
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->skewY = CC_DEGREES_TO_RADIANS(-skew_y);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
if( frameXML->QueryIntAttribute(A_DURATION, &duration) == tinyxml2::XML_SUCCESS )
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->duration = duration;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
if( frameXML->QueryIntAttribute(A_DISPLAY_INDEX, &displayIndex) == tinyxml2::XML_SUCCESS )
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->displayIndex = displayIndex;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
if( frameXML->QueryIntAttribute(A_Z, &zOrder) == tinyxml2::XML_SUCCESS )
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->zOrder = zOrder;
|
|
|
|
}
|
2013-12-19 21:12:25 +08:00
|
|
|
if( frameXML->QueryFloatAttribute(A_TWEEN_ROTATE, &tweenRotate) == tinyxml2::XML_SUCCESS )
|
|
|
|
{
|
|
|
|
frameData->tweenRotate = tweenRotate;
|
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
if ( frameXML->QueryIntAttribute(A_BLEND_TYPE, &blendType) == tinyxml2::XML_SUCCESS )
|
|
|
|
{
|
2013-12-13 15:02:09 +08:00
|
|
|
switch (blendType)
|
|
|
|
{
|
|
|
|
case BLEND_NORMAL:
|
|
|
|
{
|
|
|
|
frameData->blendFunc = BlendFunc::ALPHA_NON_PREMULTIPLIED;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BLEND_ADD:
|
|
|
|
{
|
|
|
|
frameData->blendFunc.src = GL_SRC_ALPHA;
|
|
|
|
frameData->blendFunc.dst = GL_ONE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BLEND_MULTIPLY:
|
|
|
|
{
|
|
|
|
frameData->blendFunc.src = GL_DST_COLOR;
|
|
|
|
frameData->blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BLEND_SCREEN:
|
|
|
|
{
|
|
|
|
frameData->blendFunc.src = GL_ONE;
|
|
|
|
frameData->blendFunc.dst = GL_ONE_MINUS_SRC_COLOR;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
frameData->blendFunc.src = CC_BLEND_SRC;
|
|
|
|
frameData->blendFunc.dst = CC_BLEND_DST;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
tinyxml2::XMLElement *colorTransformXML = frameXML->FirstChildElement(A_COLOR_TRANSFORM);
|
|
|
|
if (colorTransformXML)
|
|
|
|
{
|
|
|
|
int alpha, red, green, blue = 100;
|
|
|
|
int alphaOffset, redOffset, greenOffset, blueOffset = 0;
|
|
|
|
|
|
|
|
colorTransformXML->QueryIntAttribute(A_ALPHA, &alpha);
|
|
|
|
colorTransformXML->QueryIntAttribute(A_RED, &red);
|
|
|
|
colorTransformXML->QueryIntAttribute(A_GREEN, &green);
|
|
|
|
colorTransformXML->QueryIntAttribute(A_BLUE, &blue) ;
|
|
|
|
|
|
|
|
colorTransformXML->QueryIntAttribute(A_ALPHA_OFFSET, &alphaOffset);
|
|
|
|
colorTransformXML->QueryIntAttribute(A_RED_OFFSET, &redOffset);
|
|
|
|
colorTransformXML->QueryIntAttribute(A_GREEN_OFFSET, &greenOffset);
|
|
|
|
colorTransformXML->QueryIntAttribute(A_BLUE_OFFSET, &blueOffset) ;
|
|
|
|
|
|
|
|
frameData->a = 2.55 * alphaOffset + alpha;
|
|
|
|
frameData->r = 2.55 * redOffset + red;
|
|
|
|
frameData->g = 2.55 * greenOffset + green;
|
|
|
|
frameData->b = 2.55 * blueOffset + blue;
|
|
|
|
|
|
|
|
frameData->isUseColorInfo = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const char *_easing = frameXML->Attribute(A_TWEEN_EASING);
|
2013-11-05 15:32:13 +08:00
|
|
|
if(_easing != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
std::string str = _easing;
|
2013-12-24 14:21:25 +08:00
|
|
|
if(str != FL_NAN)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
if( frameXML->QueryIntAttribute(A_TWEEN_EASING, &(tweenEasing)) == tinyxml2::XML_SUCCESS)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2014-02-17 14:30:17 +08:00
|
|
|
frameData->tweenEasing = tweenEasing == 2 ? cocos2d::tweenfunc::Sine_EaseInOut : (cocos2d::tweenfunc::TweenType)tweenEasing;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-17 14:30:17 +08:00
|
|
|
frameData->tweenEasing = cocos2d::tweenfunc::Linear;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(parentFrameXml)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* recalculate frame data from parent frame data, use for translate matrix
|
|
|
|
*/
|
2013-09-15 19:08:45 +08:00
|
|
|
BaseData helpNode;
|
2013-11-05 11:57:20 +08:00
|
|
|
if (dataInfo->flashToolVersion >= VERSION_2_0)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
parentFrameXml->QueryFloatAttribute(A_COCOS2DX_X, &helpNode.x);
|
|
|
|
parentFrameXml->QueryFloatAttribute(A_COCOS2DX_Y, &helpNode.y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
parentFrameXml->QueryFloatAttribute(A_X, &helpNode.x);
|
|
|
|
parentFrameXml->QueryFloatAttribute(A_Y, &helpNode.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
parentFrameXml->QueryFloatAttribute(A_SKEW_X, &helpNode.skewX);
|
|
|
|
parentFrameXml->QueryFloatAttribute(A_SKEW_Y, &helpNode.skewY);
|
|
|
|
|
|
|
|
helpNode.y = -helpNode.y;
|
|
|
|
helpNode.skewX = CC_DEGREES_TO_RADIANS(helpNode.skewX);
|
|
|
|
helpNode.skewY = CC_DEGREES_TO_RADIANS(-helpNode.skewY);
|
|
|
|
|
2013-09-15 19:08:45 +08:00
|
|
|
TransformHelp::transformFromParent(*frameData, helpNode);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
return frameData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
TextureData *DataReaderHelper::decodeTexture(tinyxml2::XMLElement *textureXML, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
TextureData *textureData = new TextureData();
|
2013-09-13 18:07:37 +08:00
|
|
|
textureData->init();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
if( textureXML->Attribute(A_NAME) != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
textureData->name = textureXML->Attribute(A_NAME);
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
float px, py, width, height = 0;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
if(dataInfo->flashToolVersion >= VERSION_2_0)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
textureXML->QueryFloatAttribute(A_COCOS2D_PIVOT_X, &px);
|
|
|
|
textureXML->QueryFloatAttribute(A_COCOS2D_PIVOT_Y, &py);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
textureXML->QueryFloatAttribute(A_PIVOT_X, &px);
|
|
|
|
textureXML->QueryFloatAttribute(A_PIVOT_Y, &py);
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
textureXML->QueryFloatAttribute(A_WIDTH, &width);
|
|
|
|
textureXML->QueryFloatAttribute(A_HEIGHT, &height);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
float anchorPointX = px / width;
|
|
|
|
float anchorPointY = (height - py) / height;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
textureData->pivotX = anchorPointX;
|
|
|
|
textureData->pivotY = anchorPointY;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
tinyxml2::XMLElement *contourXML = textureXML->FirstChildElement(CONTOUR);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
while (contourXML)
|
|
|
|
{
|
2013-11-05 11:57:20 +08:00
|
|
|
ContourData *contourData = decodeContour(contourXML, dataInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
textureData->addContourData(contourData);
|
2013-09-13 18:07:37 +08:00
|
|
|
contourData->release();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
contourXML = contourXML->NextSiblingElement(CONTOUR);
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
return textureData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
ContourData *DataReaderHelper::decodeContour(tinyxml2::XMLElement *contourXML, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
ContourData *contourData = new ContourData();
|
2013-09-13 18:07:37 +08:00
|
|
|
contourData->init();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
tinyxml2::XMLElement *vertexDataXML = contourXML->FirstChildElement(CONTOUR_VERTEX);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
while (vertexDataXML)
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 vertex;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-13 19:40:38 +08:00
|
|
|
vertexDataXML->QueryFloatAttribute(A_X, &vertex.x);
|
|
|
|
vertexDataXML->QueryFloatAttribute(A_Y, &vertex.y);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-13 19:40:38 +08:00
|
|
|
vertex.y = -vertex.y;
|
|
|
|
contourData->vertexList.push_back(vertex);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
vertexDataXML = vertexDataXML->NextSiblingElement(CONTOUR_VERTEX);
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
return contourData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-12-24 13:35:46 +08:00
|
|
|
void DataReaderHelper::addDataFromJsonCache(const std::string& fileContent, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
rapidjson::Document json;
|
2014-05-31 06:06:56 +08:00
|
|
|
rapidjson::StringStream stream(fileContent.c_str());
|
|
|
|
|
|
|
|
if (fileContent.size() >= 3) {
|
|
|
|
// Skip BOM if exists
|
|
|
|
const unsigned char* c = (const unsigned char *)fileContent.c_str();
|
|
|
|
unsigned bom = c[0] | (c[1] << 8) | (c[2] << 16);
|
|
|
|
|
|
|
|
if (bom == 0xBFBBEF) // UTF8 BOM
|
|
|
|
{
|
|
|
|
stream.Take();
|
|
|
|
stream.Take();
|
|
|
|
stream.Take();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
json.ParseStream<0>(stream);
|
2013-12-24 20:33:55 +08:00
|
|
|
if (json.HasParseError()) {
|
|
|
|
CCLOG("GetParseError %s\n",json.GetParseError());
|
|
|
|
}
|
|
|
|
|
|
|
|
dataInfo->contentScale = DICTOOL->getFloatValue_json(json, CONTENT_SCALE, 1.0f);
|
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
// Decode armatures
|
2013-12-24 20:33:55 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, ARMATURE_DATA);
|
|
|
|
for (int i = 0; i < length; i++)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &armatureDic = DICTOOL->getSubDictionary_json(json, ARMATURE_DATA, i);
|
|
|
|
ArmatureData *armatureData = decodeArmature(armatureDic, dataInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2014-07-01 16:24:59 +08:00
|
|
|
ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData, dataInfo->filename.c_str());
|
2013-09-13 18:07:37 +08:00
|
|
|
armatureData->release();
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decode animations
|
2013-12-24 20:33:55 +08:00
|
|
|
length = DICTOOL->getArrayCount_json(json, ANIMATION_DATA); //json[ANIMATION_DATA].IsNull() ? 0 : json[ANIMATION_DATA].Size();
|
2013-06-07 10:52:32 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &animationDic = DICTOOL->getSubDictionary_json(json, ANIMATION_DATA, i);
|
|
|
|
AnimationData *animationData = decodeAnimation(animationDic, dataInfo);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2014-07-01 16:24:59 +08:00
|
|
|
ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData, dataInfo->filename.c_str());
|
2013-09-13 18:07:37 +08:00
|
|
|
animationData->release();
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Decode textures
|
2013-12-24 20:33:55 +08:00
|
|
|
length = DICTOOL->getArrayCount_json(json, TEXTURE_DATA);
|
2013-06-07 10:52:32 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &textureDic = DICTOOL->getSubDictionary_json(json, TEXTURE_DATA, i);
|
|
|
|
TextureData *textureData = decodeTexture(textureDic);
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2014-07-01 16:24:59 +08:00
|
|
|
ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData, dataInfo->filename.c_str());
|
2013-09-13 18:07:37 +08:00
|
|
|
textureData->release();
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 20:24:25 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-09-13 18:07:37 +08:00
|
|
|
|
|
|
|
// Auto load sprite file
|
2013-11-05 15:32:13 +08:00
|
|
|
bool autoLoad = dataInfo->asyncStruct == nullptr ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile;
|
2013-09-13 18:07:37 +08:00
|
|
|
if (autoLoad)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
length = DICTOOL->getArrayCount_json(json, CONFIG_FILE_PATH); // json[CONFIG_FILE_PATH].IsNull() ? 0 : json[CONFIG_FILE_PATH].Size();
|
2013-09-13 18:07:37 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *path = DICTOOL->getStringValueFromArray_json(json, CONFIG_FILE_PATH, i); // json[CONFIG_FILE_PATH][i].IsNull() ? NULL : json[CONFIG_FILE_PATH][i].GetString();
|
2013-11-05 15:32:13 +08:00
|
|
|
if (path == nullptr)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
|
|
|
CCLOG("load CONFIG_FILE_PATH error.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string filePath = path;
|
|
|
|
filePath = filePath.erase(filePath.find_last_of("."));
|
|
|
|
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
|
|
|
dataInfo->configFileQueue.push(filePath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string plistPath = filePath + ".plist";
|
|
|
|
std::string pngPath = filePath + ".png";
|
|
|
|
|
2014-07-01 16:24:59 +08:00
|
|
|
ArmatureDataManager::getInstance()->addSpriteFrameFromFile((dataInfo->baseFilePath + plistPath).c_str(), (dataInfo->baseFilePath + pngPath).c_str(), dataInfo->filename.c_str());
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
ArmatureData *DataReaderHelper::decodeArmature(const rapidjson::Value& json, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
ArmatureData *armatureData = new ArmatureData();
|
2013-09-13 18:07:37 +08:00
|
|
|
armatureData->init();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *name = DICTOOL->getStringValue_json(json, A_NAME);
|
2013-11-05 15:32:13 +08:00
|
|
|
if(name != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
armatureData->name = name;
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
dataInfo->cocoStudioVersion = armatureData->dataVersion = DICTOOL->getFloatValue_json(json, VERSION, 0.1f);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, BONE_DATA, 0);
|
2013-06-07 10:52:32 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &dic = DICTOOL->getSubDictionary_json(json, BONE_DATA, i); //json[BONE_DATA][i];
|
|
|
|
BoneData *boneData = decodeBone(dic, dataInfo);
|
2013-09-13 18:07:37 +08:00
|
|
|
armatureData->addBoneData(boneData);
|
|
|
|
boneData->release();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
return armatureData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
BoneData *DataReaderHelper::decodeBone(const rapidjson::Value& json, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
BoneData *boneData = new BoneData();
|
2013-09-13 18:07:37 +08:00
|
|
|
boneData->init();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-10-30 09:41:40 +08:00
|
|
|
decodeNode(boneData, json, dataInfo);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *str = DICTOOL->getStringValue_json(json, A_NAME);
|
2013-11-05 15:32:13 +08:00
|
|
|
if(str != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
boneData->name = str;
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
str = DICTOOL->getStringValue_json(json, A_PARENT);
|
2013-11-05 15:32:13 +08:00
|
|
|
if(str != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
boneData->parentName = str;
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, DISPLAY_DATA);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &dic = DICTOOL->getSubDictionary_json(json, DISPLAY_DATA, i);
|
|
|
|
DisplayData *displayData = decodeBoneDisplay(dic, dataInfo);
|
2013-09-13 18:07:37 +08:00
|
|
|
boneData->addDisplayData(displayData);
|
|
|
|
displayData->release();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
return boneData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
DisplayData *DataReaderHelper::decodeBoneDisplay(const rapidjson::Value& json, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
DisplayType displayType = (DisplayType)(DICTOOL->getIntValue_json(json, A_DISPLAY_TYPE, CS_DISPLAY_SPRITE));
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-11-05 15:32:13 +08:00
|
|
|
DisplayData *displayData = nullptr;
|
2013-06-07 10:52:32 +08:00
|
|
|
|
|
|
|
switch (displayType)
|
|
|
|
{
|
|
|
|
case CS_DISPLAY_SPRITE:
|
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
displayData = new SpriteDisplayData();
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *name = DICTOOL->getStringValue_json(json, A_NAME);
|
2014-06-23 10:12:54 +08:00
|
|
|
if(name != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-12-25 19:46:09 +08:00
|
|
|
((SpriteDisplayData *)displayData)->displayName = name;
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &dicArray = DICTOOL->getSubDictionary_json(json, SKIN_DATA);
|
|
|
|
if(!dicArray.IsNull())
|
|
|
|
{
|
|
|
|
rapidjson::SizeType index = 0;
|
|
|
|
const rapidjson::Value &dic = DICTOOL->getSubDictionary_json(dicArray, index);
|
|
|
|
if (!dic.IsNull())
|
|
|
|
{
|
|
|
|
SpriteDisplayData *sdd = (SpriteDisplayData *)displayData;
|
|
|
|
sdd->skinData.x = DICTOOL->getFloatValue_json(dic, A_X) * s_PositionReadScale;
|
|
|
|
sdd->skinData.y = DICTOOL->getFloatValue_json(dic, A_Y) * s_PositionReadScale;
|
|
|
|
sdd->skinData.scaleX = DICTOOL->getFloatValue_json(dic, A_SCALE_X, 1.0f);
|
|
|
|
sdd->skinData.scaleY = DICTOOL->getFloatValue_json(dic, A_SCALE_Y, 1.0f);
|
|
|
|
sdd->skinData.skewX = DICTOOL->getFloatValue_json(dic, A_SKEW_X, 1.0f);
|
|
|
|
sdd->skinData.skewY = DICTOOL->getFloatValue_json(dic, A_SKEW_Y, 1.0f);
|
|
|
|
|
|
|
|
sdd->skinData.x *= dataInfo->contentScale;
|
|
|
|
sdd->skinData.y *= dataInfo->contentScale;
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case CS_DISPLAY_ARMATURE:
|
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
displayData = new ArmatureDisplayData();
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *name = DICTOOL->getStringValue_json(json, A_NAME);
|
2013-11-05 15:32:13 +08:00
|
|
|
if(name != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
((ArmatureDisplayData *)displayData)->displayName = name;
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CS_DISPLAY_PARTICLE:
|
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
displayData = new ParticleDisplayData();
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *plist = DICTOOL->getStringValue_json(json, A_PLIST);
|
2013-11-05 15:32:13 +08:00
|
|
|
if(plist != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-10-31 17:28:14 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
2013-10-30 09:41:40 +08:00
|
|
|
{
|
2013-12-06 13:40:49 +08:00
|
|
|
static_cast<ParticleDisplayData *>(displayData)->displayName = dataInfo->asyncStruct->baseFilePath + plist;
|
2013-10-30 09:41:40 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-06 13:40:49 +08:00
|
|
|
static_cast<ParticleDisplayData *>(displayData)->displayName = dataInfo->baseFilePath + plist;
|
2013-10-30 09:41:40 +08:00
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2013-09-15 19:08:45 +08:00
|
|
|
displayData = new SpriteDisplayData();
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
displayData->displayType = displayType;
|
|
|
|
|
|
|
|
return displayData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
AnimationData *DataReaderHelper::decodeAnimation(const rapidjson::Value& json, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
AnimationData *aniData = new AnimationData();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *name = DICTOOL->getStringValue_json(json, A_NAME);
|
2013-11-05 15:32:13 +08:00
|
|
|
if(name != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
aniData->name = name;
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, MOVEMENT_DATA);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &dic = DICTOOL->getSubDictionary_json(json, MOVEMENT_DATA, i);
|
|
|
|
MovementData *movementData = decodeMovement(dic, dataInfo);
|
2013-09-13 18:07:37 +08:00
|
|
|
aniData->addMovement(movementData);
|
|
|
|
movementData->release();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
return aniData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
MovementData *DataReaderHelper::decodeMovement(const rapidjson::Value& json, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
MovementData *movementData = new MovementData();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
movementData->loop = DICTOOL->getBooleanValue_json(json, A_LOOP, true);
|
|
|
|
movementData->durationTween = DICTOOL->getIntValue_json(json, A_DURATION_TWEEN, 0);
|
|
|
|
movementData->durationTo = DICTOOL->getIntValue_json(json, A_DURATION_TO, 0);
|
|
|
|
movementData->duration = DICTOOL->getIntValue_json(json, A_DURATION, 0);
|
|
|
|
if (!DICTOOL->checkObjectExist_json(json, A_DURATION))
|
|
|
|
{
|
|
|
|
movementData->scale = 1.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
movementData->scale = DICTOOL->getFloatValue_json(json, A_MOVEMENT_SCALE, 1.0f);
|
|
|
|
}
|
2014-02-17 14:30:17 +08:00
|
|
|
movementData->tweenEasing = (TweenType)(DICTOOL->getIntValue_json(json, A_TWEEN_EASING, cocos2d::tweenfunc::Linear));
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *name = DICTOOL->getStringValue_json(json, A_NAME);
|
2013-11-05 15:32:13 +08:00
|
|
|
if(name != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
movementData->name = name;
|
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, MOVEMENT_BONE_DATA);
|
2013-06-07 10:52:32 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &dic = DICTOOL->getSubDictionary_json(json, MOVEMENT_BONE_DATA, i);
|
|
|
|
MovementBoneData *movementBoneData = decodeMovementBone(dic, dataInfo);
|
2013-09-13 18:07:37 +08:00
|
|
|
movementData->addMovementBoneData(movementBoneData);
|
|
|
|
movementBoneData->release();
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return movementData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
MovementBoneData *DataReaderHelper::decodeMovementBone(const rapidjson::Value& json, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
MovementBoneData *movementBoneData = new MovementBoneData();
|
2013-09-13 18:07:37 +08:00
|
|
|
movementBoneData->init();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
movementBoneData->delay = DICTOOL->getFloatValue_json(json, A_MOVEMENT_DELAY);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *name = DICTOOL->getStringValue_json(json, A_NAME);
|
2013-11-05 15:32:13 +08:00
|
|
|
if(name != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
movementBoneData->name = name;
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
rapidjson::SizeType length = DICTOOL->getArrayCount_json(json, FRAME_DATA);
|
|
|
|
for (rapidjson::SizeType i = 0; i < length; i++)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &dic = DICTOOL->getSubDictionary_json(json, FRAME_DATA, i);
|
|
|
|
FrameData *frameData = decodeFrame(dic, dataInfo);
|
2013-09-13 18:07:37 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
movementBoneData->addFrameData(frameData);
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->release();
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
|
|
|
frameData->frameID = movementBoneData->duration;
|
|
|
|
movementBoneData->duration += frameData->duration;
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-09-17 16:40:47 +08:00
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE)
|
2013-09-17 16:40:47 +08:00
|
|
|
{
|
|
|
|
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
|
2013-12-18 22:36:10 +08:00
|
|
|
auto frames = movementBoneData->frameList;
|
2013-12-17 19:32:16 +08:00
|
|
|
for (long i = frames.size() - 1; i >= 0; i--)
|
2013-09-17 16:40:47 +08:00
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
{
|
2013-12-13 19:40:38 +08:00
|
|
|
float difSkewX = frames.at(i)->skewX - frames.at(i-1)->skewX;
|
|
|
|
float difSkewY = frames.at(i)->skewY - frames.at(i-1)->skewY;
|
2013-09-17 16:40:47 +08:00
|
|
|
|
|
|
|
if (difSkewX < -M_PI || difSkewX > M_PI)
|
|
|
|
{
|
2013-12-13 19:40:38 +08:00
|
|
|
frames.at(i-1)->skewX = difSkewX < 0 ? frames.at(i-1)->skewX - 2 * M_PI : frames.at(i-1)->skewX + 2 * M_PI;
|
2013-09-17 16:40:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (difSkewY < -M_PI || difSkewY > M_PI)
|
|
|
|
{
|
2013-12-13 19:40:38 +08:00
|
|
|
frames.at(i-1)->skewY = difSkewY < 0 ? frames.at(i-1)->skewY - 2 * M_PI : frames.at(i-1)->skewY + 2 * M_PI;
|
2013-09-17 16:40:47 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-12-13 19:40:38 +08:00
|
|
|
if (movementBoneData->frameList.size() > 0)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
FrameData *frameData = new FrameData();
|
2013-12-13 19:40:38 +08:00
|
|
|
frameData->copy((FrameData *)movementBoneData->frameList.back());
|
2013-09-13 18:07:37 +08:00
|
|
|
movementBoneData->addFrameData(frameData);
|
|
|
|
frameData->release();
|
|
|
|
|
|
|
|
frameData->frameID = movementBoneData->duration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
return movementBoneData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
FrameData *DataReaderHelper::decodeFrame(const rapidjson::Value& json, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
FrameData *frameData = new FrameData();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-10-30 09:41:40 +08:00
|
|
|
decodeNode(frameData, json, dataInfo);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2014-02-17 14:30:17 +08:00
|
|
|
frameData->tweenEasing = (TweenType)(DICTOOL->getIntValue_json(json, A_TWEEN_EASING, cocos2d::tweenfunc::Linear));
|
2013-12-24 20:33:55 +08:00
|
|
|
frameData->displayIndex = DICTOOL->getIntValue_json(json, A_DISPLAY_INDEX);
|
|
|
|
frameData->blendFunc.src = (GLenum)(DICTOOL->getIntValue_json(json, A_BLEND_SRC, BlendFunc::ALPHA_NON_PREMULTIPLIED.src));
|
|
|
|
frameData->blendFunc.dst = (GLenum)(DICTOOL->getIntValue_json(json, A_BLEND_DST, BlendFunc::ALPHA_NON_PREMULTIPLIED.dst));
|
|
|
|
frameData->isTween = DICTOOL->getBooleanValue_json(json, A_TWEEN_FRAME, true);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *event = DICTOOL->getStringValue_json(json, A_EVENT);
|
2013-11-05 15:32:13 +08:00
|
|
|
if (event != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
2013-09-13 18:07:37 +08:00
|
|
|
frameData->strEvent = event;
|
|
|
|
}
|
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
2013-09-13 18:07:37 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
frameData->duration = DICTOOL->getIntValue_json(json, A_DURATION, 1);
|
2013-09-13 18:07:37 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
frameData->frameID = DICTOOL->getIntValue_json(json, A_FRAME_INDEX);
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-13 15:02:09 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, A_EASING_PARAM);
|
2013-12-13 15:02:09 +08:00
|
|
|
if (length != 0)
|
|
|
|
{
|
|
|
|
frameData->easingParams = new float[length];
|
|
|
|
|
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
frameData->easingParams[i] = DICTOOL->getFloatValueFromArray_json(json, A_EASING_PARAM, i);
|
2013-12-13 15:02:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
return frameData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
TextureData *DataReaderHelper::decodeTexture(const rapidjson::Value& json)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
TextureData *textureData = new TextureData();
|
2013-09-13 18:07:37 +08:00
|
|
|
textureData->init();
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
const char *name = DICTOOL->getStringValue_json(json, A_NAME);
|
2013-11-05 15:32:13 +08:00
|
|
|
if(name != nullptr)
|
2013-06-07 10:52:32 +08:00
|
|
|
{
|
|
|
|
textureData->name = name;
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
textureData->width = DICTOOL->getFloatValue_json(json, A_WIDTH);
|
|
|
|
textureData->height = DICTOOL->getFloatValue_json(json, A_HEIGHT);
|
|
|
|
textureData->pivotX = DICTOOL->getFloatValue_json(json, A_PIVOT_X);
|
|
|
|
textureData->pivotY = DICTOOL->getFloatValue_json(json, A_PIVOT_Y);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, CONTOUR_DATA);
|
2013-06-07 10:52:32 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &dic = DICTOOL->getSubDictionary_json(json, CONTOUR_DATA, i);
|
|
|
|
ContourData *contourData = decodeContour(dic);
|
2013-12-13 19:40:38 +08:00
|
|
|
textureData->contourDataList.pushBack(contourData);
|
2013-09-13 18:07:37 +08:00
|
|
|
contourData->release();
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
return textureData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-12-25 19:46:09 +08:00
|
|
|
ContourData *DataReaderHelper::decodeContour(const rapidjson::Value& json)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-09-15 19:08:45 +08:00
|
|
|
ContourData *contourData = new ContourData();
|
2013-09-13 18:07:37 +08:00
|
|
|
contourData->init();
|
2013-06-07 10:52:32 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, VERTEX_POINT);
|
2013-06-07 10:52:32 +08:00
|
|
|
for (int i = length - 1; i >= 0; i--)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
const rapidjson::Value &dic = DICTOOL->getSubDictionary_json(json, VERTEX_POINT, i);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 vertex;
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
vertex.x = DICTOOL->getFloatValue_json(dic, A_X);
|
|
|
|
vertex.y = DICTOOL->getFloatValue_json(dic, A_Y);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-13 19:40:38 +08:00
|
|
|
contourData->vertexList.push_back(vertex);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-06-07 10:52:32 +08:00
|
|
|
return contourData;
|
2013-06-06 12:02:54 +08:00
|
|
|
}
|
|
|
|
|
2013-12-25 19:46:09 +08:00
|
|
|
void DataReaderHelper::decodeNode(BaseData *node, const rapidjson::Value& json, DataInfo *dataInfo)
|
2013-06-06 12:02:54 +08:00
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
node->x = DICTOOL->getFloatValue_json(json, A_X) * s_PositionReadScale;
|
|
|
|
node->y = DICTOOL->getFloatValue_json(json, A_Y) * s_PositionReadScale;
|
2013-10-30 09:41:40 +08:00
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
node->x *= dataInfo->contentScale;
|
|
|
|
node->y *= dataInfo->contentScale;
|
2013-10-30 09:41:40 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
node->zOrder = DICTOOL->getIntValue_json(json, A_Z);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
node->skewX = DICTOOL->getFloatValue_json(json, A_SKEW_X);
|
|
|
|
node->skewY = DICTOOL->getFloatValue_json(json, A_SKEW_Y);
|
|
|
|
node->scaleX = DICTOOL->getFloatValue_json(json, A_SCALE_X, 1.0f);
|
|
|
|
node->scaleY = DICTOOL->getFloatValue_json(json, A_SCALE_Y, 1.0f);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-11-05 11:57:20 +08:00
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COLOR_READING)
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
if (DICTOOL->checkObjectExist_json(json, 0))
|
|
|
|
{
|
|
|
|
const rapidjson::Value &colorDic = DICTOOL->getSubDictionary_json(json, 0);
|
|
|
|
node->a = DICTOOL->getIntValue_json(colorDic, A_ALPHA, 255);
|
|
|
|
node->r = DICTOOL->getIntValue_json(colorDic, A_RED, 255);
|
|
|
|
node->g = DICTOOL->getIntValue_json(colorDic, A_GREEN, 255);
|
|
|
|
node->b = DICTOOL->getIntValue_json(colorDic, A_BLUE, 255);
|
|
|
|
|
|
|
|
node->isUseColorInfo = true;
|
|
|
|
}
|
2013-11-05 11:57:20 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-24 20:33:55 +08:00
|
|
|
if (DICTOOL->checkObjectExist_json(json, COLOR_INFO))
|
|
|
|
{
|
|
|
|
const rapidjson::Value &colorDic = DICTOOL->getSubDictionary_json(json, COLOR_INFO); //json.getSubDictionary(COLOR_INFO);
|
|
|
|
node->a = DICTOOL->getIntValue_json(colorDic, A_ALPHA, 255);
|
|
|
|
node->r = DICTOOL->getIntValue_json(colorDic, A_RED, 255);
|
|
|
|
node->g = DICTOOL->getIntValue_json(colorDic, A_GREEN, 255);
|
|
|
|
node->b = DICTOOL->getIntValue_json(colorDic, A_BLUE, 255);
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-12-24 20:33:55 +08:00
|
|
|
node->isUseColorInfo = true;
|
|
|
|
}
|
2013-06-07 10:52:32 +08:00
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
|
|
|
}
|
2014-06-18 17:43:13 +08:00
|
|
|
|
|
|
|
void DataReaderHelper::addDataFromBinaryCache(const char *fileContent, DataInfo *dataInfo)
|
|
|
|
{
|
|
|
|
CocoLoader tCocoLoader;
|
|
|
|
if (tCocoLoader.ReadCocoBinBuff((char*)fileContent))
|
|
|
|
{
|
|
|
|
stExpCocoNode *tpRootCocoNode = tCocoLoader.GetRootCocoNode();
|
|
|
|
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
|
|
|
|
if (rapidjson::kObjectType == tType)
|
|
|
|
{
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *tpChildArray = tpRootCocoNode->GetChildArray(&tCocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
int nCount = tpRootCocoNode->GetChildNum();
|
|
|
|
|
|
|
|
dataInfo->contentScale = 1.0f;
|
|
|
|
int length = 0;
|
|
|
|
std::string key;
|
|
|
|
stExpCocoNode* pDataArray;
|
|
|
|
for (int i = 0; i < nCount; ++i)
|
|
|
|
{
|
|
|
|
key = tpChildArray[i].GetName(&tCocoLoader);
|
|
|
|
if (key.compare(CONTENT_SCALE) == 0)
|
|
|
|
{
|
2014-07-01 16:31:17 +08:00
|
|
|
std::string value = tpChildArray[i].GetValue(&tCocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
dataInfo->contentScale = atof(value.c_str());
|
|
|
|
}
|
|
|
|
else if ( 0 == key.compare(ARMATURE_DATA))
|
|
|
|
{
|
2014-07-01 16:31:17 +08:00
|
|
|
pDataArray = tpChildArray[i].GetChildArray(&tCocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
length = tpChildArray[i].GetChildNum();
|
|
|
|
ArmatureData * armatureData;
|
|
|
|
for (int ii = 0; ii < length; ++ii)
|
|
|
|
{
|
|
|
|
armatureData = decodeArmature(&tCocoLoader, &pDataArray[ii], dataInfo);
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
|
|
|
}
|
|
|
|
ArmatureDataManager::getInstance()->addArmatureData(armatureData->name.c_str(), armatureData, dataInfo->filename.c_str());
|
|
|
|
armatureData->release();
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( 0 == key.compare(ANIMATION_DATA))
|
|
|
|
{
|
2014-07-01 16:31:17 +08:00
|
|
|
pDataArray = tpChildArray[i].GetChildArray(&tCocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
length = tpChildArray[i].GetChildNum();
|
|
|
|
AnimationData *animationData;
|
2014-06-18 20:09:12 +08:00
|
|
|
for (int ii = 0; ii < length; ++ii)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
animationData = decodeAnimation(&tCocoLoader, &pDataArray[ii], dataInfo);
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
|
|
|
}
|
|
|
|
ArmatureDataManager::getInstance()->addAnimationData(animationData->name.c_str(), animationData, dataInfo->filename.c_str());
|
|
|
|
animationData->release();
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(TEXTURE_DATA) == 0)
|
|
|
|
{
|
2014-07-01 16:31:17 +08:00
|
|
|
pDataArray = tpChildArray[i].GetChildArray(&tCocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
length = tpChildArray[i].GetChildNum();
|
|
|
|
for (int ii = 0; ii < length; ++ii)
|
|
|
|
{
|
|
|
|
TextureData *textureData = decodeTexture(&tCocoLoader, &pDataArray[ii]);
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
|
|
|
}
|
|
|
|
ArmatureDataManager::getInstance()->addTextureData(textureData->name.c_str(), textureData, dataInfo->filename.c_str());
|
|
|
|
textureData->release();
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Auto losprite file
|
2014-06-23 10:12:54 +08:00
|
|
|
bool autoLoad = dataInfo->asyncStruct == nullptr ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile() : dataInfo->asyncStruct->autoLoadSpriteFile;
|
2014-06-18 17:43:13 +08:00
|
|
|
if (autoLoad)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < nCount; ++i)
|
|
|
|
{
|
|
|
|
key = tpChildArray[i].GetName(&tCocoLoader);
|
|
|
|
if( 0 != key.compare(CONFIG_FILE_PATH))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
length = tpChildArray[i].GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pConfigFilePath = tpChildArray[i].GetChildArray(&tCocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
for (int ii = 0; ii < length; ii++)
|
|
|
|
{
|
2014-07-01 16:31:17 +08:00
|
|
|
const char *path = pConfigFilePath[ii].GetValue(&tCocoLoader);
|
2014-06-23 10:12:54 +08:00
|
|
|
if (path == nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
CCLOG("load CONFIG_FILE_PATH error.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string filePath = path;
|
|
|
|
filePath = filePath.erase(filePath.find_last_of("."));
|
|
|
|
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
dataInfo->configFileQueue.push(filePath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string plistPath = filePath + ".plist";
|
|
|
|
std::string pngPath = filePath + ".png";
|
|
|
|
|
|
|
|
ArmatureDataManager::getInstance()->addSpriteFrameFromFile((dataInfo->baseFilePath + plistPath).c_str(), (dataInfo->baseFilePath + pngPath).c_str(), dataInfo->filename.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
ArmatureData* DataReaderHelper::decodeArmature(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
ArmatureData *armatureData = new ArmatureData();
|
|
|
|
armatureData->init();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pAramtureDataArray = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
const char *name = pAramtureDataArray[2].GetValue(cocoLoader); //DICTOOL->getStringValue_json(json, A_NAME);
|
2014-06-23 10:12:54 +08:00
|
|
|
if(name != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
armatureData->name = name;
|
|
|
|
}
|
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
float version = atof(pAramtureDataArray[1].GetValue(cocoLoader));
|
2014-06-18 17:43:13 +08:00
|
|
|
dataInfo->cocoStudioVersion = armatureData->dataVersion = version; //DICTOOL->getFloatValue_json(json, VERSION, 0.1f);
|
|
|
|
|
|
|
|
int length = pAramtureDataArray[3].GetChildNum(); //DICTOOL->getArrayCount_json(json, BONE_DATA, 0);
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pBoneChildren = pAramtureDataArray[3].GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
stExpCocoNode* child;
|
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
//const rapidjson::Value &dic = DICTOOL->getSubDictionary_json(json, BONE_DATA, i); //json[BONE_DATA][i];
|
|
|
|
child = &pBoneChildren[i];
|
2014-06-23 10:02:09 +08:00
|
|
|
BoneData *boneData = decodeBone(cocoLoader, child, dataInfo);
|
2014-06-18 17:43:13 +08:00
|
|
|
armatureData->addBoneData(boneData);
|
|
|
|
boneData->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
return armatureData;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
BoneData* DataReaderHelper::decodeBone(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
BoneData *boneData = new BoneData();
|
|
|
|
boneData->init();
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
decodeNode(boneData, cocoLoader, cocoNode, dataInfo);
|
2014-06-18 17:43:13 +08:00
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pBoneChildren = cocoNode->GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
stExpCocoNode* child;
|
2014-06-23 10:12:54 +08:00
|
|
|
const char *str = nullptr;
|
2014-06-18 17:43:13 +08:00
|
|
|
std::string key;
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
child = &pBoneChildren[i];
|
2014-06-23 10:02:09 +08:00
|
|
|
key = child->GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
str = child->GetValue(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
if (key.compare(A_NAME) == 0)
|
|
|
|
{
|
|
|
|
//DICTOOL->getStringValue_json(json, A_NAME);
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
boneData->name = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_PARENT) == 0)
|
|
|
|
{
|
|
|
|
//DICTOOL->getStringValue_json(json, A_PARENT);
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
boneData->parentName = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(DISPLAY_DATA) == 0)
|
|
|
|
{
|
|
|
|
int count = child->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pDisplayData = child->GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
for (int ii = 0; ii < count; ++ii)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
DisplayData *displayData = decodeBoneDisplay(cocoLoader, &pDisplayData[ii], dataInfo);
|
2014-06-23 10:12:54 +08:00
|
|
|
if(displayData == nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
continue;
|
|
|
|
boneData->addDisplayData(displayData);
|
|
|
|
displayData->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return boneData;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
DisplayData* DataReaderHelper::decodeBoneDisplay(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode* children = cocoNode->GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
stExpCocoNode* child = &children[1];
|
2014-06-23 10:12:54 +08:00
|
|
|
const char *str = nullptr;
|
2014-06-18 17:43:13 +08:00
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string key = child->GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
str = child->GetValue(cocoLoader);
|
2014-06-23 10:12:54 +08:00
|
|
|
DisplayData *displayData = nullptr;
|
2014-06-18 17:43:13 +08:00
|
|
|
if (key.compare(A_DISPLAY_TYPE) == 0)
|
|
|
|
{
|
2014-07-01 16:31:17 +08:00
|
|
|
str = child->GetValue(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
DisplayType displayType = (DisplayType)(atoi(str));
|
|
|
|
|
|
|
|
int length = 0;
|
|
|
|
switch (displayType)
|
|
|
|
{
|
|
|
|
case CS_DISPLAY_SPRITE:
|
|
|
|
{
|
|
|
|
displayData = new SpriteDisplayData();
|
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
const char *name = children[0].GetValue(cocoLoader);
|
2014-06-23 10:12:54 +08:00
|
|
|
if(name != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
((SpriteDisplayData *)displayData)->displayName = name;
|
|
|
|
}
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pSkinDataArray = children[2].GetChildArray(cocoLoader);
|
2014-06-23 10:12:54 +08:00
|
|
|
if (pSkinDataArray != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
stExpCocoNode *pSkinData = &pSkinDataArray[0];
|
2014-06-23 10:12:54 +08:00
|
|
|
if (pSkinData != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
SpriteDisplayData *sdd = (SpriteDisplayData *)displayData;
|
|
|
|
length = pSkinData->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *SkinDataValue = pSkinData->GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
key = SkinDataValue[i].GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
str = SkinDataValue[i].GetValue(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
if (key.compare(A_X) == 0)
|
|
|
|
{
|
|
|
|
sdd->skinData.x = atof(str) * s_PositionReadScale;
|
|
|
|
}
|
|
|
|
else if (key.compare(A_Y) == 0)
|
|
|
|
{
|
|
|
|
sdd->skinData.y = atof(str) * s_PositionReadScale;
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SCALE_X) == 0)
|
|
|
|
{
|
|
|
|
sdd->skinData.scaleX = atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SCALE_Y) == 0)
|
|
|
|
{
|
|
|
|
sdd->skinData.scaleY = atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SKEW_X) == 0)
|
|
|
|
{
|
|
|
|
sdd->skinData.skewX = atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SKEW_Y) == 0)
|
|
|
|
{
|
|
|
|
sdd->skinData.skewY = atof(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sdd->skinData.x *= dataInfo->contentScale;
|
|
|
|
sdd->skinData.y *= dataInfo->contentScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case CS_DISPLAY_ARMATURE:
|
|
|
|
{
|
|
|
|
displayData = new ArmatureDisplayData();
|
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
const char *name = cocoNode[0].GetValue(cocoLoader);
|
2014-06-23 10:12:54 +08:00
|
|
|
if(name != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
((ArmatureDisplayData *)displayData)->displayName = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CS_DISPLAY_PARTICLE:
|
|
|
|
{
|
|
|
|
displayData = new ParticleDisplayData();
|
2014-06-23 10:02:09 +08:00
|
|
|
length = cocoNode->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pDisplayData = cocoNode->GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
key = pDisplayData[i].GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
str = pDisplayData[i].GetValue(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
if (key.compare(A_PLIST) == 0)
|
|
|
|
{
|
|
|
|
const char *plist = str;
|
2014-06-23 10:12:54 +08:00
|
|
|
if(plist != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
((ParticleDisplayData *)displayData)->displayName = dataInfo->asyncStruct->baseFilePath + plist;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
((ParticleDisplayData *)displayData)->displayName = dataInfo->baseFilePath + plist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
displayData = new SpriteDisplayData();
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
displayData->displayType = displayType;
|
|
|
|
}
|
|
|
|
return displayData;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
AnimationData* DataReaderHelper::decodeAnimation(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
AnimationData *aniData = new AnimationData();
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pAnimationData = cocoNode->GetChildArray(cocoLoader);
|
2014-06-23 10:12:54 +08:00
|
|
|
const char *str = nullptr;
|
2014-06-18 17:43:13 +08:00
|
|
|
std::string key;
|
|
|
|
stExpCocoNode* child;
|
|
|
|
MovementData *movementData;
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
child = &pAnimationData[i];
|
2014-06-23 10:02:09 +08:00
|
|
|
key = child->GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
str = child->GetValue(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
if (key.compare(A_NAME) == 0)
|
|
|
|
{
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
aniData->name = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(MOVEMENT_DATA) == 0)
|
|
|
|
{
|
|
|
|
int movcount = child->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode* movArray = child->GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
for( int movnum =0; movnum <movcount; movnum++)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
movementData = decodeMovement(cocoLoader, &movArray[movnum], dataInfo);
|
2014-06-18 17:43:13 +08:00
|
|
|
aniData->addMovement(movementData);
|
|
|
|
movementData->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return aniData;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
MovementData* DataReaderHelper::decodeMovement(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
MovementData *movementData = new MovementData();
|
|
|
|
movementData->scale = 1.0f;
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pMoveDataArray = cocoNode->GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
|
2014-06-23 10:12:54 +08:00
|
|
|
const char *str = nullptr;
|
2014-06-18 17:43:13 +08:00
|
|
|
std::string key;
|
|
|
|
stExpCocoNode* child;
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
child = &pMoveDataArray[i];
|
2014-06-23 10:02:09 +08:00
|
|
|
key = child->GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
str = child->GetValue(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
if (key.compare(A_NAME) == 0)
|
|
|
|
{
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
movementData->name = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_LOOP) == 0)
|
|
|
|
{
|
|
|
|
movementData->loop = true;
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
if (strcmp("1", str) != 0)
|
|
|
|
{
|
|
|
|
movementData->loop = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_DURATION_TWEEN) == 0)
|
|
|
|
{
|
|
|
|
movementData->durationTween = 0;
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
movementData->durationTween = atoi(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_DURATION_TO) == 0)
|
|
|
|
{
|
|
|
|
movementData->durationTo = 0;
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
movementData->durationTo = atoi(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_DURATION) == 0)
|
|
|
|
{
|
|
|
|
movementData->duration = 0;
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
movementData->duration = atoi(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_MOVEMENT_SCALE) == 0)
|
|
|
|
{
|
|
|
|
movementData->scale = 1.0;
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
movementData->scale = atof(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_TWEEN_EASING) == 0)
|
|
|
|
{
|
|
|
|
movementData->tweenEasing = cocos2d::tweenfunc::Linear;
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
movementData->tweenEasing = (TweenType)(atoi(str));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(MOVEMENT_BONE_DATA) == 0)
|
|
|
|
{
|
|
|
|
int count = child->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pMoveBoneData = child->GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
MovementBoneData *movementBoneData;
|
|
|
|
for (int ii = 0; ii < count; ++ii)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
movementBoneData = decodeMovementBone(cocoLoader, &pMoveBoneData[ii],dataInfo);
|
2014-06-18 17:43:13 +08:00
|
|
|
movementData->addMovementBoneData(movementBoneData);
|
|
|
|
movementBoneData->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return movementData;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
MovementBoneData* DataReaderHelper::decodeMovementBone(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
MovementBoneData *movementBoneData = new MovementBoneData();
|
|
|
|
movementBoneData->init();
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pMovementBoneDataArray = cocoNode->GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
stExpCocoNode* movebonechild;
|
2014-06-23 10:12:54 +08:00
|
|
|
const char *str = nullptr;
|
2014-06-18 17:43:13 +08:00
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
movebonechild = &pMovementBoneDataArray[i];
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string key = movebonechild->GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
str = movebonechild->GetValue(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
if (key.compare(A_NAME) == 0)
|
|
|
|
{
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
movementBoneData->name = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_MOVEMENT_DELAY) == 0)
|
|
|
|
{
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
movementBoneData->delay = atof(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(FRAME_DATA) == 0)
|
|
|
|
{
|
|
|
|
int count =movebonechild->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pFrameDataArray = movebonechild->GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
for (int ii = 0; ii < count; ++ii)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
FrameData *frameData = decodeFrame(cocoLoader, &pFrameDataArray[ii], dataInfo);
|
2014-06-18 17:43:13 +08:00
|
|
|
movementBoneData->addFrameData(frameData);
|
|
|
|
frameData->release();
|
|
|
|
|
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
|
|
|
{
|
|
|
|
frameData->frameID = movementBoneData->duration;
|
|
|
|
movementBoneData->duration += frameData->duration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ssize_t framesizemusone = movementBoneData->frameList.size()-1;
|
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE)
|
|
|
|
{
|
|
|
|
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
|
|
|
|
cocos2d::Vector<FrameData*> frames =movementBoneData->frameList;
|
|
|
|
|
|
|
|
ssize_t imusone =0;
|
|
|
|
ssize_t i =0;
|
|
|
|
for (i = framesizemusone; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
imusone = i-1;
|
|
|
|
float difSkewX = frames.at(i)->skewX - frames.at(imusone)->skewX;
|
|
|
|
float difSkewY = frames.at(i)->skewY - frames.at(imusone)->skewY;
|
|
|
|
|
|
|
|
if (difSkewX < -M_PI || difSkewX > M_PI)
|
|
|
|
{
|
|
|
|
frames.at(imusone)->skewX = difSkewX < 0 ? frames.at(imusone)->skewX - 2 * M_PI : frames.at(imusone)->skewX + 2 * M_PI;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (difSkewY < -M_PI || difSkewY > M_PI)
|
|
|
|
{
|
|
|
|
frames.at(imusone)->skewY = difSkewY < 0 ? frames.at(imusone)->skewY - 2 * M_PI : frames.at(imusone)->skewY + 2 * M_PI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
|
|
|
{
|
|
|
|
if (movementBoneData->frameList.size() > 0)
|
|
|
|
{
|
|
|
|
FrameData *frameData = new FrameData();
|
|
|
|
frameData = movementBoneData->frameList.at(framesizemusone);
|
|
|
|
movementBoneData->addFrameData(frameData);
|
|
|
|
frameData->release();
|
|
|
|
frameData->frameID = movementBoneData->duration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return movementBoneData;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
FrameData* DataReaderHelper::decodeFrame(CocoLoader *cocoLoader, stExpCocoNode *cocoNode, DataInfo *dataInfo)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
FrameData *frameData = new FrameData();
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
decodeNode(frameData, cocoLoader, cocoNode, dataInfo);
|
2014-06-18 17:43:13 +08:00
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pFrameDataArray = cocoNode->GetChildArray(cocoLoader);
|
2014-06-23 10:12:54 +08:00
|
|
|
const char *str = nullptr;
|
2014-06-18 17:43:13 +08:00
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string key = pFrameDataArray[i].GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
str = pFrameDataArray[i].GetValue(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
if (key.compare(A_TWEEN_EASING) == 0)
|
|
|
|
{
|
|
|
|
frameData->tweenEasing = cocos2d::tweenfunc::Linear;
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
frameData->tweenEasing = (TweenType)(atoi(str));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_DISPLAY_INDEX) == 0)
|
|
|
|
{
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
frameData->displayIndex = atoi(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_BLEND_SRC) == 0)
|
|
|
|
{
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
frameData->blendFunc.src = (GLenum)(atoi(str));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_BLEND_DST) == 0)
|
|
|
|
{
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
frameData->blendFunc.dst = (GLenum)(atoi(str));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_TWEEN_FRAME) == 0)
|
|
|
|
{
|
|
|
|
frameData->isTween = true;
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
if (strcmp("1", str) != 0)
|
|
|
|
{
|
|
|
|
frameData->isTween = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_EVENT) == 0)
|
|
|
|
{
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
frameData->strEvent = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_DURATION) == 0)
|
|
|
|
{
|
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
|
|
|
{
|
|
|
|
frameData->duration = 1;
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
frameData->duration = atoi(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_FRAME_INDEX) == 0)
|
|
|
|
{
|
|
|
|
if (dataInfo->cocoStudioVersion >= VERSION_COMBINED)
|
|
|
|
{
|
2014-06-23 10:12:54 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
frameData->frameID = atoi(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_EASING_PARAM) == 0)
|
|
|
|
{
|
|
|
|
int count = pFrameDataArray[i].GetChildNum();
|
|
|
|
if (count != 0 )
|
|
|
|
{
|
|
|
|
frameData->easingParams = new float[count];
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pFrameData = pFrameDataArray[i].GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
for (int ii = 0; ii < count; ++ii)
|
|
|
|
{
|
2014-07-01 16:31:17 +08:00
|
|
|
str = pFrameData[ii].GetValue(cocoLoader);
|
2014-06-23 10:12:54 +08:00
|
|
|
if (str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
frameData->easingParams[ii] = atof(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return frameData;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
TextureData* DataReaderHelper::decodeTexture(CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
TextureData *textureData = new TextureData();
|
|
|
|
textureData->init();
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
if(cocoNode == nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
return textureData;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pTextureDataArray = cocoNode->GetChildArray(cocoLoader);
|
2014-06-23 10:02:09 +08:00
|
|
|
const char *str = nullptr;
|
2014-06-18 17:43:13 +08:00
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string key = pTextureDataArray[i].GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
str = pTextureDataArray[i].GetValue(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
if (key.compare(A_NAME) == 0)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
textureData->name = str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_WIDTH) == 0)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
if(str != nullptr)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
textureData->width = atof(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_HEIGHT) == 0)
|
|
|
|
{
|
|
|
|
if(str != NULL)
|
|
|
|
{
|
|
|
|
textureData->height = atof(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_PIVOT_X) == 0)
|
|
|
|
{
|
|
|
|
if(str != NULL)
|
|
|
|
{
|
|
|
|
textureData->pivotX = atof(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(A_PIVOT_Y) == 0)
|
|
|
|
{
|
|
|
|
if(str != NULL)
|
|
|
|
{
|
|
|
|
textureData->pivotY = atof(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (key.compare(CONTOUR_DATA) == 0)
|
|
|
|
{
|
|
|
|
int count = pTextureDataArray[i].GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pContourArray = pTextureDataArray[i].GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
for (int ii = 0; ii < count; ++ii)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
ContourData *contourData = decodeContour(cocoLoader, &pContourArray[ii]);
|
2014-06-18 17:43:13 +08:00
|
|
|
textureData->contourDataList.pushBack(contourData);
|
|
|
|
contourData->release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return textureData;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
ContourData* DataReaderHelper::decodeContour(CocoLoader *cocoLoader, stExpCocoNode *cocoNode)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
ContourData *contourData = new ContourData();
|
|
|
|
contourData->init();
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *verTexPointArray = cocoNode->GetChildArray(cocoLoader);
|
2014-06-23 10:02:09 +08:00
|
|
|
const char *str = nullptr;
|
2014-06-18 17:43:13 +08:00
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string key = verTexPointArray[i].GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
str = verTexPointArray[i].GetValue(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
if (key.compare(VERTEX_POINT) == 0)
|
|
|
|
{
|
|
|
|
int count = verTexPointArray[i].GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *pVerTexPointArray = verTexPointArray[i].GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
stExpCocoNode *pVerTexPoint;
|
|
|
|
for (int ii = count - 1; ii >= 0; --ii)
|
|
|
|
{
|
2014-07-01 16:31:17 +08:00
|
|
|
pVerTexPoint = pVerTexPointArray[ii].GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
Vec2 vertex;
|
2014-07-01 16:31:17 +08:00
|
|
|
vertex.x = atof(pVerTexPoint[0].GetValue(cocoLoader));
|
|
|
|
vertex.y = atof(pVerTexPoint[1].GetValue(cocoLoader));
|
2014-06-18 17:43:13 +08:00
|
|
|
contourData->vertexList.push_back(vertex); }
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return contourData;
|
|
|
|
}
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
void DataReaderHelper::decodeNode(BaseData *node, CocoLoader *cocoLoader, stExpCocoNode* cocoNode, DataInfo *dataInfo)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *NodeArray = cocoNode->GetChildArray(cocoLoader);
|
2014-06-23 10:12:54 +08:00
|
|
|
const char *str = nullptr;
|
2014-06-18 17:43:13 +08:00
|
|
|
|
|
|
|
bool isVersionL = dataInfo->cocoStudioVersion < VERSION_COLOR_READING;
|
|
|
|
stExpCocoNode* child;
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
child = &NodeArray[i];
|
2014-06-23 10:02:09 +08:00
|
|
|
std::string key = child->GetName(cocoLoader);
|
2014-07-01 16:31:17 +08:00
|
|
|
str = child->GetValue(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
if (key.compare(A_X) == 0)
|
|
|
|
{
|
|
|
|
node->x = atof(str) * dataInfo->contentScale;
|
|
|
|
}
|
|
|
|
else if (key.compare(A_Y) == 0)
|
|
|
|
{
|
|
|
|
node->y = atof(str) * dataInfo->contentScale;
|
|
|
|
}
|
|
|
|
else if (key.compare(A_Z) == 0)
|
|
|
|
{
|
|
|
|
node->zOrder = atoi(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SKEW_X) == 0)
|
|
|
|
{
|
|
|
|
node->skewX = atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SKEW_Y) == 0)
|
|
|
|
{
|
|
|
|
node->skewY = atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SCALE_X) == 0)
|
|
|
|
{
|
|
|
|
node->scaleX = atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SCALE_Y) == 0)
|
|
|
|
{
|
|
|
|
node->scaleY = atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(COLOR_INFO) == 0)
|
|
|
|
{
|
|
|
|
if (!isVersionL)
|
|
|
|
{
|
2014-06-23 10:02:09 +08:00
|
|
|
if (child->GetType(cocoLoader) == rapidjson::kObjectType)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
if(child->GetChildNum() == 4)
|
|
|
|
{
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *ChildArray = child->GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
node->a = atoi(ChildArray[0].GetValue(cocoLoader));
|
|
|
|
node->r = atoi(ChildArray[1].GetValue(cocoLoader));
|
|
|
|
node->g = atoi(ChildArray[2].GetValue(cocoLoader));
|
|
|
|
node->b = atoi(ChildArray[3].GetValue(cocoLoader));
|
2014-06-18 17:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
node->isUseColorInfo = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isVersionL)
|
|
|
|
{
|
|
|
|
int colorcoount = NodeArray[0].GetChildNum();
|
|
|
|
if(colorcoount>0)
|
|
|
|
{
|
|
|
|
|
2014-06-23 10:02:09 +08:00
|
|
|
if (NodeArray[0].GetType(cocoLoader) == rapidjson::kObjectType)
|
2014-06-18 17:43:13 +08:00
|
|
|
{
|
|
|
|
if(NodeArray[0].GetChildNum() == 4)
|
|
|
|
{
|
2014-07-01 16:31:17 +08:00
|
|
|
stExpCocoNode *ChildArray = NodeArray[0].GetChildArray(cocoLoader);
|
2014-06-18 17:43:13 +08:00
|
|
|
|
2014-07-01 16:31:17 +08:00
|
|
|
node->a = atoi(ChildArray[0].GetValue(cocoLoader));
|
|
|
|
node->r = atoi(ChildArray[1].GetValue(cocoLoader));
|
|
|
|
node->g = atoi(ChildArray[2].GetValue(cocoLoader));
|
|
|
|
node->b = atoi(ChildArray[3].GetValue(cocoLoader));
|
2014-06-18 17:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node->isUseColorInfo = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-06 12:02:54 +08:00
|
|
|
|
2013-10-15 18:00:03 +08:00
|
|
|
}
|