2014-06-11 11:10:07 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
2019-11-25 01:35:26 +08:00
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
|
|
|
Copyright (c) 2019-2020 simdsoft, @HALX99
|
2021-10-09 13:48:56 +08:00
|
|
|
Copyright (c) 2021 Bytedance Inc.
|
2014-06-11 11:10:07 +08:00
|
|
|
|
2022-07-09 22:23:34 +08:00
|
|
|
https://axis-project.github.io/
|
2014-06-11 11:10:07 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "ActionTimeline/CCActionTimelineCache.h"
|
|
|
|
#include "ActionTimeline/CSLoader.h"
|
|
|
|
#include "ActionTimeline/CCFrame.h"
|
|
|
|
#include "ActionTimeline/CCTimeLine.h"
|
|
|
|
#include "ActionTimeline/CCActionTimeline.h"
|
2014-08-29 15:39:52 +08:00
|
|
|
#include "platform/CCFileUtils.h"
|
|
|
|
#include "2d/CCSpriteFrameCache.h"
|
|
|
|
#include "2d/CCSpriteFrame.h"
|
2019-11-25 01:35:26 +08:00
|
|
|
#include "base/ccUtils.h"
|
2014-06-11 11:10:07 +08:00
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "CSParseBinary_generated.h"
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
#include "flatbuffers/flatbuffers.h"
|
2014-10-09 18:28:09 +08:00
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "FlatBuffersSerialize.h"
|
2014-12-08 14:32:33 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
#include <fstream>
|
|
|
|
|
2014-06-11 11:10:07 +08:00
|
|
|
using namespace cocos2d;
|
2014-11-21 15:15:38 +08:00
|
|
|
using namespace flatbuffers;
|
2014-06-11 11:10:07 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
namespace timeline
|
|
|
|
{
|
2014-06-11 11:10:07 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
static const char* Property_VisibleForFrame = "VisibleForFrame";
|
|
|
|
static const char* Property_Position = "Position";
|
|
|
|
static const char* Property_Scale = "Scale";
|
|
|
|
static const char* Property_RotationSkew = "RotationSkew";
|
|
|
|
static const char* Property_CColor = "CColor";
|
|
|
|
static const char* Property_FileData = "FileData";
|
|
|
|
static const char* Property_FrameEvent = "FrameEvent";
|
|
|
|
static const char* Property_Alpha = "Alpha";
|
2015-01-22 11:20:01 +08:00
|
|
|
static const char* Property_AnchorPoint = "AnchorPoint";
|
2015-01-12 10:55:15 +08:00
|
|
|
static const char* Property_ZOrder = "ZOrder";
|
|
|
|
static const char* Property_ActionValue = "ActionValue";
|
2015-08-17 13:05:29 +08:00
|
|
|
static const char* Property_BlendValue = "BlendFunc";
|
2014-06-11 11:10:07 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static const char* ACTION = "action";
|
|
|
|
static const char* DURATION = "duration";
|
|
|
|
static const char* TIMELINES = "timelines";
|
|
|
|
static const char* FRAME_TYPE = "frameType";
|
|
|
|
static const char* FRAMES = "frames";
|
|
|
|
static const char* FRAME_INDEX = "frameIndex";
|
|
|
|
static const char* TWEEN = "tween";
|
|
|
|
static const char* TIME_SPEED = "speed";
|
|
|
|
static const char* ACTION_TAG = "actionTag";
|
|
|
|
static const char* INNER_ACTION = "innerActionType";
|
|
|
|
static const char* START_FRAME = "startFrame";
|
|
|
|
|
|
|
|
static const char* X = "x";
|
|
|
|
static const char* Y = "y";
|
|
|
|
static const char* ROTATION = "rotation";
|
|
|
|
static const char* RED = "red";
|
|
|
|
static const char* GREEN = "green";
|
|
|
|
static const char* BLUE = "blue";
|
|
|
|
static const char* Value = "value";
|
2014-06-11 11:10:07 +08:00
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
static ActionTimelineCache* _sharedActionCache = nullptr;
|
2014-06-11 11:10:07 +08:00
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
ActionTimelineCache* ActionTimelineCache::getInstance()
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
if (!_sharedActionCache)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
2021-12-08 00:11:53 +08:00
|
|
|
_sharedActionCache = new ActionTimelineCache();
|
2014-06-11 11:10:07 +08:00
|
|
|
_sharedActionCache->init();
|
|
|
|
}
|
|
|
|
|
|
|
|
return _sharedActionCache;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
void ActionTimelineCache::destroyInstance()
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(_sharedActionCache);
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
void ActionTimelineCache::purge()
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
_animationActions.clear();
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
void ActionTimelineCache::init()
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
using namespace std::placeholders;
|
2015-01-12 10:55:15 +08:00
|
|
|
/*
|
2014-06-13 16:03:03 +08:00
|
|
|
_funcs.insert(Pair(FrameType_VisibleFrame, std::bind(&ActionTimelineCache::loadVisibleFrame, this, _1)));
|
|
|
|
_funcs.insert(Pair(FrameType_PositionFrame, std::bind(&ActionTimelineCache::loadPositionFrame, this, _1)));
|
|
|
|
_funcs.insert(Pair(FrameType_ScaleFrame, std::bind(&ActionTimelineCache::loadScaleFrame, this, _1)));
|
|
|
|
_funcs.insert(Pair(FrameType_RotationFrame, std::bind(&ActionTimelineCache::loadRotationFrame, this, _1)));
|
|
|
|
_funcs.insert(Pair(FrameType_SkewFrame, std::bind(&ActionTimelineCache::loadSkewFrame, this, _1)));
|
|
|
|
_funcs.insert(Pair(FrameType_RotationSkewFrame, std::bind(&ActionTimelineCache::loadRotationSkewFrame, this, _1)));
|
|
|
|
_funcs.insert(Pair(FrameType_AnchorFrame, std::bind(&ActionTimelineCache::loadAnchorPointFrame, this, _1)));
|
|
|
|
_funcs.insert(Pair(FrameType_InnerActionFrame, std::bind(&ActionTimelineCache::loadInnerActionFrame, this, _1)));
|
|
|
|
_funcs.insert(Pair(FrameType_ColorFrame, std::bind(&ActionTimelineCache::loadColorFrame, this, _1)));
|
|
|
|
_funcs.insert(Pair(FrameType_TextureFrame, std::bind(&ActionTimelineCache::loadTextureFrame, this, _1)));
|
|
|
|
_funcs.insert(Pair(FrameType_EventFrame, std::bind(&ActionTimelineCache::loadEventFrame, this, _1)));
|
|
|
|
_funcs.insert(Pair(FrameType_ZOrderFrame, std::bind(&ActionTimelineCache::loadZOrderFrame, this, _1)));
|
2015-01-12 10:55:15 +08:00
|
|
|
*/
|
2014-06-11 11:10:07 +08:00
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
void ActionTimelineCache::removeAction(std::string_view fileName)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
if (_animationActions.find(fileName) != _animationActions.end())
|
|
|
|
{
|
|
|
|
_animationActions.erase(fileName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
ActionTimeline* ActionTimelineCache::createAction(std::string_view filename)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2021-12-27 13:52:08 +08:00
|
|
|
auto path = filename;
|
|
|
|
size_t pos = path.find_last_of('.');
|
|
|
|
auto suffix = path.substr(pos + 1, path.length());
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
ActionTimelineCache* cache = ActionTimelineCache::getInstance();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
if (suffix == "csb")
|
|
|
|
{
|
2014-12-01 12:46:29 +08:00
|
|
|
return cache->createActionWithFlatBuffersFile(filename);
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
else if (suffix == "json" || suffix == "ExportJson")
|
|
|
|
{
|
|
|
|
return cache->createActionFromJson(filename);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
ActionTimeline* ActionTimelineCache::createActionFromJson(std::string_view fileName)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
2014-06-13 16:03:03 +08:00
|
|
|
ActionTimeline* action = _animationActions.at(fileName);
|
2014-06-11 11:10:07 +08:00
|
|
|
if (action == nullptr)
|
|
|
|
{
|
|
|
|
action = loadAnimationActionWithFile(fileName);
|
|
|
|
}
|
|
|
|
return action->clone();
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
ActionTimeline* ActionTimelineCache::createActionFromContent(std::string_view fileName, std::string_view content)
|
2016-01-14 16:16:37 +08:00
|
|
|
{
|
|
|
|
ActionTimeline* action = _animationActions.at(fileName);
|
|
|
|
if (action == nullptr)
|
|
|
|
{
|
|
|
|
action = loadAnimationActionWithContent(fileName, content);
|
|
|
|
}
|
|
|
|
return action->clone();
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
ActionTimeline* ActionTimelineCache::loadAnimationActionWithFile(std::string_view fileName)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
// Read content from file
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
|
|
|
|
std::string contentStr = FileUtils::getInstance()->getStringFromFile(fullPath);
|
2014-06-11 11:10:07 +08:00
|
|
|
|
|
|
|
return loadAnimationActionWithContent(fileName, contentStr);
|
|
|
|
}
|
|
|
|
|
2021-12-27 13:52:08 +08:00
|
|
|
ActionTimeline* ActionTimelineCache::loadAnimationActionWithContent(std::string_view fileName, std::string_view content)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
// if already exists an action with filename, then return this action
|
2014-06-13 16:03:03 +08:00
|
|
|
ActionTimeline* action = _animationActions.at(fileName);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (action)
|
2014-06-11 11:10:07 +08:00
|
|
|
return action;
|
|
|
|
|
|
|
|
rapidjson::Document doc;
|
2021-12-27 13:52:08 +08:00
|
|
|
doc.Parse<0>(content.data(), content.length());
|
2021-12-25 10:04:45 +08:00
|
|
|
if (doc.HasParseError())
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
2015-05-25 11:43:03 +08:00
|
|
|
CCLOG("GetParseError %d\n", doc.GetParseError());
|
2014-06-11 11:10:07 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
const rapidjson::Value& json = DICTOOL->getSubDictionary_json(doc, ACTION);
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
action = ActionTimeline::create();
|
2014-06-11 11:10:07 +08:00
|
|
|
|
|
|
|
action->setDuration(DICTOOL->getIntValue_json(json, DURATION));
|
|
|
|
action->setTimeSpeed(DICTOOL->getFloatValue_json(json, TIME_SPEED, 1.0f));
|
|
|
|
|
|
|
|
int timelineLength = DICTOOL->getArrayCount_json(json, TIMELINES);
|
2021-12-25 10:04:45 +08:00
|
|
|
for (int i = 0; i < timelineLength; i++)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(json, TIMELINES, i);
|
2021-12-25 10:04:45 +08:00
|
|
|
Timeline* timeline = loadTimeline(dic);
|
2014-06-11 11:10:07 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (timeline)
|
2014-06-11 11:10:07 +08:00
|
|
|
action->addTimeline(timeline);
|
|
|
|
}
|
|
|
|
|
|
|
|
_animationActions.insert(fileName, action);
|
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
Timeline* ActionTimelineCache::loadTimeline(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
Timeline* timeline = nullptr;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
// get frame type
|
2014-06-11 11:10:07 +08:00
|
|
|
const char* frameType = DICTOOL->getStringValue_json(json, FRAME_TYPE);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (frameType == nullptr)
|
2014-06-11 11:10:07 +08:00
|
|
|
return nullptr;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (frameType && _funcs.find(frameType) != _funcs.end())
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
timeline = Timeline::create();
|
|
|
|
|
|
|
|
int actionTag = DICTOOL->getIntValue_json(json, ACTION_TAG);
|
|
|
|
timeline->setActionTag(actionTag);
|
|
|
|
|
|
|
|
FrameCreateFunc func = _funcs.at(frameType);
|
|
|
|
|
|
|
|
int length = DICTOOL->getArrayCount_json(json, FRAMES);
|
2021-12-25 10:04:45 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
const rapidjson::Value& dic = DICTOOL->getSubDictionary_json(json, FRAMES, i);
|
|
|
|
|
|
|
|
Frame* frame = nullptr;
|
|
|
|
|
|
|
|
if (func != nullptr)
|
|
|
|
{
|
|
|
|
frame = func(dic);
|
|
|
|
|
|
|
|
int frameIndex = DICTOOL->getIntValue_json(dic, FRAME_INDEX);
|
|
|
|
frame->setFrameIndex(frameIndex);
|
|
|
|
|
|
|
|
bool tween = DICTOOL->getBooleanValue_json(dic, TWEEN, false);
|
|
|
|
frame->setTween(tween);
|
|
|
|
}
|
|
|
|
|
|
|
|
timeline->addFrame(frame);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return timeline;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
Frame* ActionTimelineCache::loadVisibleFrame(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
VisibleFrame* frame = VisibleFrame::create();
|
|
|
|
|
|
|
|
bool visible = DICTOOL->getBooleanValue_json(json, Value);
|
|
|
|
frame->setVisible(visible);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
Frame* ActionTimelineCache::loadPositionFrame(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
PositionFrame* frame = PositionFrame::create();
|
|
|
|
|
|
|
|
float x = DICTOOL->getFloatValue_json(json, X);
|
|
|
|
float y = DICTOOL->getFloatValue_json(json, Y);
|
2021-12-25 10:04:45 +08:00
|
|
|
frame->setPosition(Point(x, y));
|
2014-06-11 11:10:07 +08:00
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
Frame* ActionTimelineCache::loadScaleFrame(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
ScaleFrame* frame = ScaleFrame::create();
|
2014-06-11 11:10:07 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
float scalex = DICTOOL->getFloatValue_json(json, X);
|
|
|
|
float scaley = DICTOOL->getFloatValue_json(json, Y);
|
2014-06-11 11:10:07 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
frame->setScaleX(scalex);
|
|
|
|
frame->setScaleY(scaley);
|
2014-06-11 11:10:07 +08:00
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
Frame* ActionTimelineCache::loadSkewFrame(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
SkewFrame* frame = SkewFrame::create();
|
|
|
|
|
|
|
|
float skewx = DICTOOL->getFloatValue_json(json, X);
|
|
|
|
float skewy = DICTOOL->getFloatValue_json(json, Y);
|
|
|
|
|
|
|
|
frame->setSkewX(skewx);
|
|
|
|
frame->setSkewY(skewy);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
Frame* ActionTimelineCache::loadRotationSkewFrame(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
RotationSkewFrame* frame = RotationSkewFrame::create();
|
|
|
|
|
|
|
|
float skewx = DICTOOL->getFloatValue_json(json, X);
|
|
|
|
float skewy = DICTOOL->getFloatValue_json(json, Y);
|
|
|
|
|
|
|
|
frame->setSkewX(skewx);
|
|
|
|
frame->setSkewY(skewy);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
Frame* ActionTimelineCache::loadRotationFrame(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
RotationFrame* frame = RotationFrame::create();
|
|
|
|
|
|
|
|
float rotation = DICTOOL->getFloatValue_json(json, ROTATION);
|
|
|
|
frame->setRotation(rotation);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Frame* ActionTimelineCache::loadAnchorPointFrame(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
AnchorPointFrame* frame = AnchorPointFrame::create();
|
|
|
|
|
|
|
|
float anchorx = DICTOOL->getFloatValue_json(json, X);
|
|
|
|
float anchory = DICTOOL->getFloatValue_json(json, Y);
|
|
|
|
|
|
|
|
frame->setAnchorPoint(Point(anchorx, anchory));
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
Frame* ActionTimelineCache::loadInnerActionFrame(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
InnerActionFrame* frame = InnerActionFrame::create();
|
|
|
|
|
|
|
|
InnerActionType type = (InnerActionType)DICTOOL->getIntValue_json(json, INNER_ACTION);
|
2021-12-25 10:04:45 +08:00
|
|
|
int startFrame = DICTOOL->getIntValue_json(json, START_FRAME);
|
2014-06-11 11:10:07 +08:00
|
|
|
|
|
|
|
frame->setInnerActionType(type);
|
|
|
|
frame->setStartFrameIndex(startFrame);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
Frame* ActionTimelineCache::loadColorFrame(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
ColorFrame* frame = ColorFrame::create();
|
|
|
|
|
2019-11-25 01:35:26 +08:00
|
|
|
uint8_t red = (uint8_t)DICTOOL->getIntValue_json(json, RED);
|
|
|
|
uint8_t green = (uint8_t)DICTOOL->getIntValue_json(json, GREEN);
|
|
|
|
uint8_t blue = (uint8_t)DICTOOL->getIntValue_json(json, BLUE);
|
2014-06-11 11:10:07 +08:00
|
|
|
|
|
|
|
frame->setColor(Color3B(red, green, blue));
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
Frame* ActionTimelineCache::loadTextureFrame(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
TextureFrame* frame = TextureFrame::create();
|
|
|
|
|
|
|
|
const char* texture = DICTOOL->getStringValue_json(json, Value);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (texture != nullptr)
|
2014-06-11 21:11:22 +08:00
|
|
|
{
|
|
|
|
std::string path = texture;
|
2014-06-11 11:10:07 +08:00
|
|
|
|
2014-06-11 21:11:22 +08:00
|
|
|
SpriteFrame* spriteFrame = SpriteFrameCache::getInstance()->getSpriteFrameByName(path);
|
2021-12-25 10:04:45 +08:00
|
|
|
if (spriteFrame == nullptr)
|
2014-06-11 21:11:22 +08:00
|
|
|
{
|
2014-10-09 18:28:09 +08:00
|
|
|
std::string jsonPath = CSLoader::getInstance()->getJsonPath();
|
2021-12-25 10:04:45 +08:00
|
|
|
path = jsonPath + texture;
|
2014-06-11 21:11:22 +08:00
|
|
|
}
|
|
|
|
|
2014-06-13 19:52:53 +08:00
|
|
|
frame->setTextureName(path);
|
2014-06-11 21:11:22 +08:00
|
|
|
}
|
2014-06-11 11:10:07 +08:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
Frame* ActionTimelineCache::loadEventFrame(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
EventFrame* frame = EventFrame::create();
|
|
|
|
|
|
|
|
const char* evnt = DICTOOL->getStringValue_json(json, Value);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
if (evnt != nullptr)
|
2014-06-11 11:10:07 +08:00
|
|
|
frame->setEvent(evnt);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2014-06-13 16:03:03 +08:00
|
|
|
Frame* ActionTimelineCache::loadZOrderFrame(const rapidjson::Value& json)
|
2014-06-11 11:10:07 +08:00
|
|
|
{
|
|
|
|
ZOrderFrame* frame = ZOrderFrame::create();
|
|
|
|
|
|
|
|
int zorder = DICTOOL->getIntValue_json(json, Value);
|
|
|
|
frame->setZOrder(zorder);
|
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
2016-01-14 16:16:37 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
ActionTimeline* ActionTimelineCache::createActionWithFlatBuffersFile(std::string_view fileName)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
|
|
|
ActionTimeline* action = _animationActions.at(fileName);
|
2014-11-21 15:15:38 +08:00
|
|
|
if (action == NULL)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
action = loadAnimationActionWithFlatBuffersFile(fileName);
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
return action->clone();
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
ActionTimeline* ActionTimelineCache::createActionWithDataBuffer(Data data, std::string_view fileName)
|
2016-01-14 16:16:37 +08:00
|
|
|
{
|
|
|
|
ActionTimeline* action = _animationActions.at(fileName);
|
|
|
|
if (action == NULL)
|
|
|
|
{
|
|
|
|
action = loadAnimationWithDataBuffer(data, fileName);
|
|
|
|
}
|
|
|
|
return action->clone();
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
ActionTimeline* ActionTimelineCache::loadAnimationActionWithFlatBuffersFile(std::string_view fileName)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
|
|
|
// if already exists an action with filename, then return this action
|
|
|
|
ActionTimeline* action = _animationActions.at(fileName);
|
|
|
|
if (action)
|
|
|
|
return action;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2016-02-03 23:12:37 +08:00
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-12-03 10:54:16 +08:00
|
|
|
CC_ASSERT(FileUtils::getInstance()->isFileExist(fullPath));
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-12-03 10:54:16 +08:00
|
|
|
Data buf = FileUtils::getInstance()->getDataFromFile(fullPath);
|
2021-12-25 10:04:45 +08:00
|
|
|
action = createActionWithDataBuffer(buf);
|
2015-07-27 11:55:18 +08:00
|
|
|
_animationActions.insert(fileName, action);
|
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
ActionTimeline* ActionTimelineCache::loadAnimationWithDataBuffer(const cocos2d::Data& data, std::string_view fileName)
|
2015-07-27 11:55:18 +08:00
|
|
|
{
|
|
|
|
// if already exists an action with filename, then return this action
|
|
|
|
ActionTimeline* action = _animationActions.at(fileName);
|
|
|
|
if (action)
|
|
|
|
return action;
|
|
|
|
|
2016-02-03 23:12:37 +08:00
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(fileName);
|
2015-07-27 11:55:18 +08:00
|
|
|
|
|
|
|
CC_ASSERT(FileUtils::getInstance()->isFileExist(fullPath));
|
|
|
|
|
|
|
|
action = createActionWithDataBuffer(data);
|
|
|
|
_animationActions.insert(fileName, action);
|
|
|
|
|
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2016-01-15 00:49:48 +08:00
|
|
|
ActionTimeline* ActionTimelineCache::createActionWithDataBuffer(const cocos2d::Data& data)
|
2015-07-27 11:55:18 +08:00
|
|
|
{
|
|
|
|
auto csparsebinary = GetCSParseBinary(data.getBytes());
|
|
|
|
|
|
|
|
auto nodeAction = csparsebinary->action();
|
2021-12-25 10:04:45 +08:00
|
|
|
auto action = ActionTimeline::create();
|
2015-07-27 11:55:18 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
int duration = nodeAction->duration();
|
|
|
|
action->setDuration(duration);
|
|
|
|
float speed = nodeAction->speed();
|
|
|
|
action->setTimeSpeed(speed);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
auto animationlist = csparsebinary->animationList();
|
|
|
|
int animationcount = animationlist->size();
|
|
|
|
for (int i = 0; i < animationcount; i++)
|
|
|
|
{
|
|
|
|
auto animationdata = animationlist->Get(i);
|
|
|
|
AnimationInfo info;
|
2021-12-25 10:04:45 +08:00
|
|
|
info.name = animationdata->name()->c_str();
|
2015-01-12 10:55:15 +08:00
|
|
|
info.startIndex = animationdata->startIndex();
|
2021-12-25 10:04:45 +08:00
|
|
|
info.endIndex = animationdata->endIndex();
|
2015-01-12 10:55:15 +08:00
|
|
|
action->addAnimationInfo(info);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
auto timeLines = nodeAction->timeLines();
|
2015-10-20 15:49:12 +08:00
|
|
|
int timelineLength = timeLines->size();
|
2021-12-25 10:04:45 +08:00
|
|
|
std::multimap<std::string, timeline::Timeline*> properTimelineMap; // order the timelines depends property name
|
2014-11-21 15:15:38 +08:00
|
|
|
for (int i = 0; i < timelineLength; i++)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2015-10-20 15:49:12 +08:00
|
|
|
auto timelineFlatBuf = timeLines->Get(i);
|
2021-12-25 10:04:45 +08:00
|
|
|
Timeline* timeline = loadTimelineWithFlatBuffers(timelineFlatBuf);
|
2014-10-09 18:28:09 +08:00
|
|
|
if (timeline)
|
2015-10-20 15:49:12 +08:00
|
|
|
{
|
2016-11-08 11:50:00 +08:00
|
|
|
properTimelineMap.emplace(timelineFlatBuf->property()->c_str(), timeline);
|
2015-10-20 15:49:12 +08:00
|
|
|
}
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
2015-07-27 11:55:18 +08:00
|
|
|
|
2015-10-20 15:49:12 +08:00
|
|
|
for (const auto& properTimelinePair : properTimelineMap)
|
|
|
|
{
|
|
|
|
action->addTimeline(properTimelinePair.second);
|
|
|
|
}
|
2014-10-09 18:28:09 +08:00
|
|
|
return action;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Timeline* ActionTimelineCache::loadTimelineWithFlatBuffers(const flatbuffers::TimeLine* flatbuffers)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
|
|
|
Timeline* timeline = nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
// property
|
|
|
|
std::string property = flatbuffers->property()->c_str();
|
2021-12-25 10:04:45 +08:00
|
|
|
if (property == "")
|
2014-11-21 15:15:38 +08:00
|
|
|
return nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
if (property != "")
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
|
|
|
timeline = Timeline::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
int actionTag = flatbuffers->actionTag();
|
2014-10-09 18:28:09 +08:00
|
|
|
timeline->setActionTag(actionTag);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
auto framesFlatbuf = flatbuffers->frames();
|
2021-12-25 10:04:45 +08:00
|
|
|
int length = framesFlatbuf->size();
|
2014-11-21 15:15:38 +08:00
|
|
|
for (int i = 0; i < length; i++)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
auto frameFlatbuf = framesFlatbuf->Get(i);
|
2021-12-25 10:04:45 +08:00
|
|
|
Frame* frame = nullptr;
|
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
if (property == Property_VisibleForFrame)
|
|
|
|
{
|
|
|
|
auto boolFrame = frameFlatbuf->boolFrame();
|
2021-12-25 10:04:45 +08:00
|
|
|
frame = loadVisibleFrameWithFlatBuffers(boolFrame);
|
2015-01-12 10:55:15 +08:00
|
|
|
}
|
|
|
|
else if (property == Property_Position)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2015-01-12 10:55:15 +08:00
|
|
|
auto potisionFrame = frameFlatbuf->pointFrame();
|
2021-12-25 10:04:45 +08:00
|
|
|
frame = loadPositionFrameWithFlatBuffers(potisionFrame);
|
2015-01-12 10:55:15 +08:00
|
|
|
}
|
|
|
|
else if (property == Property_Scale)
|
|
|
|
{
|
|
|
|
auto scaleFrame = frameFlatbuf->scaleFrame();
|
2021-12-25 10:04:45 +08:00
|
|
|
frame = loadScaleFrameWithFlatBuffers(scaleFrame);
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2015-01-12 10:55:15 +08:00
|
|
|
else if (property == Property_RotationSkew)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2015-01-12 10:55:15 +08:00
|
|
|
auto scaleFrame = frameFlatbuf->scaleFrame();
|
2021-12-25 10:04:45 +08:00
|
|
|
frame = loadRotationSkewFrameWithFlatBuffers(scaleFrame);
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2015-01-12 10:55:15 +08:00
|
|
|
else if (property == Property_CColor)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2015-01-12 10:55:15 +08:00
|
|
|
auto colorFrame = frameFlatbuf->colorFrame();
|
2021-12-25 10:04:45 +08:00
|
|
|
frame = loadColorFrameWithFlatBuffers(colorFrame);
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2015-01-12 10:55:15 +08:00
|
|
|
else if (property == Property_FrameEvent)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
|
|
|
auto eventFrame = frameFlatbuf->eventFrame();
|
2021-12-25 10:04:45 +08:00
|
|
|
frame = loadEventFrameWithFlatBuffers(eventFrame);
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2015-01-12 10:55:15 +08:00
|
|
|
else if (property == Property_FileData)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2015-01-12 10:55:15 +08:00
|
|
|
auto textureFrame = frameFlatbuf->textureFrame();
|
2021-12-25 10:04:45 +08:00
|
|
|
frame = loadTextureFrameWithFlatBuffers(textureFrame);
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2015-01-12 10:55:15 +08:00
|
|
|
else if (property == Property_Alpha)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2015-01-12 10:55:15 +08:00
|
|
|
auto intFrame = frameFlatbuf->intFrame();
|
2021-12-25 10:04:45 +08:00
|
|
|
frame = loadAlphaFrameWithFlatBuffers(intFrame);
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2015-01-22 11:20:01 +08:00
|
|
|
else if (property == Property_AnchorPoint)
|
|
|
|
{
|
|
|
|
auto scaleFrame = frameFlatbuf->scaleFrame();
|
2021-12-25 10:04:45 +08:00
|
|
|
frame = loadAnchorPointFrameWithFlatBuffers(scaleFrame);
|
2015-01-22 11:20:01 +08:00
|
|
|
}
|
2015-01-12 10:55:15 +08:00
|
|
|
else if (property == Property_ZOrder)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2015-01-12 10:55:15 +08:00
|
|
|
auto intFrame = frameFlatbuf->intFrame();
|
2021-12-25 10:04:45 +08:00
|
|
|
frame = loadZOrderFrameWithFlatBuffers(intFrame);
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2015-01-12 10:55:15 +08:00
|
|
|
else if (property == Property_ActionValue)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2015-01-12 10:55:15 +08:00
|
|
|
auto innerActionFrame = frameFlatbuf->innerActionFrame();
|
2021-12-25 10:04:45 +08:00
|
|
|
frame = loadInnerActionFrameWithFlatBuffers(innerActionFrame);
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2015-08-17 13:05:29 +08:00
|
|
|
else if (property == Property_BlendValue)
|
|
|
|
{
|
|
|
|
auto blendFrame = frameFlatbuf->blendFrame();
|
2021-12-25 10:04:45 +08:00
|
|
|
frame = loadBlendFrameWithFlatBuffers(blendFrame);
|
2015-08-17 13:05:29 +08:00
|
|
|
}
|
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
if (!frame)
|
2014-11-21 15:15:38 +08:00
|
|
|
{
|
2015-01-12 10:55:15 +08:00
|
|
|
CCLOG("frame is invalid.");
|
|
|
|
continue;
|
2014-11-21 15:15:38 +08:00
|
|
|
}
|
2014-10-09 18:28:09 +08:00
|
|
|
timeline->addFrame(frame);
|
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
return timeline;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
Frame* ActionTimelineCache::loadVisibleFrameWithFlatBuffers(const flatbuffers::BoolFrame* flatbuffers)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
|
|
|
VisibleFrame* frame = VisibleFrame::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool visible = flatbuffers->value() != 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
frame->setVisible(visible);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
int frameIndex = flatbuffers->frameIndex();
|
|
|
|
frame->setFrameIndex(frameIndex);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool tween = flatbuffers->tween() != 0;
|
2014-11-21 15:15:38 +08:00
|
|
|
frame->setTween(tween);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
auto easingData = flatbuffers->easingData();
|
|
|
|
if (easingData)
|
|
|
|
{
|
|
|
|
loadEasingDataWithFlatBuffers(frame, easingData);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
return frame;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
Frame* ActionTimelineCache::loadPositionFrameWithFlatBuffers(const flatbuffers::PointFrame* flatbuffers)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2015-01-12 10:55:15 +08:00
|
|
|
PositionFrame* frame = PositionFrame::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2016-09-06 10:14:14 +08:00
|
|
|
auto f_position = flatbuffers->position();
|
2015-01-12 10:55:15 +08:00
|
|
|
Vec2 position(f_position->x(), f_position->y());
|
|
|
|
frame->setPosition(position);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
int frameIndex = flatbuffers->frameIndex();
|
|
|
|
frame->setFrameIndex(frameIndex);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool tween = flatbuffers->tween() != 0;
|
2014-11-21 15:15:38 +08:00
|
|
|
frame->setTween(tween);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
auto easingData = flatbuffers->easingData();
|
|
|
|
if (easingData)
|
|
|
|
{
|
|
|
|
loadEasingDataWithFlatBuffers(frame, easingData);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Frame* ActionTimelineCache::loadScaleFrameWithFlatBuffers(const flatbuffers::ScaleFrame* flatbuffers)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2015-01-12 10:55:15 +08:00
|
|
|
ScaleFrame* frame = ScaleFrame::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
auto f_scale = flatbuffers->scale();
|
|
|
|
Vec2 scale(f_scale->scaleX(), f_scale->scaleY());
|
|
|
|
frame->setScaleX(scale.x);
|
|
|
|
frame->setScaleY(scale.y);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
int frameIndex = flatbuffers->frameIndex();
|
|
|
|
frame->setFrameIndex(frameIndex);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool tween = flatbuffers->tween() != 0;
|
2014-11-21 15:15:38 +08:00
|
|
|
frame->setTween(tween);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
auto easingData = flatbuffers->easingData();
|
|
|
|
if (easingData)
|
|
|
|
{
|
|
|
|
loadEasingDataWithFlatBuffers(frame, easingData);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Frame* ActionTimelineCache::loadRotationSkewFrameWithFlatBuffers(const flatbuffers::ScaleFrame* flatbuffers)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2015-01-12 10:55:15 +08:00
|
|
|
RotationSkewFrame* frame = RotationSkewFrame::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
auto f_scale = flatbuffers->scale();
|
|
|
|
Vec2 rotationSkew(f_scale->scaleX(), f_scale->scaleY());
|
|
|
|
frame->setSkewX(rotationSkew.x);
|
|
|
|
frame->setSkewY(rotationSkew.y);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
int frameIndex = flatbuffers->frameIndex();
|
|
|
|
frame->setFrameIndex(frameIndex);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool tween = flatbuffers->tween() != 0;
|
2014-11-21 15:15:38 +08:00
|
|
|
frame->setTween(tween);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
auto easingData = flatbuffers->easingData();
|
|
|
|
if (easingData)
|
|
|
|
{
|
|
|
|
loadEasingDataWithFlatBuffers(frame, easingData);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Frame* ActionTimelineCache::loadColorFrameWithFlatBuffers(const flatbuffers::ColorFrame* flatbuffers)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2014-11-21 15:15:38 +08:00
|
|
|
ColorFrame* frame = ColorFrame::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
auto f_color = flatbuffers->color();
|
|
|
|
Color3B color(f_color->r(), f_color->g(), f_color->b());
|
2021-12-25 10:04:45 +08:00
|
|
|
frame->setColor(color);
|
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
int frameIndex = flatbuffers->frameIndex();
|
|
|
|
frame->setFrameIndex(frameIndex);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool tween = flatbuffers->tween() != 0;
|
2014-11-21 15:15:38 +08:00
|
|
|
frame->setTween(tween);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
auto easingData = flatbuffers->easingData();
|
|
|
|
if (easingData)
|
|
|
|
{
|
|
|
|
loadEasingDataWithFlatBuffers(frame, easingData);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
Frame* ActionTimelineCache::loadTextureFrameWithFlatBuffers(const flatbuffers::TextureFrame* flatbuffers)
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2020-08-04 10:55:30 +08:00
|
|
|
std::string path;
|
2014-12-10 12:36:14 +08:00
|
|
|
int resourceType = 0;
|
2020-08-04 10:55:30 +08:00
|
|
|
std::string plist;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
TextureFrame* frame = TextureFrame::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
auto fileNameData = flatbuffers->textureFile();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-12-10 12:36:14 +08:00
|
|
|
resourceType = fileNameData->resourceType();
|
|
|
|
switch (resourceType)
|
2014-12-08 15:48:24 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
case 0:
|
|
|
|
{
|
|
|
|
path = fileNameData->path()->c_str();
|
|
|
|
// pitfall: use fullPath will lead some asset managment solution not work with ETC1 seperate ALPHA channel.
|
|
|
|
/*if (FileUtils::getInstance()->isFileExist(path))
|
2014-12-10 12:36:14 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
std::string fullPath = FileUtils::getInstance()->fullPathForFilename(path);
|
|
|
|
path = fullPath;
|
2014-12-10 12:36:14 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
plist = fileNameData->plistFile()->c_str();
|
|
|
|
if (FileUtils::getInstance()->isFileExist(plist))
|
2014-12-10 12:36:14 +08:00
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
path = fileNameData->path()->c_str();
|
2014-12-10 12:36:14 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2014-12-08 15:48:24 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
frame->setTextureName(path);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
int frameIndex = flatbuffers->frameIndex();
|
|
|
|
frame->setFrameIndex(frameIndex);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool tween = flatbuffers->tween() != 0;
|
2014-11-21 15:15:38 +08:00
|
|
|
frame->setTween(tween);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
auto easingData = flatbuffers->easingData();
|
|
|
|
if (easingData)
|
|
|
|
{
|
|
|
|
loadEasingDataWithFlatBuffers(frame, easingData);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
return frame;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
Frame* ActionTimelineCache::loadEventFrameWithFlatBuffers(const flatbuffers::EventFrame* flatbuffers)
|
2015-01-12 10:55:15 +08:00
|
|
|
{
|
|
|
|
EventFrame* frame = EventFrame::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
std::string event = flatbuffers->value()->c_str();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
if (event != "")
|
2021-12-25 10:04:45 +08:00
|
|
|
frame->setEvent(event);
|
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
int frameIndex = flatbuffers->frameIndex();
|
|
|
|
frame->setFrameIndex(frameIndex);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool tween = flatbuffers->tween() != 0;
|
2015-01-12 10:55:15 +08:00
|
|
|
frame->setTween(tween);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
auto easingData = flatbuffers->easingData();
|
|
|
|
if (easingData)
|
|
|
|
{
|
|
|
|
loadEasingDataWithFlatBuffers(frame, easingData);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
return frame;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
Frame* ActionTimelineCache::loadAlphaFrameWithFlatBuffers(const flatbuffers::IntFrame* flatbuffers)
|
2015-01-12 10:55:15 +08:00
|
|
|
{
|
|
|
|
AlphaFrame* frame = AlphaFrame::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
int alpha = flatbuffers->value();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
frame->setAlpha(alpha);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
int frameIndex = flatbuffers->frameIndex();
|
|
|
|
frame->setFrameIndex(frameIndex);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool tween = flatbuffers->tween() != 0;
|
2015-01-12 10:55:15 +08:00
|
|
|
frame->setTween(tween);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
return frame;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
Frame* ActionTimelineCache::loadAnchorPointFrameWithFlatBuffers(const flatbuffers::ScaleFrame* flatbuffers)
|
2015-04-09 16:55:15 +08:00
|
|
|
{
|
|
|
|
AnchorPointFrame* frame = AnchorPointFrame::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
auto f_scale = flatbuffers->scale();
|
|
|
|
Vec2 scale(f_scale->scaleX(), f_scale->scaleY());
|
|
|
|
frame->setAnchorPoint(scale);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
int frameIndex = flatbuffers->frameIndex();
|
|
|
|
frame->setFrameIndex(frameIndex);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
bool tween = flatbuffers->tween() != 0;
|
|
|
|
frame->setTween(tween);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
auto easingData = flatbuffers->easingData();
|
|
|
|
if (easingData)
|
2015-01-22 11:20:01 +08:00
|
|
|
{
|
2015-04-09 16:55:15 +08:00
|
|
|
loadEasingDataWithFlatBuffers(frame, easingData);
|
2015-01-22 11:20:01 +08:00
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
return frame;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
Frame* ActionTimelineCache::loadZOrderFrameWithFlatBuffers(const flatbuffers::IntFrame* flatbuffers)
|
2015-01-12 10:55:15 +08:00
|
|
|
{
|
|
|
|
ZOrderFrame* frame = ZOrderFrame::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
int zorder = flatbuffers->value();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
frame->setZOrder(zorder);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
int frameIndex = flatbuffers->frameIndex();
|
|
|
|
frame->setFrameIndex(frameIndex);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool tween = flatbuffers->tween() != 0;
|
2015-01-12 10:55:15 +08:00
|
|
|
frame->setTween(tween);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
auto easingData = flatbuffers->easingData();
|
|
|
|
if (easingData)
|
|
|
|
{
|
|
|
|
loadEasingDataWithFlatBuffers(frame, easingData);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
return frame;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
Frame* ActionTimelineCache::loadInnerActionFrameWithFlatBuffers(const flatbuffers::InnerActionFrame* flatbuffers)
|
2015-01-12 10:55:15 +08:00
|
|
|
{
|
|
|
|
InnerActionFrame* frame = InnerActionFrame::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
InnerActionType innerActionType = (InnerActionType)flatbuffers->innerActionType();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
std::string currentAnimationFrame = flatbuffers->currentAniamtionName()->c_str();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
int singleFrameIndex = flatbuffers->singleFrameIndex();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
int frameIndex = flatbuffers->frameIndex();
|
|
|
|
frame->setFrameIndex(frameIndex);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-23 09:02:33 +08:00
|
|
|
bool tween = flatbuffers->tween() != 0;
|
2015-01-12 10:55:15 +08:00
|
|
|
frame->setTween(tween);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
frame->setInnerActionType(innerActionType);
|
|
|
|
frame->setSingleFrameIndex(singleFrameIndex);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
frame->setEnterWithName(true);
|
|
|
|
frame->setAnimationName(currentAnimationFrame);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-04-09 16:55:15 +08:00
|
|
|
auto easingData = flatbuffers->easingData();
|
|
|
|
if (easingData)
|
|
|
|
{
|
|
|
|
loadEasingDataWithFlatBuffers(frame, easingData);
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
return frame;
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-08-17 13:05:29 +08:00
|
|
|
Frame* ActionTimelineCache::loadBlendFrameWithFlatBuffers(const flatbuffers::BlendFrame* flatbuffers)
|
|
|
|
{
|
|
|
|
BlendFuncFrame* frame = BlendFuncFrame::create();
|
|
|
|
cocos2d::BlendFunc blend;
|
2019-11-25 01:35:26 +08:00
|
|
|
blend.src = backend::BlendFactor::ONE;
|
|
|
|
blend.dst = backend::BlendFactor::ONE_MINUS_SRC_ALPHA;
|
2015-08-17 13:05:29 +08:00
|
|
|
if (nullptr != flatbuffers->blendFunc())
|
|
|
|
{
|
2019-11-25 01:35:26 +08:00
|
|
|
blend.src = utils::toBackendBlendFactor(flatbuffers->blendFunc()->src());
|
|
|
|
blend.dst = utils::toBackendBlendFactor(flatbuffers->blendFunc()->dst());
|
2015-08-17 13:05:29 +08:00
|
|
|
}
|
|
|
|
frame->setBlendFunc(blend);
|
|
|
|
|
|
|
|
int frameIndex = flatbuffers->frameIndex();
|
|
|
|
frame->setFrameIndex(frameIndex);
|
|
|
|
|
|
|
|
bool tween = flatbuffers->tween() != 0;
|
|
|
|
frame->setTween(tween);
|
|
|
|
|
2015-08-17 16:19:29 +08:00
|
|
|
// easing data won't use in blend frame
|
2021-12-25 10:04:45 +08:00
|
|
|
// auto easingData = flatbuffers->easingData();
|
|
|
|
// if (easingData)
|
2015-08-17 16:19:29 +08:00
|
|
|
//{
|
|
|
|
// loadEasingDataWithFlatBuffers(frame, easingData);
|
|
|
|
//}
|
2015-08-17 13:05:29 +08:00
|
|
|
|
|
|
|
return frame;
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
void ActionTimelineCache::loadEasingDataWithFlatBuffers(cocostudio::timeline::Frame* frame,
|
|
|
|
const flatbuffers::EasingData* flatbuffers)
|
2015-04-09 16:55:15 +08:00
|
|
|
{
|
|
|
|
int type = flatbuffers->type();
|
|
|
|
frame->setTweenType((cocos2d::tweenfunc::TweenType)type);
|
|
|
|
auto points = flatbuffers->points();
|
|
|
|
if (points)
|
|
|
|
{
|
2015-04-10 17:05:55 +08:00
|
|
|
std::vector<float> easings;
|
2015-04-09 16:55:15 +08:00
|
|
|
for (auto it = points->begin(); it != points->end(); ++it)
|
|
|
|
{
|
|
|
|
easings.push_back(it->x());
|
|
|
|
easings.push_back(it->y());
|
|
|
|
}
|
2015-04-10 17:05:55 +08:00
|
|
|
frame->setEasingParams(easings);
|
2015-04-09 16:55:15 +08:00
|
|
|
}
|
|
|
|
}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
ActionTimeline* ActionTimelineCache::createActionWithFlatBuffersForSimulator(std::string_view fileName)
|
2014-12-08 14:32:33 +08:00
|
|
|
{
|
|
|
|
FlatBuffersSerialize* fbs = FlatBuffersSerialize::getInstance();
|
2021-12-25 10:04:45 +08:00
|
|
|
fbs->_isSimulator = true;
|
|
|
|
auto builder = fbs->createFlatBuffersWithXMLFileForSimulator(fileName);
|
|
|
|
|
2014-12-08 14:32:33 +08:00
|
|
|
auto csparsebinary = GetCSParseBinary(builder->GetBufferPointer());
|
2021-12-25 10:04:45 +08:00
|
|
|
auto nodeAction = csparsebinary->action();
|
|
|
|
|
2017-02-08 13:58:11 +08:00
|
|
|
auto action = ActionTimeline::create();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-12-08 14:32:33 +08:00
|
|
|
int duration = nodeAction->duration();
|
|
|
|
action->setDuration(duration);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2014-12-08 14:32:33 +08:00
|
|
|
float speed = nodeAction->speed();
|
|
|
|
action->setTimeSpeed(speed);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
auto animationlist = csparsebinary->animationList();
|
|
|
|
int animationcount = animationlist->size();
|
|
|
|
for (int i = 0; i < animationcount; i++)
|
|
|
|
{
|
|
|
|
auto animationdata = animationlist->Get(i);
|
|
|
|
AnimationInfo info;
|
2021-12-25 10:04:45 +08:00
|
|
|
info.name = animationdata->name()->c_str();
|
2015-01-12 10:55:15 +08:00
|
|
|
info.startIndex = animationdata->startIndex();
|
2021-12-25 10:04:45 +08:00
|
|
|
info.endIndex = animationdata->endIndex();
|
2015-01-12 10:55:15 +08:00
|
|
|
action->addAnimationInfo(info);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
auto timeLines = nodeAction->timeLines();
|
2014-12-08 14:32:33 +08:00
|
|
|
int timelineLength = timeLines->size();
|
2021-12-25 10:04:45 +08:00
|
|
|
std::multimap<std::string, cocostudio::timeline::Timeline*>
|
|
|
|
properTimelineMap; // order the timelines depends property name
|
2014-12-08 14:32:33 +08:00
|
|
|
for (int i = 0; i < timelineLength; i++)
|
|
|
|
{
|
|
|
|
auto timelineFlatBuf = timeLines->Get(i);
|
2021-12-25 10:04:45 +08:00
|
|
|
Timeline* timeline = loadTimelineWithFlatBuffers(timelineFlatBuf);
|
2014-12-08 14:32:33 +08:00
|
|
|
if (timeline)
|
2015-10-20 15:49:12 +08:00
|
|
|
{
|
2016-11-08 11:50:00 +08:00
|
|
|
properTimelineMap.emplace(timelineFlatBuf->property()->c_str(), timeline);
|
2015-10-20 15:49:12 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const auto& properTimelinePair : properTimelineMap)
|
|
|
|
{
|
|
|
|
action->addTimeline(properTimelinePair.second);
|
2014-12-08 14:32:33 +08:00
|
|
|
}
|
|
|
|
fbs->deleteFlatBufferBuilder();
|
|
|
|
return action;
|
|
|
|
}
|
2014-06-11 11:10:07 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
} // namespace timeline
|
|
|
|
} // namespace cocostudio
|