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
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CCDatas.h"
|
|
|
|
#include "CCTransformHelp.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
using namespace cocos2d;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
BaseData::BaseData()
|
|
|
|
: x(0.0f)
|
|
|
|
, y(0.0f)
|
|
|
|
, zOrder(0)
|
|
|
|
|
|
|
|
, skewX(0.0f)
|
|
|
|
, skewY(0.0f)
|
|
|
|
, scaleX(1.0f)
|
|
|
|
, scaleY(1.0f)
|
|
|
|
|
|
|
|
, tweenRotate(0.0f)
|
|
|
|
|
|
|
|
, isUseColorInfo(false)
|
|
|
|
, a(255)
|
|
|
|
, r(255)
|
|
|
|
, g(255)
|
|
|
|
, b(255)
|
2021-12-25 10:04:45 +08:00
|
|
|
{}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
BaseData::~BaseData() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void BaseData::copy(const BaseData* node)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
x = node->x;
|
|
|
|
y = node->y;
|
2019-11-23 20:27:39 +08:00
|
|
|
zOrder = node->zOrder;
|
|
|
|
|
|
|
|
scaleX = node->scaleX;
|
|
|
|
scaleY = node->scaleY;
|
2021-12-25 10:04:45 +08:00
|
|
|
skewX = node->skewX;
|
|
|
|
skewY = node->skewY;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
tweenRotate = node->tweenRotate;
|
|
|
|
|
|
|
|
isUseColorInfo = node->isUseColorInfo;
|
2021-12-25 10:04:45 +08:00
|
|
|
r = node->r;
|
|
|
|
g = node->g;
|
|
|
|
b = node->b;
|
|
|
|
a = node->a;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void BaseData::subtract(BaseData* from, BaseData* to, bool limit)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
x = to->x - from->x;
|
|
|
|
y = to->y - from->y;
|
2019-11-23 20:27:39 +08:00
|
|
|
scaleX = to->scaleX - from->scaleX;
|
|
|
|
scaleY = to->scaleY - from->scaleY;
|
2021-12-25 10:04:45 +08:00
|
|
|
skewX = to->skewX - from->skewX;
|
|
|
|
skewY = to->skewY - from->skewY;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (isUseColorInfo || from->isUseColorInfo || to->isUseColorInfo)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
a = to->a - from->a;
|
|
|
|
r = to->r - from->r;
|
|
|
|
g = to->g - from->g;
|
|
|
|
b = to->b - from->b;
|
|
|
|
|
|
|
|
isUseColorInfo = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
a = r = g = b = 0;
|
2019-11-23 20:27:39 +08:00
|
|
|
isUseColorInfo = false;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (limit)
|
|
|
|
{
|
2019-11-23 20:27:39 +08:00
|
|
|
if (skewX > M_PI)
|
|
|
|
{
|
|
|
|
skewX -= (float)CC_DOUBLE_PI;
|
|
|
|
}
|
|
|
|
if (skewX < -M_PI)
|
|
|
|
{
|
|
|
|
skewX += (float)CC_DOUBLE_PI;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (skewY > M_PI)
|
|
|
|
{
|
|
|
|
skewY -= (float)CC_DOUBLE_PI;
|
|
|
|
}
|
|
|
|
if (skewY < -M_PI)
|
|
|
|
{
|
|
|
|
skewY += (float)CC_DOUBLE_PI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (to->tweenRotate)
|
|
|
|
{
|
|
|
|
skewX += to->tweenRotate * M_PI * 2;
|
|
|
|
skewY -= to->tweenRotate * M_PI * 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void BaseData::setColor(const Color4B& color)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
r = color.r;
|
|
|
|
g = color.g;
|
|
|
|
b = color.b;
|
|
|
|
a = color.a;
|
|
|
|
}
|
|
|
|
|
|
|
|
Color4B BaseData::getColor()
|
|
|
|
{
|
|
|
|
return Color4B(r, g, b, a);
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
std::string DisplayData::changeDisplayToTexture(std::string_view displayName)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
// remove .xxx
|
2021-12-27 13:52:08 +08:00
|
|
|
std::string textureName;
|
|
|
|
size_t startPos = displayName.find_last_of(".");
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (startPos != std::string::npos)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-27 13:52:08 +08:00
|
|
|
textureName.assign(displayName.data(), startPos); // textureName = textureName.erase(startPos);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
2021-12-27 13:52:08 +08:00
|
|
|
else
|
|
|
|
textureName = displayName;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
return textureName;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
DisplayData::DisplayData(void) : displayType(CS_DISPLAY_MAX), displayName("") {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void DisplayData::copy(DisplayData* displayData)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
displayName = displayData->displayName;
|
|
|
|
displayType = displayData->displayType;
|
|
|
|
}
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
SpriteDisplayData::SpriteDisplayData(void)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
displayType = CS_DISPLAY_SPRITE;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void SpriteDisplayData::copy(DisplayData* displayData)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
DisplayData::copy(displayData);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (SpriteDisplayData* sdd = dynamic_cast<SpriteDisplayData*>(displayData))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
skinData = sdd->skinData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
ArmatureDisplayData::ArmatureDisplayData(void)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
displayType = CS_DISPLAY_ARMATURE;
|
|
|
|
}
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
ParticleDisplayData::ParticleDisplayData(void)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
displayType = CS_DISPLAY_PARTICLE;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
BoneData::BoneData(void) : name(""), parentName("") {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
BoneData::~BoneData(void) {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
bool BoneData::init()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void BoneData::addDisplayData(DisplayData* displayData)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
displayDataList.pushBack(displayData);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
DisplayData* BoneData::getDisplayData(int index)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
return displayDataList.at(index);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureData::ArmatureData() : dataVersion(0.1f) {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ArmatureData::~ArmatureData() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
bool ArmatureData::init()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ArmatureData::addBoneData(BoneData* boneData)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
boneDataDic.insert(boneData->name, boneData);
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
BoneData* ArmatureData::getBoneData(std::string_view boneName)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
return static_cast<BoneData*>(boneDataDic.at(boneName));
|
|
|
|
}
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
FrameData::FrameData(void)
|
2019-11-23 20:27:39 +08:00
|
|
|
: frameID(0)
|
|
|
|
, duration(1)
|
|
|
|
, tweenEasing(cocos2d::tweenfunc::Linear)
|
|
|
|
, easingParamNumber(0)
|
|
|
|
, easingParams(nullptr)
|
|
|
|
, isTween(true)
|
|
|
|
, displayIndex(0)
|
|
|
|
, blendFunc(BlendFunc::ALPHA_PREMULTIPLIED)
|
|
|
|
|
|
|
|
, strEvent("")
|
|
|
|
, strMovement("")
|
|
|
|
, strSound("")
|
|
|
|
, strSoundEffect("")
|
2021-12-25 10:04:45 +08:00
|
|
|
{}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
FrameData::~FrameData(void)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2020-10-17 16:32:16 +08:00
|
|
|
CC_SAFE_DELETE(easingParams);
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void FrameData::copy(const BaseData* baseData)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
BaseData::copy(baseData);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (const FrameData* frameData = dynamic_cast<const FrameData*>(baseData))
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
duration = frameData->duration;
|
2019-11-23 20:27:39 +08:00
|
|
|
displayIndex = frameData->displayIndex;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
tweenEasing = frameData->tweenEasing;
|
2019-11-23 20:27:39 +08:00
|
|
|
easingParamNumber = frameData->easingParamNumber;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
CC_SAFE_DELETE(easingParams);
|
2019-11-23 20:27:39 +08:00
|
|
|
if (easingParamNumber != 0)
|
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
easingParams = new float[easingParamNumber];
|
2021-12-25 10:04:45 +08:00
|
|
|
for (int i = 0; i < easingParamNumber; i++)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
easingParams[i] = frameData->easingParams[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
blendFunc = frameData->blendFunc;
|
2021-12-25 10:04:45 +08:00
|
|
|
isTween = frameData->isTween;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementBoneData::MovementBoneData() : delay(0.0f), scale(1.0f), duration(0), name("") {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementBoneData::~MovementBoneData(void) {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
bool MovementBoneData::init()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void MovementBoneData::addFrameData(FrameData* frameData)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
frameList.pushBack(frameData);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
FrameData* MovementBoneData::getFrameData(int index)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
return frameList.at(index);
|
|
|
|
}
|
|
|
|
|
2020-10-17 16:32:16 +08:00
|
|
|
MovementData::MovementData(void)
|
2019-11-23 20:27:39 +08:00
|
|
|
: name("")
|
|
|
|
, duration(0)
|
|
|
|
, scale(1.0f)
|
|
|
|
, durationTo(0)
|
|
|
|
, durationTween(0)
|
|
|
|
, loop(true)
|
|
|
|
, tweenEasing(cocos2d::tweenfunc::Linear)
|
2021-12-25 10:04:45 +08:00
|
|
|
{}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MovementData::~MovementData(void) {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void MovementData::addMovementBoneData(MovementBoneData* movBoneData)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
movBoneDataDic.insert(movBoneData->name, movBoneData);
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
MovementBoneData* MovementData::getMovementBoneData(std::string_view boneName)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
return movBoneDataDic.at(boneName);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
AnimationData::AnimationData(void) {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
AnimationData::~AnimationData(void) {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void AnimationData::addMovement(MovementData* movData)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
movementDataDic.insert(movData->name, movData);
|
|
|
|
movementNames.push_back(movData->name);
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
MovementData* AnimationData::getMovement(std::string_view movementName)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
return movementDataDic.at(movementName);
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t AnimationData::getMovementCount()
|
|
|
|
{
|
|
|
|
return movementDataDic.size();
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ContourData::ContourData() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ContourData::~ContourData() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
bool ContourData::init()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ContourData::addVertex(Vec2& vertex)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
vertexList.push_back(vertex);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
TextureData::TextureData() : height(0.0f), width(0.0f), pivotX(0.5f), pivotY(0.5f), name("") {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
TextureData::~TextureData() {}
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
bool TextureData::init()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void TextureData::addContourData(ContourData* contourData)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
contourDataList.pushBack(contourData);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
ContourData* TextureData::getContourData(int index)
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
return contourDataList.at(index);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace cocostudio
|