axmol/extensions/CCArmature/datas/CCDatas.cpp

414 lines
7.5 KiB
C++
Raw Normal View History

2013-06-06 12:02:54 +08:00
/****************************************************************************
Copyright (c) 2013 cocos2d-x.org
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 "CCDatas.h"
#include "CCArmature/utils/CCUtilMath.h"
namespace cocos2d { namespace extension { namespace armature {
2013-06-06 12:02:54 +08:00
2013-06-07 19:48:31 +08:00
BaseData::BaseData()
2013-06-07 19:48:31 +08:00
: 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)
{
}
BaseData::~BaseData()
2013-06-07 19:48:31 +08:00
{
}
void BaseData::copy(const BaseData *node )
2013-06-07 19:48:31 +08:00
{
x = node->x;
y = node->y;
zOrder = node->zOrder;
scaleX = node->scaleX;
scaleY = node->scaleY;
skewX = node->skewX;
skewY = node->skewY;
tweenRotate = node->tweenRotate;
isUseColorInfo = node->isUseColorInfo;
r = node->r;
g = node->g;
b = node->b;
a = node->a;
}
void BaseData::subtract(BaseData *from, BaseData *to)
2013-06-07 19:48:31 +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;
if(from->isUseColorInfo || to->isUseColorInfo)
{
a = to->a - from->a;
r = to->r - from->r;
g = to->g - from->g;
b = to->b - from->b;
isUseColorInfo = true;
}
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;
skewY -= to->tweenRotate;
}
}
const char *DisplayData::changeDisplayToTexture(const char *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-06-07 10:52:32 +08:00
return textureName.c_str();
2013-06-06 12:02:54 +08:00
}
DisplayData::DisplayData(void)
2013-06-07 10:52:32 +08:00
: displayType(CS_DISPLAY_SPRITE)
2013-06-06 12:02:54 +08:00
{
}
DisplayData::~DisplayData(void)
2013-06-06 12:02:54 +08:00
{
}
SpriteDisplayData::SpriteDisplayData(void)
2013-06-07 10:52:32 +08:00
: displayName("")
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
}
SpriteDisplayData::~SpriteDisplayData()
2013-06-06 12:02:54 +08:00
{
}
void SpriteDisplayData::copy(SpriteDisplayData *displayData)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
displayName = displayData->displayName;
displayType = displayData->displayType;
2013-06-06 12:02:54 +08:00
}
ArmatureDisplayData::ArmatureDisplayData(void)
2013-06-07 10:52:32 +08:00
: displayName("")
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
}
ArmatureDisplayData::~ArmatureDisplayData()
2013-06-06 12:02:54 +08:00
{
}
void ArmatureDisplayData::copy(ArmatureDisplayData *displayData)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
displayName = displayData->displayName;
displayType = displayData->displayType;
2013-06-06 12:02:54 +08:00
}
ParticleDisplayData::ParticleDisplayData(void)
2013-06-07 10:52:32 +08:00
: plist("")
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
}
void ParticleDisplayData::copy(ParticleDisplayData *displayData)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
plist = displayData->plist;
displayType = displayData->displayType;
2013-06-06 12:02:54 +08:00
}
ShaderDisplayData::ShaderDisplayData(void)
2013-06-07 10:52:32 +08:00
: vert("")
, frag("")
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
displayType = CS_DISPLAY_SHADER;
2013-06-06 12:02:54 +08:00
}
void ShaderDisplayData::copy(ShaderDisplayData *displayData)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
vert = displayData->vert;
frag = displayData->frag;
displayType = displayData->displayType;
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
displayDataList.init();
return true;
2013-06-06 12:02:54 +08:00
}
void BoneData::addDisplayData(DisplayData *displayData)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
displayDataList.addObject(displayData);
2013-06-06 12:02:54 +08:00
}
DisplayData *BoneData::getDisplayData(int index)
2013-06-06 12:02:54 +08:00
{
return (DisplayData *)displayDataList.objectAtIndex(index);
2013-06-06 12:02:54 +08:00
}
ArmatureData::ArmatureData()
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
{
2013-06-07 10:52:32 +08:00
return boneList.init();
2013-06-06 12:02:54 +08:00
}
void ArmatureData::addBoneData(BoneData *boneData)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
boneDataDic.setObject(boneData, boneData->name);
boneList.addObject(boneData);
2013-06-06 12:02:54 +08:00
}
BoneData *ArmatureData::getBoneData(const char *boneName)
2013-06-06 12:02:54 +08:00
{
return (BoneData *)boneDataDic.objectForKey(boneName);
2013-06-06 12:02:54 +08:00
}
FrameData::FrameData(void)
2013-06-07 10:52:32 +08:00
: duration(1)
, tweenEasing(Linear)
, displayIndex(0)
2013-06-06 12:02:54 +08:00
, _movement("")
, _event("")
, _sound("")
, _soundEffect("")
2013-06-06 12:02:54 +08:00
{
}
FrameData::~FrameData(void)
2013-06-06 12:02:54 +08:00
{
}
void FrameData::copy(FrameData *frameData)
2013-06-06 12:02:54 +08:00
{
BaseData::copy(frameData);
2013-06-06 12:02:54 +08:00
2013-06-07 10:52:32 +08:00
duration = frameData->duration;
displayIndex = frameData->displayIndex;
tweenEasing = frameData->tweenEasing;
}
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-06-07 10:52:32 +08:00
return frameList.init();
2013-06-06 12:02:54 +08:00
}
void MovementBoneData::addFrameData(FrameData *frameData)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
frameList.addObject(frameData);
duration += frameData->duration;
2013-06-06 12:02:54 +08:00
}
FrameData *MovementBoneData::getFrameData(int index)
2013-06-06 12:02:54 +08:00
{
return (FrameData *)frameList.objectAtIndex(index);
2013-06-06 12:02:54 +08:00
}
MovementData::MovementData(void)
2013-06-07 10:52:32 +08:00
: name("")
, duration(0)
, durationTo(0)
, durationTween(0)
, loop(true)
, tweenEasing(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-06-07 10:52:32 +08:00
movBoneDataDic.setObject(movBoneData, movBoneData->name);
2013-06-06 12:02:54 +08:00
}
MovementBoneData *MovementData::getMovementBoneData(const char *boneName)
2013-06-06 12:02:54 +08:00
{
return (MovementBoneData *)movBoneDataDic.objectForKey(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::release()
2013-06-06 12:02:54 +08:00
{
Object::release();
2013-06-06 12:02:54 +08:00
}
void AnimationData::retain()
2013-06-06 12:02:54 +08:00
{
Object::retain();
2013-06-06 12:02:54 +08:00
}
void AnimationData::addMovement(MovementData *movData)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
movementDataDic.setObject(movData, movData->name);
movementNames.push_back(movData->name);
2013-06-06 12:02:54 +08:00
}
MovementData *AnimationData::getMovement(const char *movementName)
2013-06-06 12:02:54 +08:00
{
return (MovementData *)movementDataDic.objectForKey(movementName);
2013-06-06 12:02:54 +08:00
}
int AnimationData::getMovementCount()
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
return movementDataDic.count();
2013-06-06 12:02:54 +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-06-07 10:52:32 +08:00
return vertexList.init();
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-06-07 10:52:32 +08:00
return contourDataList.init();
2013-06-06 12:02:54 +08:00
}
void TextureData::addContourData(ContourData *contourData)
2013-06-06 12:02:54 +08:00
{
2013-06-07 10:52:32 +08:00
contourDataList.addObject(contourData);
2013-06-06 12:02:54 +08:00
}
ContourData *TextureData::getContourData(int index)
2013-06-06 12:02:54 +08:00
{
return (ContourData *)contourDataList.objectAtIndex(index);
2013-06-06 12:02:54 +08:00
}
}}} // namespace cocos2d { namespace extension { namespace armature {