axmol/extensions/cocostudio/CCDatas.cpp

369 lines
8.0 KiB
C++
Raw Normal View History

2013-06-06 12:02:54 +08:00
/****************************************************************************
2020-10-17 16:32:16 +08:00
Copyright (c) 2013-2017 Chukong Technologies Inc.
2013-06-06 12:02:54 +08:00
https://axis-project.github.io/
2013-06-06 12:02:54 +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 "CCDatas.h"
#include "CCTransformHelp.h"
2013-06-06 12:02:54 +08:00
USING_NS_AX;
2021-12-25 10:04:45 +08:00
namespace cocostudio
{
2013-06-07 19:48:31 +08:00
BaseData::BaseData()
2013-09-13 18:07:37 +08:00
: x(0.0f)
, y(0.0f)
, zOrder(0)
2013-06-07 19:48:31 +08:00
2013-09-13 18:07:37 +08:00
, skewX(0.0f)
, skewY(0.0f)
, scaleX(1.0f)
, scaleY(1.0f)
2013-06-07 19:48:31 +08:00
2013-09-13 18:07:37 +08:00
, tweenRotate(0.0f)
2013-06-07 19:48:31 +08:00
2013-09-13 18:07:37 +08:00
, isUseColorInfo(false)
, a(255)
, r(255)
, g(255)
, b(255)
2021-12-25 10:04:45 +08:00
{}
2013-06-07 19:48:31 +08:00
2021-12-25 10:04:45 +08:00
BaseData::~BaseData() {}
2013-06-07 19:48:31 +08:00
2021-12-25 10:04:45 +08:00
void BaseData::copy(const BaseData* node)
2013-06-07 19:48:31 +08:00
{
2021-12-25 10:04:45 +08:00
x = node->x;
y = node->y;
2013-09-13 18:07:37 +08:00
zOrder = node->zOrder;
2013-06-07 19:48:31 +08:00
2013-09-13 18:07:37 +08:00
scaleX = node->scaleX;
scaleY = node->scaleY;
2021-12-25 10:04:45 +08:00
skewX = node->skewX;
skewY = node->skewY;
2013-06-07 19:48:31 +08:00
2013-09-13 18:07:37 +08:00
tweenRotate = node->tweenRotate;
2013-06-07 19:48:31 +08:00
2013-09-13 18:07:37 +08:00
isUseColorInfo = node->isUseColorInfo;
2021-12-25 10:04:45 +08:00
r = node->r;
g = node->g;
b = node->b;
a = node->a;
2013-06-07 19:48:31 +08:00
}
2021-12-25 10:04:45 +08:00
void BaseData::subtract(BaseData* from, BaseData* to, bool limit)
2013-06-07 19:48:31 +08:00
{
2021-12-25 10:04:45 +08:00
x = to->x - from->x;
y = to->y - from->y;
2013-09-13 18:07:37 +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;
2013-06-07 19:48:31 +08:00
2021-12-25 10:04:45 +08:00
if (isUseColorInfo || from->isUseColorInfo || to->isUseColorInfo)
2013-09-13 18:07:37 +08:00
{
a = to->a - from->a;
r = to->r - from->r;
g = to->g - from->g;
b = to->b - from->b;
2013-06-07 19:48:31 +08:00
2013-09-13 18:07:37 +08:00
isUseColorInfo = true;
}
else
{
2021-12-25 10:04:45 +08:00
a = r = g = b = 0;
2013-09-13 18:07:37 +08:00
isUseColorInfo = false;
}
2013-06-07 19:48:31 +08:00
2021-12-25 10:04:45 +08:00
if (limit)
{
if (skewX > M_PI)
{
2022-07-15 19:17:01 +08:00
skewX -= (float)AX_DOUBLE_PI;
}
if (skewX < -M_PI)
{
2022-07-15 19:17:01 +08:00
skewX += (float)AX_DOUBLE_PI;
}
if (skewY > M_PI)
{
2022-07-15 19:17:01 +08:00
skewY -= (float)AX_DOUBLE_PI;
}
if (skewY < -M_PI)
{
2022-07-15 19:17:01 +08:00
skewY += (float)AX_DOUBLE_PI;
}
2013-09-13 18:07:37 +08:00
}
2013-06-07 19:48:31 +08:00
2013-09-13 18:07:37 +08:00
if (to->tweenRotate)
{
2013-12-19 21:12:25 +08:00
skewX += to->tweenRotate * M_PI * 2;
skewY -= to->tweenRotate * M_PI * 2;
2013-09-13 18:07:37 +08:00
}
}
2013-06-07 19:48:31 +08:00
2021-12-25 10:04:45 +08:00
void BaseData::setColor(const Color4B& color)
2013-09-13 18:07:37 +08:00
{
r = color.r;
g = color.g;
b = color.b;
a = color.a;
2013-06-07 19:48:31 +08:00
}
Color4B BaseData::getColor()
2013-09-13 18:07:37 +08:00
{
return Color4B(r, g, b, a);
2013-09-13 18:07:37 +08:00
}
2013-06-07 19:48:31 +08:00
2021-12-26 23:26:34 +08:00
std::string DisplayData::changeDisplayToTexture(std::string_view displayName)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
// remove .xxx
2021-12-27 13:52:08 +08:00
std::string textureName;
size_t startPos = displayName.find_last_of(".");
2013-06-06 12:02:54 +08:00
2021-12-25 10:04:45 +08:00
if (startPos != std::string::npos)
2013-06-07 10:52:32 +08:00
{
2021-12-27 13:52:08 +08:00
textureName.assign(displayName.data(), startPos); // textureName = textureName.erase(startPos);
2013-06-07 10:52:32 +08:00
}
2021-12-27 13:52:08 +08:00
else
textureName = displayName;
2013-06-06 12:02:54 +08:00
2013-12-25 19:46:09 +08:00
return textureName;
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
DisplayData::DisplayData(void) : displayType(CS_DISPLAY_MAX), displayName("") {}
2013-06-06 12:02:54 +08:00
2021-12-25 10:04:45 +08:00
void DisplayData::copy(DisplayData* displayData)
2013-06-06 12:02:54 +08:00
{
displayName = displayData->displayName;
displayType = displayData->displayType;
2013-06-06 12:02:54 +08:00
}
2020-10-17 16:32:16 +08:00
SpriteDisplayData::SpriteDisplayData(void)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
displayType = CS_DISPLAY_SPRITE;
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
void SpriteDisplayData::copy(DisplayData* displayData)
2013-06-06 12:02:54 +08:00
{
DisplayData::copy(displayData);
2013-09-13 18:07:37 +08:00
2021-12-25 10:04:45 +08:00
if (SpriteDisplayData* sdd = dynamic_cast<SpriteDisplayData*>(displayData))
{
skinData = sdd->skinData;
}
2013-06-06 12:02:54 +08:00
}
2020-10-17 16:32:16 +08:00
ArmatureDisplayData::ArmatureDisplayData(void)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
displayType = CS_DISPLAY_ARMATURE;
2013-06-06 12:02:54 +08:00
}
2020-10-17 16:32:16 +08:00
ParticleDisplayData::ParticleDisplayData(void)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
displayType = CS_DISPLAY_PARTICLE;
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
BoneData::BoneData(void) : name(""), parentName("") {}
2013-06-06 12:02:54 +08:00
2021-12-25 10:04:45 +08:00
BoneData::~BoneData(void) {}
2013-06-06 12:02:54 +08:00
bool BoneData::init()
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
return true;
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
void BoneData::addDisplayData(DisplayData* displayData)
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
displayDataList.pushBack(displayData);
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
DisplayData* BoneData::getDisplayData(int index)
2013-06-06 12:02:54 +08:00
{
2013-12-18 22:07:33 +08:00
return displayDataList.at(index);
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
ArmatureData::ArmatureData() : dataVersion(0.1f) {}
2013-09-13 18:07:37 +08:00
2021-12-25 10:04:45 +08:00
ArmatureData::~ArmatureData() {}
2013-06-06 12:02:54 +08:00
bool ArmatureData::init()
2013-06-06 12:02:54 +08:00
{
return true;
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
void ArmatureData::addBoneData(BoneData* boneData)
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
boneDataDic.insert(boneData->name, boneData);
2013-06-06 12:02:54 +08:00
}
2021-12-26 23:26:34 +08:00
BoneData* ArmatureData::getBoneData(std::string_view boneName)
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
return static_cast<BoneData*>(boneDataDic.at(boneName));
2013-06-06 12:02:54 +08:00
}
2020-10-17 16:32:16 +08:00
FrameData::FrameData(void)
2013-09-13 18:07:37 +08:00
: frameID(0)
, duration(1)
, tweenEasing(axis::tweenfunc::Linear)
, easingParamNumber(0)
, easingParams(nullptr)
2013-09-17 20:14:08 +08:00
, isTween(true)
2013-06-07 10:52:32 +08:00
, displayIndex(0)
2014-07-23 20:07:33 +08:00
, blendFunc(BlendFunc::ALPHA_PREMULTIPLIED)
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
, strEvent("")
, strMovement("")
, strSound("")
, strSoundEffect("")
2021-12-25 10:04:45 +08:00
{}
2013-06-06 12:02:54 +08:00
2020-10-17 16:32:16 +08:00
FrameData::~FrameData(void)
2013-06-06 12:02:54 +08:00
{
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(easingParams);
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
void FrameData::copy(const BaseData* baseData)
2013-06-06 12:02:54 +08:00
{
BaseData::copy(baseData);
2021-12-25 10:04:45 +08:00
if (const FrameData* frameData = dynamic_cast<const FrameData*>(baseData))
{
2021-12-25 10:04:45 +08:00
duration = frameData->duration;
displayIndex = frameData->displayIndex;
2021-12-25 10:04:45 +08:00
tweenEasing = frameData->tweenEasing;
easingParamNumber = frameData->easingParamNumber;
2021-12-25 10:04:45 +08:00
2022-07-15 19:17:01 +08:00
AX_SAFE_DELETE(easingParams);
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++)
{
easingParams[i] = frameData->easingParams[i];
}
}
blendFunc = frameData->blendFunc;
2021-12-25 10:04:45 +08:00
isTween = frameData->isTween;
}
2013-06-07 10:52:32 +08:00
}
2013-06-06 12:02:54 +08:00
2021-12-25 10:04:45 +08:00
MovementBoneData::MovementBoneData() : delay(0.0f), scale(1.0f), duration(0), name("") {}
2013-06-06 12:02:54 +08:00
2021-12-25 10:04:45 +08:00
MovementBoneData::~MovementBoneData(void) {}
2013-06-06 12:02:54 +08:00
bool MovementBoneData::init()
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
return true;
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
void MovementBoneData::addFrameData(FrameData* frameData)
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
frameList.pushBack(frameData);
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
FrameData* MovementBoneData::getFrameData(int index)
2013-06-06 12:02:54 +08:00
{
2013-12-18 22:07:33 +08:00
return frameList.at(index);
2013-06-06 12:02:54 +08:00
}
2020-10-17 16:32:16 +08:00
MovementData::MovementData(void)
2013-06-07 10:52:32 +08:00
: name("")
, duration(0)
2013-09-13 18:07:37 +08:00
, scale(1.0f)
2013-06-07 10:52:32 +08:00
, durationTo(0)
, durationTween(0)
, loop(true)
, tweenEasing(axis::tweenfunc::Linear)
2021-12-25 10:04:45 +08:00
{}
2013-06-06 12:02:54 +08:00
2021-12-25 10:04:45 +08:00
MovementData::~MovementData(void) {}
2013-06-06 12:02:54 +08:00
2021-12-25 10:04:45 +08:00
void MovementData::addMovementBoneData(MovementBoneData* movBoneData)
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
movBoneDataDic.insert(movBoneData->name, movBoneData);
2013-06-06 12:02:54 +08:00
}
2021-12-26 23:26:34 +08:00
MovementBoneData* MovementData::getMovementBoneData(std::string_view boneName)
2013-06-06 12:02:54 +08:00
{
2013-12-18 22:07:33 +08:00
return movBoneDataDic.at(boneName);
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
AnimationData::AnimationData(void) {}
2013-06-06 12:02:54 +08:00
2021-12-25 10:04:45 +08:00
AnimationData::~AnimationData(void) {}
2013-06-06 12:02:54 +08:00
2021-12-25 10:04:45 +08:00
void AnimationData::addMovement(MovementData* movData)
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
movementDataDic.insert(movData->name, movData);
2013-09-13 18:07:37 +08:00
movementNames.push_back(movData->name);
2013-06-06 12:02:54 +08:00
}
2021-12-26 23:26:34 +08:00
MovementData* AnimationData::getMovement(std::string_view movementName)
2013-06-06 12:02:54 +08:00
{
2013-12-18 22:07:33 +08:00
return movementDataDic.at(movementName);
2013-06-06 12:02:54 +08:00
}
2013-12-18 22:07:33 +08:00
ssize_t AnimationData::getMovementCount()
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
return movementDataDic.size();
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
ContourData::ContourData() {}
2013-06-06 12:02:54 +08:00
2021-12-25 10:04:45 +08:00
ContourData::~ContourData() {}
2013-06-06 12:02:54 +08:00
bool ContourData::init()
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
return true;
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
void ContourData::addVertex(Vec2& vertex)
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
vertexList.push_back(vertex);
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
TextureData::TextureData() : height(0.0f), width(0.0f), pivotX(0.5f), pivotY(0.5f), name("") {}
2013-06-06 12:02:54 +08:00
2021-12-25 10:04:45 +08:00
TextureData::~TextureData() {}
2013-06-06 12:02:54 +08:00
bool TextureData::init()
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
return true;
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
void TextureData::addContourData(ContourData* contourData)
2013-06-06 12:02:54 +08:00
{
2013-12-13 19:40:38 +08:00
contourDataList.pushBack(contourData);
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
ContourData* TextureData::getContourData(int index)
2013-06-06 12:02:54 +08:00
{
2013-12-18 22:07:33 +08:00
return contourDataList.at(index);
2013-06-06 12:02:54 +08:00
}
2021-12-25 10:04:45 +08:00
} // namespace cocostudio