2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
2020-10-17 16:32:16 +08:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "platform/CCFileUtils.h"
|
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "base/CCScheduler.h"
|
|
|
|
#include "base/ccUtils.h"
|
|
|
|
|
2020-10-21 12:28:34 +08:00
|
|
|
#include "pugixml/pugixml.hpp"
|
2020-10-17 16:32:16 +08:00
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CCDataReaderHelper.h"
|
|
|
|
#include "CCArmatureDataManager.h"
|
|
|
|
#include "CCTransformHelp.h"
|
|
|
|
#include "CCArmatureDefine.h"
|
|
|
|
#include "CCDatas.h"
|
|
|
|
|
|
|
|
#include "CocoLoader.h"
|
2020-08-03 20:31:47 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
USING_NS_AX;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static const char* VERSION = "version";
|
2019-11-23 20:27:39 +08:00
|
|
|
static const float VERSION_2_0 = 2.0f;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
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";
|
|
|
|
static const char* A_FRAME_INDEX = "fi";
|
|
|
|
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";
|
|
|
|
static const char* A_EASING_PARAM = "twEP";
|
|
|
|
static const char* A_TWEEN_ROTATE = "twR";
|
|
|
|
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";
|
|
|
|
|
|
|
|
static const char* A_BLEND_TYPE = "bd";
|
|
|
|
static const char* A_BLEND_SRC = "bd_src";
|
|
|
|
static const char* A_BLEND_DST = "bd_dst";
|
|
|
|
|
|
|
|
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";
|
|
|
|
static const char* A_TWEEN_FRAME = "tweenFrame";
|
|
|
|
|
|
|
|
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";
|
|
|
|
static const char* SKIN_DATA = "skin_data";
|
|
|
|
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";
|
|
|
|
|
|
|
|
static const char* CONFIG_FILE_PATH = "config_file_path";
|
|
|
|
static const char* CONTENT_SCALE = "content_scale";
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
static std::string readFileContent(std::string_view filename, bool binary)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
auto fs = FileUtils::getInstance();
|
|
|
|
std::string s;
|
|
|
|
if (binary)
|
|
|
|
fs->getContents(filename, &s);
|
|
|
|
else
|
|
|
|
s = fs->getStringFromFile(filename);
|
|
|
|
return s;
|
|
|
|
};
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
float s_PositionReadScale = 1;
|
|
|
|
|
|
|
|
std::vector<std::string> DataReaderHelper::_configFileList;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
DataReaderHelper* DataReaderHelper::_dataReaderHelper = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
//! Async load
|
|
|
|
void DataReaderHelper::loadData()
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
AsyncStruct* pAsyncStruct = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
while (true)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::queue<AsyncStruct*>* pQueue = _asyncStructQueue;
|
|
|
|
_asyncStructQueueMutex.lock(); // get async struct from queue
|
2019-11-23 20:27:39 +08:00
|
|
|
if (pQueue->empty())
|
|
|
|
{
|
|
|
|
_asyncStructQueueMutex.unlock();
|
|
|
|
if (need_quit)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::unique_lock<std::mutex> lk(_sleepMutex);
|
|
|
|
_sleepCondition.wait(lk);
|
2019-11-23 20:27:39 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pAsyncStruct = pQueue->front();
|
|
|
|
pQueue->pop();
|
|
|
|
_asyncStructQueueMutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate data info
|
2021-12-25 10:04:45 +08:00
|
|
|
DataInfo* pDataInfo = new DataInfo();
|
|
|
|
pDataInfo->asyncStruct = pAsyncStruct;
|
|
|
|
pDataInfo->filename = pAsyncStruct->filename;
|
2019-11-23 20:27:39 +08:00
|
|
|
pDataInfo->baseFilePath = pAsyncStruct->baseFilePath;
|
|
|
|
|
|
|
|
if (pAsyncStruct->configType == DragonBone_XML)
|
|
|
|
{
|
|
|
|
DataReaderHelper::addDataFromCache(pAsyncStruct->fileContent, pDataInfo);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (pAsyncStruct->configType == CocoStudio_JSON)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
DataReaderHelper::addDataFromJsonCache(pAsyncStruct->fileContent, pDataInfo);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (pAsyncStruct->configType == CocoStudio_Binary)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
DataReaderHelper::addDataFromBinaryCache(pAsyncStruct->fileContent.c_str(), pDataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// put the image info into the queue
|
|
|
|
_dataInfoMutex.lock();
|
|
|
|
_dataQueue->push(pDataInfo);
|
|
|
|
_dataInfoMutex.unlock();
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (_asyncStructQueue != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
delete _asyncStructQueue;
|
|
|
|
_asyncStructQueue = nullptr;
|
|
|
|
delete _dataQueue;
|
|
|
|
_dataQueue = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
DataReaderHelper* DataReaderHelper::getInstance()
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_dataReaderHelper)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
_dataReaderHelper = new DataReaderHelper();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return _dataReaderHelper;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataReaderHelper::setPositionReadScale(float scale)
|
|
|
|
{
|
|
|
|
s_PositionReadScale = scale;
|
|
|
|
}
|
|
|
|
|
|
|
|
float DataReaderHelper::getPositionReadScale()
|
|
|
|
{
|
|
|
|
return s_PositionReadScale;
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataReaderHelper::purge()
|
|
|
|
{
|
|
|
|
_configFileList.clear();
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SAFE_RELEASE_NULL(_dataReaderHelper);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
DataReaderHelper::DataReaderHelper()
|
2021-12-25 10:04:45 +08:00
|
|
|
: _loadingThread(nullptr)
|
|
|
|
, _asyncRefCount(0)
|
|
|
|
, _asyncRefTotalCount(0)
|
|
|
|
, need_quit(false)
|
|
|
|
, _asyncStructQueue(nullptr)
|
|
|
|
, _dataQueue(nullptr)
|
|
|
|
{}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
DataReaderHelper::~DataReaderHelper()
|
|
|
|
{
|
|
|
|
need_quit = true;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
_sleepCondition.notify_one();
|
|
|
|
if (_loadingThread)
|
|
|
|
_loadingThread->join();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SAFE_DELETE(_loadingThread);
|
2021-12-25 10:04:45 +08:00
|
|
|
_dataReaderHelper = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void DataReaderHelper::addDataFromFile(std::string_view filePath)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
/*
|
2021-12-25 10:04:45 +08:00
|
|
|
* Check if file is already added to ArmatureDataManager, if then return.
|
|
|
|
*/
|
|
|
|
for (unsigned int i = 0; i < _configFileList.size(); i++)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (_configFileList[i] == filePath)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-08-09 09:54:53 +08:00
|
|
|
_configFileList.emplace_back(std::string{filePath});
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
//! find the base file path
|
2021-12-31 12:12:40 +08:00
|
|
|
std::string basefilePath;
|
|
|
|
size_t pos = filePath.find_last_of('/');
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
basefilePath = filePath.substr(0, pos + 1);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
std::string fileExtension = ax::FileUtils::getInstance()->getFileExtension(filePath);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// Read content from file
|
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
|
|
|
bool isbinaryfilesrc = fileExtension == ".csb";
|
|
|
|
|
|
|
|
_dataReaderHelper->_getFileMutex.lock();
|
|
|
|
std::string contentStr(readFileContent(fullPath, isbinaryfilesrc));
|
|
|
|
_dataReaderHelper->_getFileMutex.unlock();
|
|
|
|
|
|
|
|
DataInfo dataInfo;
|
2021-12-25 10:04:45 +08:00
|
|
|
dataInfo.filename = filePath;
|
|
|
|
dataInfo.asyncStruct = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
dataInfo.baseFilePath = basefilePath;
|
|
|
|
if (fileExtension == ".xml")
|
|
|
|
{
|
|
|
|
DataReaderHelper::addDataFromCache(contentStr, &dataInfo);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (fileExtension == ".json" || fileExtension == ".exportjson")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
DataReaderHelper::addDataFromJsonCache(contentStr, &dataInfo);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (isbinaryfilesrc)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
DataReaderHelper::addDataFromBinaryCache(contentStr.c_str(), &dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void DataReaderHelper::addDataFromFileAsync(std::string_view imagePath,
|
|
|
|
std::string_view plistPath,
|
|
|
|
std::string_view filePath,
|
2021-12-25 10:04:45 +08:00
|
|
|
Ref* target,
|
|
|
|
SEL_SCHEDULE selector)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
/*
|
2021-12-25 10:04:45 +08:00
|
|
|
* Check if file is already added to ArmatureDataManager, if then return.
|
|
|
|
*/
|
|
|
|
for (unsigned int i = 0; i < _configFileList.size(); i++)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (_configFileList[i] == filePath)
|
|
|
|
{
|
|
|
|
if (target && selector)
|
|
|
|
{
|
|
|
|
if (_asyncRefTotalCount == 0 && _asyncRefCount == 0)
|
|
|
|
{
|
|
|
|
(target->*selector)(1);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
(target->*selector)((_asyncRefTotalCount - _asyncRefCount) / (float)_asyncRefTotalCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2022-08-09 09:54:53 +08:00
|
|
|
_configFileList.emplace_back(std::string{filePath});
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
//! find the base file path
|
2021-12-31 12:12:40 +08:00
|
|
|
std::string basefilePath;
|
|
|
|
size_t pos = filePath.find_last_of('/');
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (pos != std::string::npos)
|
|
|
|
{
|
2021-12-31 12:12:40 +08:00
|
|
|
basefilePath = filePath.substr(0, pos + 1);
|
2020-10-04 23:41:01 +08:00
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// lazy init
|
|
|
|
if (_asyncStructQueue == nullptr)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_asyncStructQueue = new std::queue<AsyncStruct*>();
|
|
|
|
_dataQueue = new std::queue<DataInfo*>();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
// create a new thread to load images
|
|
|
|
_loadingThread = new std::thread(&DataReaderHelper::loadData, this);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
need_quit = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == _asyncRefCount)
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
Director::getInstance()->getScheduler()->schedule(AX_SCHEDULE_SELECTOR(DataReaderHelper::addDataAsyncCallBack),
|
2021-12-25 10:04:45 +08:00
|
|
|
this, 0, false);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
++_asyncRefCount;
|
|
|
|
++_asyncRefTotalCount;
|
|
|
|
|
|
|
|
if (target)
|
|
|
|
{
|
|
|
|
target->retain();
|
|
|
|
}
|
|
|
|
|
|
|
|
// generate async struct
|
2021-12-25 10:04:45 +08:00
|
|
|
AsyncStruct* data = new AsyncStruct();
|
|
|
|
data->filename = filePath;
|
|
|
|
data->baseFilePath = basefilePath;
|
|
|
|
data->target = target;
|
|
|
|
data->selector = selector;
|
2019-11-23 20:27:39 +08:00
|
|
|
data->autoLoadSpriteFile = ArmatureDataManager::getInstance()->isAutoLoadSpriteFile();
|
|
|
|
|
|
|
|
data->imagePath = imagePath;
|
|
|
|
data->plistPath = plistPath;
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
std::string fileExtension = ax::FileUtils::getInstance()->getFileExtension(filePath);
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(filePath);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
bool isbinaryfilesrc = fileExtension == ".csb";
|
|
|
|
|
|
|
|
// This only read exportJson file, it takes only a little time.
|
|
|
|
// Large image files are loaded in DataReaderHelper::addDataFromJsonCache(dataInfo) asynchronously.
|
|
|
|
_dataReaderHelper->_getFileMutex.lock();
|
|
|
|
data->fileContent.assign(readFileContent(fullPath, isbinaryfilesrc));
|
|
|
|
_dataReaderHelper->_getFileMutex.unlock();
|
|
|
|
|
|
|
|
if (fileExtension == ".xml")
|
|
|
|
{
|
|
|
|
data->configType = DragonBone_XML;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (fileExtension == ".json" || fileExtension == ".exportjson")
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
data->configType = CocoStudio_JSON;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (isbinaryfilesrc)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
data->configType = CocoStudio_Binary;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add async struct into queue
|
|
|
|
_asyncStructQueueMutex.lock();
|
|
|
|
_asyncStructQueue->push(data);
|
|
|
|
_asyncStructQueueMutex.unlock();
|
|
|
|
|
|
|
|
_sleepCondition.notify_one();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DataReaderHelper::addDataAsyncCallBack(float /*dt*/)
|
|
|
|
{
|
|
|
|
// the data is generated in loading thread
|
2021-12-25 10:04:45 +08:00
|
|
|
std::queue<DataInfo*>* dataQueue = _dataQueue;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
_dataInfoMutex.lock();
|
|
|
|
if (dataQueue->empty())
|
|
|
|
{
|
|
|
|
_dataInfoMutex.unlock();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
DataInfo* pDataInfo = dataQueue->front();
|
2019-11-23 20:27:39 +08:00
|
|
|
dataQueue->pop();
|
|
|
|
_dataInfoMutex.unlock();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
AsyncStruct* pAsyncStruct = pDataInfo->asyncStruct;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (pAsyncStruct->imagePath != "" && pAsyncStruct->plistPath != "")
|
|
|
|
{
|
|
|
|
_getFileMutex.lock();
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureDataManager::getInstance()->addSpriteFrameFromFile(pAsyncStruct->plistPath, pAsyncStruct->imagePath,
|
|
|
|
pDataInfo->filename);
|
2019-11-23 20:27:39 +08:00
|
|
|
_getFileMutex.unlock();
|
|
|
|
}
|
|
|
|
|
|
|
|
while (!pDataInfo->configFileQueue.empty())
|
|
|
|
{
|
|
|
|
std::string configPath = pDataInfo->configFileQueue.front();
|
|
|
|
_getFileMutex.lock();
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureDataManager::getInstance()->addSpriteFrameFromFile(
|
|
|
|
(pAsyncStruct->baseFilePath + configPath + ".plist"),
|
|
|
|
(pAsyncStruct->baseFilePath + configPath + ".png"), pDataInfo->filename);
|
2019-11-23 20:27:39 +08:00
|
|
|
_getFileMutex.unlock();
|
|
|
|
pDataInfo->configFileQueue.pop();
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Ref* target = pAsyncStruct->target;
|
2019-11-23 20:27:39 +08:00
|
|
|
SEL_SCHEDULE selector = pAsyncStruct->selector;
|
|
|
|
|
|
|
|
--_asyncRefCount;
|
|
|
|
|
|
|
|
if (target && selector)
|
|
|
|
{
|
|
|
|
(target->*selector)((_asyncRefTotalCount - _asyncRefCount) / (float)_asyncRefTotalCount);
|
|
|
|
target->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
delete pAsyncStruct;
|
|
|
|
delete pDataInfo;
|
|
|
|
|
|
|
|
if (0 == _asyncRefCount)
|
|
|
|
{
|
|
|
|
_asyncRefTotalCount = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
Director::getInstance()->getScheduler()->unschedule(
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_SCHEDULE_SELECTOR(DataReaderHelper::addDataAsyncCallBack), this);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void DataReaderHelper::removeConfigFile(std::string_view configFile)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
auto it_end = _configFileList.end();
|
|
|
|
for (auto it = _configFileList.begin(); it != it_end; ++it)
|
|
|
|
{
|
|
|
|
if (*it == configFile)
|
|
|
|
{
|
|
|
|
_configFileList.erase(it);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void DataReaderHelper::addDataFromCache(std::string_view pFileContent, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_document document;
|
2021-12-31 12:12:40 +08:00
|
|
|
pugi::xml_parse_result ret = document.load_buffer(pFileContent.data(), pFileContent.length());
|
|
|
|
if (!ret)
|
|
|
|
return;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
auto root = document.document_element();
|
2019-11-24 23:15:56 +08:00
|
|
|
dataInfo->flashToolVersion = root.attribute(VERSION).as_float();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/*
|
2021-12-25 10:04:45 +08:00
|
|
|
* Begin decode armature data from xml
|
|
|
|
*/
|
2019-11-24 23:15:56 +08:00
|
|
|
auto armaturesXML = root.child(ARMATURES);
|
2021-12-25 10:04:45 +08:00
|
|
|
auto armatureXML = armaturesXML.child(ARMATURE);
|
|
|
|
while (armatureXML)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureData* armatureData = DataReaderHelper::decodeArmature(armatureXML, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
|
|
|
}
|
|
|
|
ArmatureDataManager::getInstance()->addArmatureData(armatureData->name, armatureData, dataInfo->filename);
|
|
|
|
armatureData->release();
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
armatureXML = armatureXML.next_sibling(ARMATURE);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-12-25 10:04:45 +08:00
|
|
|
* Begin decode animation data from xml
|
|
|
|
*/
|
2019-11-24 23:15:56 +08:00
|
|
|
auto animationsXML = root.child(ANIMATIONS);
|
2021-12-25 10:04:45 +08:00
|
|
|
auto animationXML = animationsXML.child(ANIMATION);
|
|
|
|
while (animationXML)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
AnimationData* animationData = DataReaderHelper::decodeAnimation(animationXML, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
|
|
|
}
|
|
|
|
ArmatureDataManager::getInstance()->addAnimationData(animationData->name, animationData, dataInfo->filename);
|
|
|
|
animationData->release();
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
animationXML = animationXML.next_sibling(ANIMATION);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2021-12-25 10:04:45 +08:00
|
|
|
* Begin decode texture data from xml
|
|
|
|
*/
|
2019-11-24 23:15:56 +08:00
|
|
|
auto texturesXML = root.child(TEXTURE_ATLAS);
|
2021-12-25 10:04:45 +08:00
|
|
|
auto textureXML = texturesXML.child(SUB_TEXTURE);
|
|
|
|
while (textureXML)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
TextureData* textureData = DataReaderHelper::decodeTexture(textureXML, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
|
|
|
}
|
|
|
|
ArmatureDataManager::getInstance()->addTextureData(textureData->name, textureData, dataInfo->filename);
|
|
|
|
textureData->release();
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
textureXML = textureXML.next_sibling(SUB_TEXTURE);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureData* DataReaderHelper::decodeArmature(pugi::xml_node& armatureXML, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureData* armatureData = new ArmatureData();
|
2019-11-23 20:27:39 +08:00
|
|
|
armatureData->init();
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
armatureData->name = armatureXML.attribute(A_NAME).as_string();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_node boneXML = armatureXML.child(BONE);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
while (boneXML)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
/*
|
2021-12-25 10:04:45 +08:00
|
|
|
* If this bone have parent, then get the parent bone xml
|
|
|
|
*/
|
2021-12-31 15:49:45 +08:00
|
|
|
auto parentName = boneXML.attribute(A_PARENT).as_string();
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_node parentXML;
|
2021-12-31 15:49:45 +08:00
|
|
|
if (!parentName.empty())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
parentXML = armatureXML.child(BONE);
|
2021-12-31 15:49:45 +08:00
|
|
|
auto parentNameStr = parentName;
|
2019-11-23 20:27:39 +08:00
|
|
|
while (parentXML)
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
if (parentNameStr == parentXML.attribute(A_NAME).as_string())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
parentXML = parentXML.next_sibling(BONE);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
BoneData* boneData = decodeBone(boneXML, parentXML, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
armatureData->addBoneData(boneData);
|
|
|
|
boneData->release();
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
boneXML = boneXML.next_sibling(BONE);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return armatureData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
BoneData* DataReaderHelper::decodeBone(pugi::xml_node& boneXML, pugi::xml_node& /*parentXml*/, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
BoneData* boneData = new BoneData();
|
2019-11-23 20:27:39 +08:00
|
|
|
boneData->init();
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
boneData->name = boneXML.attribute(A_NAME).as_string();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
auto aparent = boneXML.attribute(A_PARENT);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (aparent)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
boneData->parentName = aparent.as_string();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
boneData->zOrder = boneXML.attribute(A_Z).as_int();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_node displayXML = boneXML.child(DISPLAY);
|
2021-12-25 10:04:45 +08:00
|
|
|
while (displayXML)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
DisplayData* displayData = decodeBoneDisplay(displayXML, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
boneData->addDisplayData(displayData);
|
|
|
|
displayData->release();
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
displayXML = displayXML.next_sibling(DISPLAY);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return boneData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
DisplayData* DataReaderHelper::decodeBoneDisplay(pugi::xml_node& displayXML, DataInfo* /*dataInfo*/)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
int _isArmature = 0;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
DisplayData* displayData;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
auto isArmatureDS = displayXML.attribute(A_IS_ARMATURE);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (isArmatureDS)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
_isArmature = isArmatureDS.as_int();
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_isArmature)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
displayData = new SpriteDisplayData();
|
|
|
|
displayData->displayType = CS_DISPLAY_SPRITE;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
displayData = new ArmatureDisplayData();
|
|
|
|
displayData->displayType = CS_DISPLAY_ARMATURE;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
displayData = new SpriteDisplayData();
|
|
|
|
displayData->displayType = CS_DISPLAY_SPRITE;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
auto nameDS = displayXML.attribute(A_NAME);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (nameDS)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_isArmature)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
((SpriteDisplayData*)displayData)->displayName = nameDS.as_string();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
((ArmatureDisplayData*)displayData)->displayName = nameDS.as_string();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return displayData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
AnimationData* DataReaderHelper::decodeAnimation(pugi::xml_node& animationXML, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
AnimationData* aniData = new AnimationData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 15:49:45 +08:00
|
|
|
auto name = animationXML.attribute(A_NAME).as_string();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureData* armatureData = ArmatureDataManager::getInstance()->getArmatureData(name);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
aniData->name = name;
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_node movementXML = animationXML.child(MOVEMENT);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
while (movementXML)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementData* movementData = decodeMovement(movementXML, armatureData, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
aniData->addMovement(movementData);
|
|
|
|
movementData->release();
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
movementXML = movementXML.next_sibling(MOVEMENT);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return aniData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementData* DataReaderHelper::decodeMovement(pugi::xml_node& movementXML,
|
|
|
|
ArmatureData* armatureData,
|
|
|
|
DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementData* movementData = new MovementData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 15:49:45 +08:00
|
|
|
auto movName = movementXML.attribute(A_NAME).as_string();
|
2021-12-25 10:04:45 +08:00
|
|
|
movementData->name = movName;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(movementXML, A_DURATION, &movementData->duration);
|
|
|
|
pugiext::query_attribute(movementXML, A_DURATION_TO, &movementData->durationTo);
|
|
|
|
pugiext::query_attribute(movementXML, A_DURATION_TWEEN, &movementData->durationTween);
|
|
|
|
pugiext::query_attribute(movementXML, A_LOOP, &movementData->loop);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-31 15:49:45 +08:00
|
|
|
auto _easing = movementXML.attribute(A_TWEEN_EASING).as_string();
|
|
|
|
if (!_easing.empty())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
if (_easing != FL_NAN)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
int tweenEasing = atoi(_easing.data());
|
2022-08-08 18:02:17 +08:00
|
|
|
movementData->tweenEasing = tweenEasing == 2 ? ax::tweenfunc::Sine_EaseInOut : (TweenType)tweenEasing;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
movementData->tweenEasing = ax::tweenfunc::Linear;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_node movBoneXml = movementXML.child(BONE);
|
2021-12-25 10:04:45 +08:00
|
|
|
while (movBoneXml)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-31 15:49:45 +08:00
|
|
|
auto boneName = movBoneXml.attribute(A_NAME).as_string();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (movementData->getMovementBoneData(boneName))
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
movBoneXml = movBoneXml.next_sibling();
|
2019-11-23 20:27:39 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
BoneData* boneData = (BoneData*)armatureData->getBoneData(boneName);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
std::string parentName = boneData->parentName;
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_node parentXml;
|
2019-11-23 20:27:39 +08:00
|
|
|
if (!parentName.empty())
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
parentXml = movementXML.child(BONE);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
while (parentXml)
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
if (parentName == parentXml.attribute(A_NAME).as_string())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2019-11-24 23:15:56 +08:00
|
|
|
parentXml = parentXml.next_sibling(BONE);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementBoneData* moveBoneData = decodeMovementBone(movBoneXml, parentXml, boneData, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
movementData->addMovementBoneData(moveBoneData);
|
|
|
|
moveBoneData->release();
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
movBoneXml = movBoneXml.next_sibling(BONE);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return movementData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementBoneData* DataReaderHelper::decodeMovementBone(pugi::xml_node& movBoneXml,
|
|
|
|
pugi::xml_node& parentXml,
|
|
|
|
BoneData* boneData,
|
|
|
|
DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementBoneData* movBoneData = new MovementBoneData();
|
2019-11-23 20:27:39 +08:00
|
|
|
movBoneData->init();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (movBoneXml)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(movBoneXml, A_MOVEMENT_SCALE, &movBoneData->scale);
|
|
|
|
float delay;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (pugiext::query_attribute(movBoneXml, A_MOVEMENT_DELAY, &delay))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (delay > 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
delay -= 1;
|
|
|
|
}
|
|
|
|
movBoneData->delay = delay;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
unsigned long length = 0;
|
|
|
|
unsigned long index = 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
int parentTotalDuration = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
int currentDuration = 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_node parentFrameXML;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
std::vector<pugi::xml_node> parentXmlList;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/*
|
2021-12-25 10:04:45 +08:00
|
|
|
* get the parent frame xml list, we need get the origin data
|
|
|
|
*/
|
|
|
|
if (parentXml != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
parentFrameXML = parentXml.child(FRAME);
|
2019-11-23 20:27:39 +08:00
|
|
|
while (parentFrameXML)
|
|
|
|
{
|
2022-08-09 09:54:53 +08:00
|
|
|
parentXmlList.emplace_back(parentFrameXML);
|
2019-11-24 23:15:56 +08:00
|
|
|
parentFrameXML = parentFrameXML.next_sibling(FRAME);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
length = parentXmlList.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
int totalDuration = 0;
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
movBoneData->name = movBoneXml.attribute(A_NAME).as_string();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_node frameXML = movBoneXml.child(FRAME);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
while (frameXML)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (parentXml)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
/*
|
2021-12-25 10:04:45 +08:00
|
|
|
* in this loop we get the corresponding parent frame xml
|
|
|
|
*/
|
|
|
|
while (index < length && (parentFrameXML ? (totalDuration < parentTotalDuration ||
|
|
|
|
totalDuration >= parentTotalDuration + currentDuration)
|
|
|
|
: true))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
parentFrameXML = parentXmlList[index];
|
|
|
|
parentTotalDuration += currentDuration;
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(parentFrameXML, A_DURATION, ¤tDuration);
|
2019-11-23 20:27:39 +08:00
|
|
|
index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
FrameData* frameData = decodeFrame(frameXML, parentFrameXML, boneData, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
movBoneData->addFrameData(frameData);
|
|
|
|
frameData->release();
|
|
|
|
|
|
|
|
frameData->frameID = totalDuration;
|
|
|
|
totalDuration += frameData->duration;
|
|
|
|
movBoneData->duration = totalDuration;
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
frameXML = frameXML.next_sibling(FRAME);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
|
|
|
|
auto frames = movBoneData->frameList;
|
|
|
|
for (long j = movBoneData->frameList.size() - 1; j >= 0; j--)
|
|
|
|
{
|
|
|
|
if (j > 0)
|
|
|
|
{
|
|
|
|
float difSkewX = frames.at(j)->skewX - frames.at(j - 1)->skewX;
|
|
|
|
float difSkewY = frames.at(j)->skewY - frames.at(j - 1)->skewY;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (difSkewX < -M_PI || difSkewX > M_PI)
|
|
|
|
{
|
|
|
|
frames.at(j - 1)->skewX =
|
|
|
|
difSkewX < 0 ? frames.at(j - 1)->skewX - 2 * M_PI : frames.at(j - 1)->skewX + 2 * M_PI;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (difSkewY < -M_PI || difSkewY > M_PI)
|
|
|
|
{
|
|
|
|
frames.at(j - 1)->skewY =
|
|
|
|
difSkewY < 0 ? frames.at(j - 1)->skewY - 2 * M_PI : frames.at(j - 1)->skewY + 2 * M_PI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
//
|
2021-12-25 10:04:45 +08:00
|
|
|
FrameData* frameData = new FrameData();
|
|
|
|
frameData->copy((FrameData*)movBoneData->frameList.back());
|
2019-11-23 20:27:39 +08:00
|
|
|
frameData->frameID = movBoneData->duration;
|
|
|
|
movBoneData->addFrameData(frameData);
|
|
|
|
frameData->release();
|
|
|
|
|
|
|
|
return movBoneData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
FrameData* DataReaderHelper::decodeFrame(pugi::xml_node& frameXML,
|
|
|
|
pugi::xml_node& parentFrameXml,
|
|
|
|
BoneData* /*boneData*/,
|
|
|
|
DataInfo* dataInfo)
|
2019-11-23 20:27:39 +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;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
FrameData* frameData = new FrameData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(frameXML, A_MOVEMENT, &frameData->strMovement);
|
|
|
|
pugiext::query_attribute(frameXML, A_SOUND, &frameData->strSound);
|
|
|
|
pugiext::query_attribute(frameXML, A_SOUND_EFFECT, &frameData->strSoundEffect);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
pugiext::query_attribute(frameXML, A_SOUND_EFFECT, &frameData->isTween);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (dataInfo->flashToolVersion >= VERSION_2_0)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (pugiext::query_attribute(frameXML, A_COCOS2DX_X, &frameData->x))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
frameData->x *= s_PositionReadScale;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
if (pugiext::query_attribute(frameXML, A_COCOS2DX_Y, &frameData->y))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
frameData->y *= s_PositionReadScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (pugiext::query_attribute(frameXML, A_X, &frameData->x))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
frameData->x *= s_PositionReadScale;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
if (pugiext::query_attribute(frameXML, A_Y, &frameData->y))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
frameData->y *= s_PositionReadScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
auto degrees2radius = [](float v) { return AX_DEGREES_TO_RADIANS(v); };
|
2019-11-24 23:15:56 +08:00
|
|
|
|
|
|
|
pugiext::query_attribute(frameXML, A_SCALE_X, &frameData->scaleX);
|
|
|
|
pugiext::query_attribute(frameXML, A_SCALE_Y, &frameData->scaleY);
|
|
|
|
pugiext::query_attribute(frameXML, A_SKEW_X, &frameData->skewX, degrees2radius);
|
|
|
|
pugiext::query_attribute(frameXML, A_SKEW_Y, &frameData->skewY, degrees2radius);
|
|
|
|
pugiext::query_attribute(frameXML, A_DURATION, &frameData->duration);
|
|
|
|
pugiext::query_attribute(frameXML, A_DISPLAY_INDEX, &frameData->displayIndex);
|
|
|
|
pugiext::query_attribute(frameXML, A_Z, &frameData->zOrder);
|
|
|
|
pugiext::query_attribute(frameXML, A_TWEEN_ROTATE, &frameData->tweenRotate);
|
|
|
|
|
|
|
|
if (pugiext::query_attribute(frameXML, A_BLEND_TYPE, &blendType))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
switch (blendType)
|
|
|
|
{
|
|
|
|
case BLEND_NORMAL:
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
frameData->blendFunc = BlendFunc::ALPHA_PREMULTIPLIED;
|
|
|
|
}
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
case BLEND_ADD:
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
frameData->blendFunc.src = backend::BlendFactor::SRC_ALPHA;
|
|
|
|
frameData->blendFunc.dst = backend::BlendFactor::ONE;
|
|
|
|
}
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
case BLEND_MULTIPLY:
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
frameData->blendFunc.src = backend::BlendFactor::DST_COLOR;
|
|
|
|
frameData->blendFunc.dst = backend::BlendFactor::ONE_MINUS_SRC_ALPHA;
|
|
|
|
}
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
case BLEND_SCREEN:
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
|
|
|
frameData->blendFunc.src = backend::BlendFactor::ONE;
|
|
|
|
frameData->blendFunc.dst = backend::BlendFactor::ONE_MINUS_SRC_COLOR;
|
|
|
|
}
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
default:
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
frameData->blendFunc.src = AX_BLEND_SRC;
|
|
|
|
frameData->blendFunc.dst = AX_BLEND_DST;
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_node colorTransformXML = frameXML.child(A_COLOR_TRANSFORM);
|
2019-11-23 20:27:39 +08:00
|
|
|
if (colorTransformXML)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
int alpha, red, green, blue = 100;
|
2019-11-23 20:27:39 +08:00
|
|
|
int alphaOffset, redOffset, greenOffset, blueOffset = 0;
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(colorTransformXML, A_ALPHA, &alpha);
|
|
|
|
pugiext::query_attribute(colorTransformXML, A_RED, &red);
|
|
|
|
pugiext::query_attribute(colorTransformXML, A_GREEN, &green);
|
2021-12-25 10:04:45 +08:00
|
|
|
pugiext::query_attribute(colorTransformXML, A_BLUE, &blue);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(colorTransformXML, A_ALPHA_OFFSET, &alphaOffset);
|
|
|
|
pugiext::query_attribute(colorTransformXML, A_RED_OFFSET, &redOffset);
|
|
|
|
pugiext::query_attribute(colorTransformXML, A_GREEN_OFFSET, &greenOffset);
|
2021-12-25 10:04:45 +08:00
|
|
|
pugiext::query_attribute(colorTransformXML, A_BLUE_OFFSET, &blueOffset);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
const char* _easing = nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (pugiext::query_attribute(frameXML, A_TWEEN_EASING, &_easing))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (strcmp(_easing, FL_NAN) != 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
tweenEasing = atoi(_easing);
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->tweenEasing =
|
2022-08-08 18:02:17 +08:00
|
|
|
tweenEasing == 2 ? ax::tweenfunc::Sine_EaseInOut : (ax::tweenfunc::TweenType)tweenEasing;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
frameData->tweenEasing = ax::tweenfunc::Linear;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (parentFrameXml)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
/*
|
2021-12-25 10:04:45 +08:00
|
|
|
* recalculate frame data from parent frame data, use for translate matrix
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
BaseData helpNode;
|
|
|
|
if (dataInfo->flashToolVersion >= VERSION_2_0)
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(parentFrameXml, A_COCOS2DX_X, &helpNode.x);
|
|
|
|
pugiext::query_attribute(parentFrameXml, A_COCOS2DX_Y, &helpNode.y);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(parentFrameXml, A_X, &helpNode.x);
|
|
|
|
pugiext::query_attribute(parentFrameXml, A_Y, &helpNode.y);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(parentFrameXml, A_SKEW_X, &helpNode.skewX);
|
|
|
|
pugiext::query_attribute(parentFrameXml, A_SKEW_Y, &helpNode.skewY);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
helpNode.y = -helpNode.y;
|
2022-07-16 10:43:05 +08:00
|
|
|
helpNode.skewX = AX_DEGREES_TO_RADIANS(helpNode.skewX);
|
|
|
|
helpNode.skewY = AX_DEGREES_TO_RADIANS(-helpNode.skewY);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
TransformHelp::transformFromParent(*frameData, helpNode);
|
|
|
|
}
|
|
|
|
return frameData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
TextureData* DataReaderHelper::decodeTexture(pugi::xml_node& textureXML, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
TextureData* textureData = new TextureData();
|
2019-11-23 20:27:39 +08:00
|
|
|
textureData->init();
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(textureXML, A_NAME, &textureData->name);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
float px, py, width, height = 0;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (dataInfo->flashToolVersion >= VERSION_2_0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(textureXML, A_COCOS2D_PIVOT_X, &px);
|
|
|
|
pugiext::query_attribute(textureXML, A_COCOS2D_PIVOT_Y, &py);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(textureXML, A_PIVOT_X, &px);
|
|
|
|
pugiext::query_attribute(textureXML, A_PIVOT_Y, &py);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(textureXML, A_WIDTH, &width);
|
|
|
|
pugiext::query_attribute(textureXML, A_HEIGHT, &height);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
float anchorPointX = px / width;
|
|
|
|
float anchorPointY = (height - py) / height;
|
|
|
|
|
|
|
|
textureData->pivotX = anchorPointX;
|
|
|
|
textureData->pivotY = anchorPointY;
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_node contourXML = textureXML.child(CONTOUR);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
while (contourXML)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ContourData* contourData = decodeContour(contourXML, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
textureData->addContourData(contourData);
|
|
|
|
contourData->release();
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
contourXML = contourXML.next_sibling(CONTOUR);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return textureData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ContourData* DataReaderHelper::decodeContour(pugi::xml_node& contourXML, DataInfo* /*dataInfo*/)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ContourData* contourData = new ContourData();
|
2019-11-23 20:27:39 +08:00
|
|
|
contourData->init();
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugi::xml_node vertexDataXML = contourXML.child(CONTOUR_VERTEX);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
while (vertexDataXML)
|
|
|
|
{
|
|
|
|
Vec2 vertex;
|
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
pugiext::query_attribute(vertexDataXML, A_X, &vertex.x);
|
|
|
|
pugiext::query_attribute(vertexDataXML, A_Y, &vertex.y);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
vertex.y = -vertex.y;
|
2022-08-09 09:54:53 +08:00
|
|
|
contourData->vertexList.emplace_back(vertex);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2019-11-24 23:15:56 +08:00
|
|
|
vertexDataXML = vertexDataXML.next_sibling(CONTOUR_VERTEX);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return contourData;
|
|
|
|
}
|
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void DataReaderHelper::addDataFromJsonCache(std::string_view fileContent, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
rapidjson::Document json;
|
2021-12-31 12:12:40 +08:00
|
|
|
rapidjson::StringStream stream(fileContent.data());
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (fileContent.size() >= 3)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
// Skip BOM if exists
|
2021-12-31 12:12:40 +08:00
|
|
|
const unsigned char* c = (const unsigned char*)fileContent.data();
|
2021-12-25 10:04:45 +08:00
|
|
|
unsigned bom = c[0] | (c[1] << 8) | (c[2] << 16);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (bom == 0xBFBBEF) // UTF8 BOM
|
|
|
|
{
|
|
|
|
stream.Take();
|
|
|
|
stream.Take();
|
|
|
|
stream.Take();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
json.ParseStream<0>(stream);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (json.HasParseError())
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("GetParseError %d\n", json.GetParseError());
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
dataInfo->contentScale = DICTOOL->getFloatValue_json(json, CONTENT_SCALE, 1.0f);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// Decode armatures
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, ARMATURE_DATA);
|
|
|
|
for (int i = 0; i < length; i++)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& armatureDic = DICTOOL->getSubDictionary_json(json, ARMATURE_DATA, i);
|
|
|
|
ArmatureData* armatureData = decodeArmature(armatureDic, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
|
|
|
}
|
|
|
|
ArmatureDataManager::getInstance()->addArmatureData(armatureData->name, armatureData, dataInfo->filename);
|
|
|
|
armatureData->release();
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode animations
|
2021-12-25 10:04:45 +08:00
|
|
|
length = DICTOOL->getArrayCount_json(
|
|
|
|
json, ANIMATION_DATA); // json[ANIMATION_DATA].IsNull() ? 0 : json[ANIMATION_DATA].Size();
|
2019-11-23 20:27:39 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& animationDic = DICTOOL->getSubDictionary_json(json, ANIMATION_DATA, i);
|
|
|
|
AnimationData* animationData = decodeAnimation(animationDic, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
|
|
|
}
|
|
|
|
ArmatureDataManager::getInstance()->addAnimationData(animationData->name, animationData, dataInfo->filename);
|
|
|
|
animationData->release();
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Decode textures
|
|
|
|
length = DICTOOL->getArrayCount_json(json, TEXTURE_DATA);
|
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& textureDic = DICTOOL->getSubDictionary_json(json, TEXTURE_DATA, i);
|
|
|
|
TextureData* textureData = decodeTexture(textureDic);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
|
|
|
}
|
|
|
|
ArmatureDataManager::getInstance()->addTextureData(textureData->name, textureData, dataInfo->filename);
|
|
|
|
textureData->release();
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auto load sprite file
|
2021-12-25 10:04:45 +08:00
|
|
|
bool autoLoad = dataInfo->asyncStruct == nullptr ? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile()
|
|
|
|
: dataInfo->asyncStruct->autoLoadSpriteFile;
|
2019-11-23 20:27:39 +08:00
|
|
|
if (autoLoad)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
length = DICTOOL->getArrayCount_json(
|
|
|
|
json, CONFIG_FILE_PATH); // json[CONFIG_FILE_PATH].IsNull() ? 0 : json[CONFIG_FILE_PATH].Size();
|
2019-11-23 20:27:39 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* path = DICTOOL->getStringValueFromArray_json(
|
|
|
|
json, CONFIG_FILE_PATH,
|
|
|
|
i); // json[CONFIG_FILE_PATH][i].IsNull() ? nullptr : json[CONFIG_FILE_PATH][i].GetString();
|
2019-11-23 20:27:39 +08:00
|
|
|
if (path == nullptr)
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("load CONFIG_FILE_PATH error.");
|
2019-11-23 20:27:39 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string filePath = path;
|
2021-12-25 10:04:45 +08:00
|
|
|
filePath = filePath.erase(filePath.find_last_of('.'));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
dataInfo->configFileQueue.push(filePath);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::string plistPath = filePath + ".plist";
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string pngPath = filePath + ".png";
|
|
|
|
if (FileUtils::getInstance()->isFileExist(dataInfo->baseFilePath + plistPath) &&
|
|
|
|
FileUtils::getInstance()->isFileExist(dataInfo->baseFilePath + pngPath))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(dataInfo->baseFilePath + plistPath);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (dict.find("particleLifespan") != dict.end())
|
|
|
|
continue;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureDataManager::getInstance()->addSpriteFrameFromFile(
|
|
|
|
(dataInfo->baseFilePath + plistPath), (dataInfo->baseFilePath + pngPath), dataInfo->filename);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureData* DataReaderHelper::decodeArmature(const rapidjson::Value& json, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureData* armatureData = new ArmatureData();
|
2019-11-23 20:27:39 +08:00
|
|
|
armatureData->init();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* name = DICTOOL->getStringValue_json(json, A_NAME);
|
|
|
|
if (name != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
armatureData->name = name;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
dataInfo->cocoStudioVersion = armatureData->dataVersion = DICTOOL->getFloatValue_json(json, VERSION, 0.1f);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, BONE_DATA, 0);
|
2019-11-23 20:27:39 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(json, BONE_DATA, i); // json[BONE_DATA][i];
|
|
|
|
BoneData* boneData = decodeBone(dic, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
armatureData->addBoneData(boneData);
|
|
|
|
boneData->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
return armatureData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
BoneData* DataReaderHelper::decodeBone(const rapidjson::Value& json, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
BoneData* boneData = new BoneData();
|
2019-11-23 20:27:39 +08:00
|
|
|
boneData->init();
|
|
|
|
|
|
|
|
decodeNode(boneData, json, dataInfo);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* str = DICTOOL->getStringValue_json(json, A_NAME);
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
boneData->name = str;
|
|
|
|
}
|
|
|
|
|
|
|
|
str = DICTOOL->getStringValue_json(json, A_PARENT);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
boneData->parentName = str;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, DISPLAY_DATA);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(json, DISPLAY_DATA, i);
|
|
|
|
DisplayData* displayData = decodeBoneDisplay(dic, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
boneData->addDisplayData(displayData);
|
|
|
|
displayData->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
return boneData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
DisplayData* DataReaderHelper::decodeBoneDisplay(const rapidjson::Value& json, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
DisplayType displayType = (DisplayType)(DICTOOL->getIntValue_json(json, A_DISPLAY_TYPE, CS_DISPLAY_SPRITE));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
DisplayData* displayData = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
switch (displayType)
|
|
|
|
{
|
|
|
|
case CS_DISPLAY_SPRITE:
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
displayData = new SpriteDisplayData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* name = DICTOOL->getStringValue_json(json, A_NAME);
|
|
|
|
if (name != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
((SpriteDisplayData*)displayData)->displayName = name;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
if (json.HasMember(SKIN_DATA))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& dicArray = DICTOOL->getSubDictionary_json(json, SKIN_DATA);
|
|
|
|
if (!dicArray.IsNull())
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
rapidjson::SizeType index = 0;
|
|
|
|
const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(dicArray, index);
|
2019-11-23 20:27:39 +08:00
|
|
|
if (!dic.IsNull())
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
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);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
sdd->skinData.x *= dataInfo->contentScale;
|
|
|
|
sdd->skinData.y *= dataInfo->contentScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case CS_DISPLAY_ARMATURE:
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
displayData = new ArmatureDisplayData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* name = DICTOOL->getStringValue_json(json, A_NAME);
|
|
|
|
if (name != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
((ArmatureDisplayData*)displayData)->displayName = name;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CS_DISPLAY_PARTICLE:
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
displayData = new ParticleDisplayData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* plist = DICTOOL->getStringValue_json(json, A_PLIST);
|
|
|
|
if (plist != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
static_cast<ParticleDisplayData*>(displayData)->displayName =
|
|
|
|
dataInfo->asyncStruct->baseFilePath + plist;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
static_cast<ParticleDisplayData*>(displayData)->displayName = dataInfo->baseFilePath + plist;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2021-12-08 00:11:53 +08:00
|
|
|
displayData = new SpriteDisplayData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
displayData->displayType = displayType;
|
|
|
|
|
|
|
|
return displayData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
AnimationData* DataReaderHelper::decodeAnimation(const rapidjson::Value& json, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
AnimationData* aniData = new AnimationData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* name = DICTOOL->getStringValue_json(json, A_NAME);
|
|
|
|
if (name != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
aniData->name = name;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, MOVEMENT_DATA);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(json, MOVEMENT_DATA, i);
|
|
|
|
MovementData* movementData = decodeMovement(dic, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
aniData->addMovement(movementData);
|
|
|
|
movementData->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
return aniData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementData* DataReaderHelper::decodeMovement(const rapidjson::Value& json, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementData* movementData = new MovementData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +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);
|
2019-11-23 20:27:39 +08:00
|
|
|
if (!DICTOOL->checkObjectExist_json(json, A_DURATION))
|
|
|
|
{
|
|
|
|
movementData->scale = 1.0f;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
movementData->scale = DICTOOL->getFloatValue_json(json, A_MOVEMENT_SCALE, 1.0f);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
movementData->tweenEasing =
|
2022-08-08 18:02:17 +08:00
|
|
|
(TweenType)(DICTOOL->getIntValue_json(json, A_TWEEN_EASING, ax::tweenfunc::Linear));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* name = DICTOOL->getStringValue_json(json, A_NAME);
|
|
|
|
if (name != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
movementData->name = name;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, MOVEMENT_BONE_DATA);
|
2019-11-23 20:27:39 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(json, MOVEMENT_BONE_DATA, i);
|
|
|
|
MovementBoneData* movementBoneData = decodeMovementBone(dic, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
movementData->addMovementBoneData(movementBoneData);
|
|
|
|
movementBoneData->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
return movementData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementBoneData* DataReaderHelper::decodeMovementBone(const rapidjson::Value& json, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementBoneData* movementBoneData = new MovementBoneData();
|
2019-11-23 20:27:39 +08:00
|
|
|
movementBoneData->init();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
movementBoneData->delay = DICTOOL->getFloatValue_json(json, A_MOVEMENT_DELAY);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* name = DICTOOL->getStringValue_json(json, A_NAME);
|
|
|
|
if (name != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
movementBoneData->name = name;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
rapidjson::SizeType length = DICTOOL->getArrayCount_json(json, FRAME_DATA);
|
2019-11-23 20:27:39 +08:00
|
|
|
for (rapidjson::SizeType i = 0; i < length; i++)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(json, FRAME_DATA, i);
|
|
|
|
FrameData* frameData = decodeFrame(dic, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
movementBoneData->addFrameData(frameData);
|
|
|
|
frameData->release();
|
|
|
|
|
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
|
|
|
{
|
|
|
|
frameData->frameID = movementBoneData->duration;
|
|
|
|
movementBoneData->duration += frameData->duration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE)
|
|
|
|
{
|
|
|
|
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
|
|
|
|
auto frames = movementBoneData->frameList;
|
|
|
|
for (long i = frames.size() - 1; i >= 0; i--)
|
|
|
|
{
|
|
|
|
if (i > 0)
|
|
|
|
{
|
|
|
|
float difSkewX = frames.at(i)->skewX - frames.at(i - 1)->skewX;
|
|
|
|
float difSkewY = frames.at(i)->skewY - frames.at(i - 1)->skewY;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (difSkewX < -M_PI || difSkewX > M_PI)
|
|
|
|
{
|
|
|
|
frames.at(i - 1)->skewX =
|
|
|
|
difSkewX < 0 ? frames.at(i - 1)->skewX - 2 * M_PI : frames.at(i - 1)->skewX + 2 * M_PI;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (difSkewY < -M_PI || difSkewY > M_PI)
|
|
|
|
{
|
|
|
|
frames.at(i - 1)->skewY =
|
|
|
|
difSkewY < 0 ? frames.at(i - 1)->skewY - 2 * M_PI : frames.at(i - 1)->skewY + 2 * M_PI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
|
|
|
{
|
|
|
|
if (movementBoneData->frameList.size() > 0)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
FrameData* frameData = new FrameData();
|
|
|
|
frameData->copy((FrameData*)movementBoneData->frameList.back());
|
2019-11-23 20:27:39 +08:00
|
|
|
movementBoneData->addFrameData(frameData);
|
|
|
|
frameData->release();
|
|
|
|
|
|
|
|
frameData->frameID = movementBoneData->duration;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return movementBoneData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
FrameData* DataReaderHelper::decodeFrame(const rapidjson::Value& json, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
FrameData* frameData = new FrameData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
decodeNode(frameData, json, dataInfo);
|
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
frameData->tweenEasing = (TweenType)(DICTOOL->getIntValue_json(json, A_TWEEN_EASING, ax::tweenfunc::Linear));
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->displayIndex = DICTOOL->getIntValue_json(json, A_DISPLAY_INDEX);
|
|
|
|
frameData->blendFunc.src = utils::toBackendBlendFactor(
|
|
|
|
DICTOOL->getIntValue_json(json, A_BLEND_SRC, utils::toGLBlendFactor(BlendFunc::ALPHA_PREMULTIPLIED.src)));
|
|
|
|
frameData->blendFunc.dst = utils::toBackendBlendFactor(
|
|
|
|
DICTOOL->getIntValue_json(json, A_BLEND_DST, utils::toGLBlendFactor(BlendFunc::ALPHA_PREMULTIPLIED.dst)));
|
|
|
|
frameData->isTween = DICTOOL->getBooleanValue_json(json, A_TWEEN_FRAME, true);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* event = DICTOOL->getStringValue_json(json, A_EVENT);
|
2019-11-23 20:27:39 +08:00
|
|
|
if (event != nullptr)
|
|
|
|
{
|
|
|
|
frameData->strEvent = event;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->duration = DICTOOL->getIntValue_json(json, A_DURATION, 1);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
frameData->frameID = DICTOOL->getIntValue_json(json, A_FRAME_INDEX);
|
|
|
|
}
|
|
|
|
|
|
|
|
int length = DICTOOL->getArrayCount_json(json, A_EASING_PARAM);
|
|
|
|
if (length != 0)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->easingParams = new float[length];
|
2019-11-23 20:27:39 +08:00
|
|
|
frameData->easingParamNumber = length;
|
|
|
|
|
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
|
|
|
frameData->easingParams[i] = DICTOOL->getFloatValueFromArray_json(json, A_EASING_PARAM, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return frameData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
TextureData* DataReaderHelper::decodeTexture(const rapidjson::Value& json)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
TextureData* textureData = new TextureData();
|
2019-11-23 20:27:39 +08:00
|
|
|
textureData->init();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* name = DICTOOL->getStringValue_json(json, A_NAME);
|
|
|
|
if (name != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
textureData->name = name;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
textureData->width = DICTOOL->getFloatValue_json(json, A_WIDTH);
|
2019-11-23 20:27:39 +08:00
|
|
|
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);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, CONTOUR_DATA);
|
2019-11-23 20:27:39 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(json, CONTOUR_DATA, i);
|
|
|
|
ContourData* contourData = decodeContour(dic);
|
2019-11-23 20:27:39 +08:00
|
|
|
textureData->contourDataList.pushBack(contourData);
|
|
|
|
contourData->release();
|
|
|
|
}
|
|
|
|
|
|
|
|
return textureData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ContourData* DataReaderHelper::decodeContour(const rapidjson::Value& json)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ContourData* contourData = new ContourData();
|
|
|
|
contourData->init();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = DICTOOL->getArrayCount_json(json, VERTEX_POINT);
|
2019-11-23 20:27:39 +08:00
|
|
|
for (int i = length - 1; i >= 0; i--)
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(json, VERTEX_POINT, i);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
Vec2 vertex;
|
|
|
|
|
|
|
|
vertex.x = DICTOOL->getFloatValue_json(dic, A_X);
|
|
|
|
vertex.y = DICTOOL->getFloatValue_json(dic, A_Y);
|
|
|
|
|
2022-08-09 09:54:53 +08:00
|
|
|
contourData->vertexList.emplace_back(vertex);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return contourData;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void DataReaderHelper::decodeNode(BaseData* node, const rapidjson::Value& json, DataInfo* dataInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
node->x = DICTOOL->getFloatValue_json(json, A_X) * s_PositionReadScale;
|
|
|
|
node->y = DICTOOL->getFloatValue_json(json, A_Y) * s_PositionReadScale;
|
|
|
|
|
|
|
|
node->x *= dataInfo->contentScale;
|
|
|
|
node->y *= dataInfo->contentScale;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
node->zOrder = DICTOOL->getIntValue_json(json, A_Z);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
node->skewX = DICTOOL->getFloatValue_json(json, A_SKEW_X);
|
|
|
|
node->skewY = DICTOOL->getFloatValue_json(json, A_SKEW_Y);
|
2019-11-23 20:27:39 +08:00
|
|
|
node->scaleX = DICTOOL->getFloatValue_json(json, A_SCALE_X, 1.0f);
|
|
|
|
node->scaleY = DICTOOL->getFloatValue_json(json, A_SCALE_Y, 1.0f);
|
|
|
|
|
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COLOR_READING)
|
|
|
|
{
|
|
|
|
if (DICTOOL->checkObjectExist_json(json, 0))
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
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);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
node->isUseColorInfo = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (DICTOOL->checkObjectExist_json(json, COLOR_INFO))
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const rapidjson::Value& colorDic =
|
|
|
|
DICTOOL->getSubDictionary_json(json, COLOR_INFO); // json.getSubDictionary(COLOR_INFO);
|
2019-11-23 20:27:39 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void DataReaderHelper::addDataFromBinaryCache(const char* fileContent, DataInfo* dataInfo)
|
|
|
|
{
|
|
|
|
CocoLoader tCocoLoader;
|
|
|
|
if (tCocoLoader.ReadCocoBinBuff((char*)fileContent))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
stExpCocoNode* tpRootCocoNode = tCocoLoader.GetRootCocoNode();
|
|
|
|
rapidjson::Type tType = tpRootCocoNode->GetType(&tCocoLoader);
|
|
|
|
if (rapidjson::kObjectType == tType)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
stExpCocoNode* tpChildArray = tpRootCocoNode->GetChildArray(&tCocoLoader);
|
|
|
|
int nCount = tpRootCocoNode->GetChildNum();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
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)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string value = tpChildArray[i].GetValue(&tCocoLoader);
|
2021-12-31 15:49:45 +08:00
|
|
|
dataInfo->contentScale = utils::atof(value.data());
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (0 == key.compare(ARMATURE_DATA))
|
|
|
|
{
|
|
|
|
pDataArray = tpChildArray[i].GetChildArray(&tCocoLoader);
|
|
|
|
length = tpChildArray[i].GetChildNum();
|
|
|
|
ArmatureData* armatureData;
|
|
|
|
for (int ii = 0; ii < length; ++ii)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
armatureData = decodeArmature(&tCocoLoader, &pDataArray[ii], dataInfo);
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
|
|
|
}
|
|
|
|
ArmatureDataManager::getInstance()->addArmatureData(armatureData->name, armatureData,
|
|
|
|
dataInfo->filename);
|
|
|
|
armatureData->release();
|
|
|
|
if (dataInfo->asyncStruct)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (0 == key.compare(ANIMATION_DATA))
|
|
|
|
{
|
|
|
|
pDataArray = tpChildArray[i].GetChildArray(&tCocoLoader);
|
|
|
|
length = tpChildArray[i].GetChildNum();
|
|
|
|
AnimationData* animationData;
|
|
|
|
for (int ii = 0; ii < length; ++ii)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
animationData = decodeAnimation(&tCocoLoader, &pDataArray[ii], dataInfo);
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
|
|
|
}
|
|
|
|
ArmatureDataManager::getInstance()->addAnimationData(animationData->name, animationData,
|
|
|
|
dataInfo->filename);
|
|
|
|
animationData->release();
|
|
|
|
if (dataInfo->asyncStruct)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(TEXTURE_DATA) == 0)
|
|
|
|
{
|
|
|
|
pDataArray = tpChildArray[i].GetChildArray(&tCocoLoader);
|
|
|
|
length = tpChildArray[i].GetChildNum();
|
|
|
|
for (int ii = 0; ii < length; ++ii)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
TextureData* textureData = decodeTexture(&tCocoLoader, &pDataArray[ii]);
|
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
_dataReaderHelper->_addDataMutex.lock();
|
|
|
|
}
|
|
|
|
ArmatureDataManager::getInstance()->addTextureData(textureData->name, textureData,
|
|
|
|
dataInfo->filename);
|
|
|
|
textureData->release();
|
|
|
|
if (dataInfo->asyncStruct)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
_dataReaderHelper->_addDataMutex.unlock();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
// Auto losprite file
|
|
|
|
bool autoLoad = dataInfo->asyncStruct == nullptr
|
|
|
|
? ArmatureDataManager::getInstance()->isAutoLoadSpriteFile()
|
|
|
|
: dataInfo->asyncStruct->autoLoadSpriteFile;
|
|
|
|
if (autoLoad)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < nCount; ++i)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
key = tpChildArray[i].GetName(&tCocoLoader);
|
|
|
|
if (0 != key.compare(CONFIG_FILE_PATH))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
length = tpChildArray[i].GetChildNum();
|
|
|
|
stExpCocoNode* pConfigFilePath = tpChildArray[i].GetChildArray(&tCocoLoader);
|
|
|
|
for (int ii = 0; ii < length; ii++)
|
|
|
|
{
|
|
|
|
const char* path = pConfigFilePath[ii].GetValue(&tCocoLoader);
|
|
|
|
if (path == nullptr)
|
|
|
|
{
|
2022-07-16 10:43:05 +08:00
|
|
|
AXLOG("load CONFIG_FILE_PATH error.");
|
2021-12-25 10:04:45 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string filePath = path;
|
|
|
|
filePath = filePath.erase(filePath.find_last_of('.'));
|
|
|
|
|
|
|
|
if (dataInfo->asyncStruct)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
dataInfo->configFileQueue.push(filePath);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string plistPath = filePath + ".plist";
|
|
|
|
std::string pngPath = filePath + ".png";
|
|
|
|
|
|
|
|
ArmatureDataManager::getInstance()->addSpriteFrameFromFile(
|
|
|
|
(dataInfo->baseFilePath + plistPath), (dataInfo->baseFilePath + pngPath),
|
|
|
|
dataInfo->filename);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureData* DataReaderHelper::decodeArmature(CocoLoader* cocoLoader, stExpCocoNode* cocoNode, DataInfo* dataInfo)
|
|
|
|
{
|
|
|
|
ArmatureData* armatureData = new ArmatureData();
|
|
|
|
armatureData->init();
|
|
|
|
stExpCocoNode* pAramtureDataArray = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
const char* name = pAramtureDataArray[2].GetValue(cocoLoader); // DICTOOL->getStringValue_json(json, A_NAME);
|
|
|
|
if (name != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
armatureData->name = name;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
float version = utils::atof(pAramtureDataArray[1].GetValue(cocoLoader));
|
|
|
|
dataInfo->cocoStudioVersion = armatureData->dataVersion =
|
|
|
|
version; // DICTOOL->getFloatValue_json(json, VERSION, 0.1f);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = pAramtureDataArray[3].GetChildNum(); // DICTOOL->getArrayCount_json(json, BONE_DATA, 0);
|
|
|
|
stExpCocoNode* pBoneChildren = pAramtureDataArray[3].GetChildArray(cocoLoader);
|
|
|
|
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];
|
|
|
|
BoneData* boneData = decodeBone(cocoLoader, child, dataInfo);
|
|
|
|
armatureData->addBoneData(boneData);
|
|
|
|
boneData->release();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
return armatureData;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
BoneData* DataReaderHelper::decodeBone(CocoLoader* cocoLoader, stExpCocoNode* cocoNode, DataInfo* dataInfo)
|
|
|
|
{
|
|
|
|
BoneData* boneData = new BoneData();
|
|
|
|
boneData->init();
|
|
|
|
|
|
|
|
decodeNode(boneData, cocoLoader, cocoNode, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
|
|
|
stExpCocoNode* pBoneChildren = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
stExpCocoNode* child;
|
|
|
|
const char* str = nullptr;
|
|
|
|
std::string key;
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
child = &pBoneChildren[i];
|
|
|
|
key = child->GetName(cocoLoader);
|
|
|
|
str = child->GetValue(cocoLoader);
|
|
|
|
if (key.compare(A_NAME) == 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
// DICTOOL->getStringValue_json(json, A_NAME);
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
boneData->name = str;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_PARENT) == 0)
|
|
|
|
{
|
|
|
|
// DICTOOL->getStringValue_json(json, A_PARENT);
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
boneData->parentName = str;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(DISPLAY_DATA) == 0)
|
|
|
|
{
|
|
|
|
int count = child->GetChildNum();
|
|
|
|
stExpCocoNode* pDisplayData = child->GetChildArray(cocoLoader);
|
|
|
|
for (int ii = 0; ii < count; ++ii)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
DisplayData* displayData = decodeBoneDisplay(cocoLoader, &pDisplayData[ii], dataInfo);
|
|
|
|
if (displayData == nullptr)
|
|
|
|
continue;
|
|
|
|
boneData->addDisplayData(displayData);
|
|
|
|
displayData->release();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
return boneData;
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayData* DataReaderHelper::decodeBoneDisplay(CocoLoader* cocoLoader, stExpCocoNode* cocoNode, DataInfo* dataInfo)
|
|
|
|
{
|
|
|
|
stExpCocoNode* children = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
stExpCocoNode* child = &children[1];
|
|
|
|
|
|
|
|
std::string key = child->GetName(cocoLoader);
|
|
|
|
const char* str = child->GetValue(cocoLoader);
|
|
|
|
DisplayData* displayData = nullptr;
|
|
|
|
if (key.compare(A_DISPLAY_TYPE) == 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
str = child->GetValue(cocoLoader);
|
|
|
|
DisplayType displayType = (DisplayType)(atoi(str));
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = 0;
|
|
|
|
switch (displayType)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
case CS_DISPLAY_SPRITE:
|
|
|
|
{
|
|
|
|
displayData = new SpriteDisplayData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* name = children[0].GetValue(cocoLoader);
|
|
|
|
if (name != nullptr)
|
|
|
|
{
|
|
|
|
((SpriteDisplayData*)displayData)->displayName = name;
|
|
|
|
}
|
|
|
|
stExpCocoNode* pSkinDataArray = children[2].GetChildArray(cocoLoader);
|
|
|
|
if (pSkinDataArray != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
stExpCocoNode* pSkinData = &pSkinDataArray[0];
|
|
|
|
if (pSkinData != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
SpriteDisplayData* sdd = (SpriteDisplayData*)displayData;
|
|
|
|
length = pSkinData->GetChildNum();
|
|
|
|
stExpCocoNode* SkinDataValue = pSkinData->GetChildArray(cocoLoader);
|
|
|
|
for (int i = 0; i < length; ++i)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
key = SkinDataValue[i].GetName(cocoLoader);
|
|
|
|
str = SkinDataValue[i].GetValue(cocoLoader);
|
|
|
|
if (key.compare(A_X) == 0)
|
|
|
|
{
|
|
|
|
sdd->skinData.x = utils::atof(str) * s_PositionReadScale;
|
|
|
|
}
|
|
|
|
else if (key.compare(A_Y) == 0)
|
|
|
|
{
|
|
|
|
sdd->skinData.y = utils::atof(str) * s_PositionReadScale;
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SCALE_X) == 0)
|
|
|
|
{
|
|
|
|
sdd->skinData.scaleX = utils::atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SCALE_Y) == 0)
|
|
|
|
{
|
|
|
|
sdd->skinData.scaleY = utils::atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SKEW_X) == 0)
|
|
|
|
{
|
|
|
|
sdd->skinData.skewX = utils::atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SKEW_Y) == 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
sdd->skinData.skewY = utils::atof(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
sdd->skinData.x *= dataInfo->contentScale;
|
|
|
|
sdd->skinData.y *= dataInfo->contentScale;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
break;
|
|
|
|
case CS_DISPLAY_ARMATURE:
|
|
|
|
{
|
|
|
|
displayData = new ArmatureDisplayData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* name = cocoNode[0].GetValue(cocoLoader);
|
|
|
|
if (name != nullptr)
|
|
|
|
{
|
|
|
|
((ArmatureDisplayData*)displayData)->displayName = name;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case CS_DISPLAY_PARTICLE:
|
|
|
|
{
|
|
|
|
displayData = new ParticleDisplayData();
|
|
|
|
length = cocoNode->GetChildNum();
|
|
|
|
stExpCocoNode* pDisplayData = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
key = pDisplayData[i].GetName(cocoLoader);
|
|
|
|
str = pDisplayData[i].GetValue(cocoLoader);
|
|
|
|
if (key.compare(A_PLIST) == 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* plist = str;
|
|
|
|
if (plist != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (dataInfo->asyncStruct)
|
|
|
|
{
|
|
|
|
((ParticleDisplayData*)displayData)->displayName =
|
|
|
|
dataInfo->asyncStruct->baseFilePath + plist;
|
|
|
|
}
|
|
|
|
else
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
((ParticleDisplayData*)displayData)->displayName = dataInfo->baseFilePath + plist;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
displayData = new SpriteDisplayData();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
displayData->displayType = displayType;
|
|
|
|
}
|
|
|
|
return displayData;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
AnimationData* DataReaderHelper::decodeAnimation(CocoLoader* cocoLoader, stExpCocoNode* cocoNode, DataInfo* dataInfo)
|
|
|
|
{
|
|
|
|
AnimationData* aniData = new AnimationData();
|
|
|
|
|
|
|
|
int length = cocoNode->GetChildNum();
|
|
|
|
stExpCocoNode* pAnimationData = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
const char* str = nullptr;
|
|
|
|
std::string key;
|
|
|
|
stExpCocoNode* child;
|
|
|
|
MovementData* movementData;
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
child = &pAnimationData[i];
|
|
|
|
key = child->GetName(cocoLoader);
|
|
|
|
str = child->GetValue(cocoLoader);
|
|
|
|
if (key.compare(A_NAME) == 0)
|
|
|
|
{
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
aniData->name = str;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(MOVEMENT_DATA) == 0)
|
|
|
|
{
|
|
|
|
int movcount = child->GetChildNum();
|
|
|
|
stExpCocoNode* movArray = child->GetChildArray(cocoLoader);
|
|
|
|
for (int movnum = 0; movnum < movcount; movnum++)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
movementData = decodeMovement(cocoLoader, &movArray[movnum], dataInfo);
|
|
|
|
aniData->addMovement(movementData);
|
|
|
|
movementData->release();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
return aniData;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementData* DataReaderHelper::decodeMovement(CocoLoader* cocoLoader, stExpCocoNode* cocoNode, DataInfo* dataInfo)
|
|
|
|
{
|
|
|
|
MovementData* movementData = new MovementData();
|
|
|
|
movementData->scale = 1.0f;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
|
|
|
stExpCocoNode* pMoveDataArray = cocoNode->GetChildArray(cocoLoader);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const char* str = nullptr;
|
|
|
|
std::string key;
|
|
|
|
stExpCocoNode* child;
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
child = &pMoveDataArray[i];
|
|
|
|
key = child->GetName(cocoLoader);
|
|
|
|
str = child->GetValue(cocoLoader);
|
|
|
|
if (key.compare(A_NAME) == 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
movementData->name = str;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_LOOP) == 0)
|
|
|
|
{
|
|
|
|
movementData->loop = true;
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (strcmp("1", str) != 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
movementData->loop = false;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_DURATION_TWEEN) == 0)
|
|
|
|
{
|
|
|
|
movementData->durationTween = 0;
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
movementData->durationTween = atoi(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_DURATION_TO) == 0)
|
|
|
|
{
|
|
|
|
movementData->durationTo = 0;
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
movementData->durationTo = atoi(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_DURATION) == 0)
|
|
|
|
{
|
|
|
|
movementData->duration = 0;
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
movementData->duration = atoi(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_MOVEMENT_SCALE) == 0)
|
|
|
|
{
|
|
|
|
movementData->scale = 1.0;
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
movementData->scale = utils::atof(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_TWEEN_EASING) == 0)
|
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
movementData->tweenEasing = ax::tweenfunc::Linear;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
movementData->tweenEasing = (TweenType)(atoi(str));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(MOVEMENT_BONE_DATA) == 0)
|
|
|
|
{
|
|
|
|
int count = child->GetChildNum();
|
|
|
|
stExpCocoNode* pMoveBoneData = child->GetChildArray(cocoLoader);
|
|
|
|
MovementBoneData* movementBoneData;
|
|
|
|
for (int ii = 0; ii < count; ++ii)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
movementBoneData = decodeMovementBone(cocoLoader, &pMoveBoneData[ii], dataInfo);
|
|
|
|
movementData->addMovementBoneData(movementBoneData);
|
|
|
|
movementBoneData->release();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
return movementData;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementBoneData* DataReaderHelper::decodeMovementBone(CocoLoader* cocoLoader,
|
|
|
|
stExpCocoNode* cocoNode,
|
|
|
|
DataInfo* dataInfo)
|
|
|
|
{
|
|
|
|
MovementBoneData* movementBoneData = new MovementBoneData();
|
|
|
|
movementBoneData->init();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
|
|
|
stExpCocoNode* pMovementBoneDataArray = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
stExpCocoNode* movebonechild;
|
|
|
|
const char* str = nullptr;
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
movebonechild = &pMovementBoneDataArray[i];
|
|
|
|
std::string key = movebonechild->GetName(cocoLoader);
|
|
|
|
str = movebonechild->GetValue(cocoLoader);
|
|
|
|
if (key.compare(A_NAME) == 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
movementBoneData->name = str;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_MOVEMENT_DELAY) == 0)
|
|
|
|
{
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
movementBoneData->delay = utils::atof(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(FRAME_DATA) == 0)
|
|
|
|
{
|
|
|
|
int count = movebonechild->GetChildNum();
|
|
|
|
stExpCocoNode* pFrameDataArray = movebonechild->GetChildArray(cocoLoader);
|
|
|
|
for (int ii = 0; ii < count; ++ii)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
FrameData* frameData = decodeFrame(cocoLoader, &pFrameDataArray[ii], dataInfo);
|
|
|
|
movementBoneData->addFrameData(frameData);
|
|
|
|
frameData->release();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
|
|
|
{
|
|
|
|
frameData->frameID = movementBoneData->duration;
|
|
|
|
movementBoneData->duration += frameData->duration;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
const ssize_t framesizemusone = movementBoneData->frameList.size() - 1;
|
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_CHANGE_ROTATION_RANGE)
|
|
|
|
{
|
|
|
|
//! Change rotation range from (-180 -- 180) to (-infinity -- infinity)
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vector<FrameData*> frames = movementBoneData->frameList;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ssize_t imusone = 0;
|
|
|
|
ssize_t i = 0;
|
|
|
|
for (i = framesizemusone; i >= 0; i--)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (i > 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
imusone = i - 1;
|
|
|
|
float difSkewX = frames.at(i)->skewX - frames.at(imusone)->skewX;
|
|
|
|
float difSkewY = frames.at(i)->skewY - frames.at(imusone)->skewY;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
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;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
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;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
|
|
|
{
|
|
|
|
if (movementBoneData->frameList.size() > 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
auto frameData = movementBoneData->frameList.at(framesizemusone);
|
|
|
|
movementBoneData->addFrameData(frameData);
|
|
|
|
frameData->release();
|
|
|
|
frameData->frameID = movementBoneData->duration;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
return movementBoneData;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
FrameData* DataReaderHelper::decodeFrame(CocoLoader* cocoLoader, stExpCocoNode* cocoNode, DataInfo* dataInfo)
|
|
|
|
{
|
|
|
|
FrameData* frameData = new FrameData();
|
|
|
|
|
|
|
|
decodeNode(frameData, cocoLoader, cocoNode, dataInfo);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
|
|
|
stExpCocoNode* pFrameDataArray = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
const char* str = nullptr;
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
std::string key = pFrameDataArray[i].GetName(cocoLoader);
|
|
|
|
str = pFrameDataArray[i].GetValue(cocoLoader);
|
|
|
|
if (key.compare(A_TWEEN_EASING) == 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2022-08-08 18:02:17 +08:00
|
|
|
frameData->tweenEasing = ax::tweenfunc::Linear;
|
2021-12-25 10:04:45 +08:00
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->tweenEasing = (TweenType)(atoi(str));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_DISPLAY_INDEX) == 0)
|
|
|
|
{
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->displayIndex = atoi(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_BLEND_SRC) == 0)
|
|
|
|
{
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->blendFunc.src = utils::toBackendBlendFactor(atoi(str));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_BLEND_DST) == 0)
|
|
|
|
{
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->blendFunc.dst = utils::toBackendBlendFactor(atoi(str));
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_TWEEN_FRAME) == 0)
|
|
|
|
{
|
|
|
|
frameData->isTween = true;
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (strcmp("1", str) != 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->isTween = false;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_EVENT) == 0)
|
|
|
|
{
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->strEvent = str;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_DURATION) == 0)
|
|
|
|
{
|
|
|
|
if (dataInfo->cocoStudioVersion < VERSION_COMBINED)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->duration = 1;
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->duration = atoi(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_FRAME_INDEX) == 0)
|
|
|
|
{
|
|
|
|
if (dataInfo->cocoStudioVersion >= VERSION_COMBINED)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->frameID = atoi(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_EASING_PARAM) == 0)
|
|
|
|
{
|
|
|
|
int count = pFrameDataArray[i].GetChildNum();
|
|
|
|
if (count != 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->easingParams = new float[count];
|
|
|
|
stExpCocoNode* pFrameData = pFrameDataArray[i].GetChildArray(cocoLoader);
|
|
|
|
for (int ii = 0; ii < count; ++ii)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
str = pFrameData[ii].GetValue(cocoLoader);
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
frameData->easingParams[ii] = utils::atof(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
return frameData;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
TextureData* DataReaderHelper::decodeTexture(CocoLoader* cocoLoader, stExpCocoNode* cocoNode)
|
|
|
|
{
|
|
|
|
TextureData* textureData = new TextureData();
|
|
|
|
textureData->init();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (cocoNode == nullptr)
|
|
|
|
{
|
|
|
|
return textureData;
|
|
|
|
}
|
|
|
|
|
|
|
|
int length = cocoNode->GetChildNum();
|
|
|
|
stExpCocoNode* pTextureDataArray = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
const char* str = nullptr;
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
std::string key = pTextureDataArray[i].GetName(cocoLoader);
|
|
|
|
str = pTextureDataArray[i].GetValue(cocoLoader);
|
|
|
|
if (key.compare(A_NAME) == 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
textureData->name = str;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_WIDTH) == 0)
|
|
|
|
{
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
textureData->width = utils::atof(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_HEIGHT) == 0)
|
|
|
|
{
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
textureData->height = utils::atof(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_PIVOT_X) == 0)
|
|
|
|
{
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
textureData->pivotX = utils::atof(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(A_PIVOT_Y) == 0)
|
|
|
|
{
|
|
|
|
if (str != nullptr)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
textureData->pivotY = utils::atof(str);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
}
|
|
|
|
else if (key.compare(CONTOUR_DATA) == 0)
|
|
|
|
{
|
|
|
|
int count = pTextureDataArray[i].GetChildNum();
|
|
|
|
stExpCocoNode* pContourArray = pTextureDataArray[i].GetChildArray(cocoLoader);
|
|
|
|
for (int ii = 0; ii < count; ++ii)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ContourData* contourData = decodeContour(cocoLoader, &pContourArray[ii]);
|
|
|
|
textureData->contourDataList.pushBack(contourData);
|
|
|
|
contourData->release();
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
return textureData;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ContourData* DataReaderHelper::decodeContour(CocoLoader* cocoLoader, stExpCocoNode* cocoNode)
|
|
|
|
{
|
|
|
|
ContourData* contourData = new ContourData();
|
|
|
|
contourData->init();
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = cocoNode->GetChildNum();
|
|
|
|
stExpCocoNode* verTexPointArray = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
const char* str = nullptr;
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
std::string key = verTexPointArray[i].GetName(cocoLoader);
|
|
|
|
str = verTexPointArray[i].GetValue(cocoLoader);
|
|
|
|
if (key.compare(VERTEX_POINT) == 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
int count = verTexPointArray[i].GetChildNum();
|
|
|
|
stExpCocoNode* pVerTexPointArray = verTexPointArray[i].GetChildArray(cocoLoader);
|
|
|
|
stExpCocoNode* pVerTexPoint;
|
|
|
|
for (int ii = count - 1; ii >= 0; --ii)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
pVerTexPoint = pVerTexPointArray[ii].GetChildArray(cocoLoader);
|
|
|
|
Vec2 vertex;
|
|
|
|
vertex.x = utils::atof(pVerTexPoint[0].GetValue(cocoLoader));
|
|
|
|
vertex.y = utils::atof(pVerTexPoint[1].GetValue(cocoLoader));
|
2022-08-09 09:54:53 +08:00
|
|
|
contourData->vertexList.emplace_back(vertex);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
break;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
return contourData;
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void DataReaderHelper::decodeNode(BaseData* node, CocoLoader* cocoLoader, stExpCocoNode* cocoNode, DataInfo* dataInfo)
|
|
|
|
{
|
|
|
|
int length = cocoNode->GetChildNum();
|
|
|
|
stExpCocoNode* NodeArray = cocoNode->GetChildArray(cocoLoader);
|
|
|
|
const char* str = nullptr;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool isVersionL = dataInfo->cocoStudioVersion < VERSION_COLOR_READING;
|
|
|
|
stExpCocoNode* child;
|
|
|
|
for (int i = 0; i < length; ++i)
|
|
|
|
{
|
|
|
|
child = &NodeArray[i];
|
|
|
|
std::string key = child->GetName(cocoLoader);
|
|
|
|
str = child->GetValue(cocoLoader);
|
|
|
|
if (key.compare(A_X) == 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
node->x = utils::atof(str) * dataInfo->contentScale;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
else if (key.compare(A_Y) == 0)
|
|
|
|
{
|
|
|
|
node->y = utils::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 = utils::atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SKEW_Y) == 0)
|
|
|
|
{
|
|
|
|
node->skewY = utils::atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SCALE_X) == 0)
|
|
|
|
{
|
|
|
|
node->scaleX = utils::atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(A_SCALE_Y) == 0)
|
|
|
|
{
|
|
|
|
node->scaleY = utils::atof(str);
|
|
|
|
}
|
|
|
|
else if (key.compare(COLOR_INFO) == 0)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!isVersionL)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (child->GetType(cocoLoader) == rapidjson::kObjectType)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (child->GetChildNum() == 4)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
stExpCocoNode* ChildArray = child->GetChildArray(cocoLoader);
|
2019-11-23 20:27:39 +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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node->isUseColorInfo = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (isVersionL)
|
|
|
|
{
|
|
|
|
int colorcoount = NodeArray[0].GetChildNum();
|
|
|
|
if (colorcoount > 0)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (NodeArray[0].GetType(cocoLoader) == rapidjson::kObjectType)
|
|
|
|
{
|
|
|
|
if (NodeArray[0].GetChildNum() == 4)
|
|
|
|
{
|
|
|
|
stExpCocoNode* ChildArray = NodeArray[0].GetChildArray(cocoLoader);
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
node->isUseColorInfo = true;
|
|
|
|
}
|
|
|
|
}
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
} // namespace cocostudio
|