axmol/cocos/editor-support/cocostudio/CCDatas.cpp

427 lines
8.0 KiB
C++
Raw Normal View History

2013-06-06 12:02:54 +08:00
/****************************************************************************
Copyright (c) 2013-2014 Chukong Technologies Inc.
2013-06-06 12:02:54 +08:00
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "cocostudio/CCDatas.h"
#include "cocostudio/CCUtilMath.h"
#include "cocostudio/CCTransformHelp.h"
2013-06-06 12:02:54 +08:00
using namespace cocos2d;
namespace cocostudio {
2013-06-06 12:02:54 +08:00
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)
2013-06-07 19:48:31 +08:00
{
}
BaseData::~BaseData()
2013-06-07 19:48:31 +08:00
{
}
void BaseData::copy(const BaseData *node )
2013-06-07 19:48:31 +08:00
{
2013-09-13 18:07:37 +08:00
x = node->x;
y = node->y;
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;
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;
r = node->r;
g = node->g;
b = node->b;
a = node->a;
2013-06-07 19:48:31 +08:00
}
void BaseData::subtract(BaseData *from, BaseData *to, bool limit)
2013-06-07 19:48:31 +08:00
{
2013-09-13 18:07:37 +08:00
x = to->x - from->x;
y = to->y - from->y;
scaleX = to->scaleX - from->scaleX;
scaleY = to->scaleY - from->scaleY;
skewX = to->skewX - from->skewX;
skewY = to->skewY - from->skewY;
2013-06-07 19:48:31 +08:00
2013-09-13 18:07:37 +08:00
if(isUseColorInfo || from->isUseColorInfo || to->isUseColorInfo)
{
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
{
a = r = g = b = 0;
isUseColorInfo = false;
}
2013-06-07 19:48:31 +08:00
if (limit)
{
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;
}
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-09-13 18:07:37 +08:00
}
2013-06-07 19:48:31 +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
2013-12-25 19:46:09 +08:00
const std::string DisplayData::changeDisplayToTexture(const std::string& displayName)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
// remove .xxx
std::string textureName = displayName;
size_t startPos = textureName.find_last_of(".");
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
if(startPos != std::string::npos)
{
textureName = textureName.erase(startPos);
}
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
}
DisplayData::DisplayData(void)
2013-09-13 18:07:37 +08:00
: displayType(CS_DISPLAY_MAX)
, displayName("")
2013-06-06 12:02:54 +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
}
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
}
void SpriteDisplayData::copy(DisplayData *displayData)
2013-06-06 12:02:54 +08:00
{
DisplayData::copy(displayData);
2013-09-13 18:07:37 +08:00
if (SpriteDisplayData *sdd = dynamic_cast<SpriteDisplayData*>(displayData))
{
skinData = sdd->skinData;
}
2013-06-06 12:02:54 +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
}
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
}
BoneData::BoneData(void)
2013-06-07 10:52:32 +08:00
: name("")
, parentName("")
2013-06-06 12:02:54 +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
}
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
}
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
}
2013-09-13 18:07:37 +08:00
ArmatureData::ArmatureData()
2013-09-13 18:07:37 +08:00
: dataVersion(0.1f)
2013-06-06 12:02:54 +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
}
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
}
BoneData *ArmatureData::getBoneData(const std::string& 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
}
FrameData::FrameData(void)
2013-09-13 18:07:37 +08:00
: frameID(0)
, duration(1)
, tweenEasing(cocos2d::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)
, blendFunc(BlendFunc::ALPHA_NON_PREMULTIPLIED)
2013-06-06 12:02:54 +08:00
2013-09-13 18:07:37 +08:00
, strEvent("")
, strMovement("")
, strSound("")
, strSoundEffect("")
2013-06-06 12:02:54 +08:00
{
}
FrameData::~FrameData(void)
2013-06-06 12:02:54 +08:00
{
CC_SAFE_DELETE(easingParams);
2013-06-06 12:02:54 +08:00
}
void FrameData::copy(const BaseData *baseData)
2013-06-06 12:02:54 +08:00
{
BaseData::copy(baseData);
if (const FrameData *frameData = dynamic_cast<const FrameData*>(baseData))
{
duration = frameData->duration;
displayIndex = frameData->displayIndex;
tweenEasing = frameData->tweenEasing;
easingParamNumber = frameData->easingParamNumber;
CC_SAFE_DELETE(easingParams);
if (easingParamNumber != 0)
{
easingParams = new float[easingParamNumber];
for (int i = 0; i<easingParamNumber; i++)
{
easingParams[i] = frameData->easingParams[i];
}
}
blendFunc = frameData->blendFunc;
}
2013-06-07 10:52:32 +08:00
}
2013-06-06 12:02:54 +08:00
MovementBoneData::MovementBoneData()
2013-06-07 10:52:32 +08:00
: delay(0.0f)
, scale(1.0f)
, duration(0)
, name("")
2013-06-06 12:02:54 +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
}
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
}
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
}
2013-09-13 18:07:37 +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(cocos2d::tweenfunc::Linear)
2013-06-06 12:02:54 +08:00
{
}
MovementData::~MovementData(void)
2013-06-06 12:02:54 +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
}
MovementBoneData *MovementData::getMovementBoneData(const std::string& 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
}
AnimationData::AnimationData(void)
2013-06-06 12:02:54 +08:00
{
}
AnimationData::~AnimationData(void)
2013-06-06 12:02:54 +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
}
MovementData *AnimationData::getMovement(const std::string& 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
}
2013-09-13 18:07:37 +08:00
ContourData::ContourData()
2013-06-06 12:02:54 +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
}
2013-12-13 19:40:38 +08:00
void ContourData::addVertex(Point &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
}
TextureData::TextureData()
2013-06-07 10:52:32 +08:00
: height(0.0f)
, width(0.0f)
, pivotX(0.5f)
, pivotY(0.5f)
, name("")
2013-06-06 12:02:54 +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
}
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
}
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
}
}