2021-12-31 12:12:40 +08:00
|
|
|
/****************************************************************************
|
2019-11-23 20:27:39 +08:00
|
|
|
Copyright (c) 2013 cocos2d-x.org
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-10-01 16:24:52 +08:00
|
|
|
https://axmolengine.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +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:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __cocos2d_libs__CSLoader__
|
|
|
|
#define __cocos2d_libs__CSLoader__
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#include "DictionaryHelper.h"
|
|
|
|
#include "CocosStudioExport.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#include "base/ObjectFactory.h"
|
|
|
|
#include "base/CCData.h"
|
|
|
|
#include "ui/UIWidget.h"
|
|
|
|
|
|
|
|
namespace flatbuffers
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
class FlatBufferBuilder;
|
|
|
|
|
|
|
|
struct NodeTree;
|
|
|
|
|
|
|
|
struct WidgetOptions;
|
|
|
|
struct SingleNodeOptions;
|
|
|
|
struct SpriteOptions;
|
|
|
|
struct ParticleSystemOptions;
|
|
|
|
struct TMXTiledMapOptions;
|
|
|
|
struct ProjectNodeOptions;
|
|
|
|
|
|
|
|
struct ComponentOptions;
|
|
|
|
struct ComAudioOptions;
|
|
|
|
} // namespace flatbuffers
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
namespace cocostudio
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
class ComAudio;
|
2019-11-23 20:27:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace cocostudio
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
namespace timeline
|
|
|
|
{
|
|
|
|
class ActionTimeline;
|
|
|
|
class ActionTimelineNode;
|
|
|
|
} // namespace timeline
|
|
|
|
} // namespace cocostudio
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
typedef std::function<void(Ref*)> ccNodeLoadCallback;
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
class CCS_DLL CSLoader
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static CSLoader* getInstance();
|
|
|
|
static void destroyInstance();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
CSLoader();
|
|
|
|
/** @deprecated Use method destroyInstance() instead */
|
2022-07-16 10:43:05 +08:00
|
|
|
AX_DEPRECATED_ATTRIBUTE void purge();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
void init();
|
2019-11-24 23:15:56 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
static ax::Node* createNode(std::string_view filename);
|
|
|
|
static ax::Node* createNode(std::string_view filename, const ccNodeLoadCallback& callback);
|
|
|
|
static ax::Node* createNode(const Data& data);
|
|
|
|
static ax::Node* createNode(const Data& data, const ccNodeLoadCallback& callback);
|
|
|
|
static ax::Node* createNodeWithVisibleSize(std::string_view filename);
|
|
|
|
static ax::Node* createNodeWithVisibleSize(std::string_view filename, const ccNodeLoadCallback& callback);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
static cocostudio::timeline::ActionTimeline* createTimeline(std::string_view filename);
|
|
|
|
static cocostudio::timeline::ActionTimeline* createTimeline(const Data& data, std::string_view filename);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/*
|
2021-12-31 12:12:40 +08:00
|
|
|
static cocostudio::timeline::ActionTimelineNode* createActionTimelineNode(std::string_view filename);
|
|
|
|
static cocostudio::timeline::ActionTimelineNode* createActionTimelineNode(std::string_view filename, int
|
2021-12-25 10:04:45 +08:00
|
|
|
startIndex, int endIndex, bool loop);
|
2019-11-23 20:27:39 +08:00
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* createNodeFromJson(std::string_view filename);
|
|
|
|
ax::Node* loadNodeWithFile(std::string_view fileName);
|
|
|
|
ax::Node* loadNodeWithContent(std::string_view content);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
void setRecordJsonPath(bool record) { _recordJsonPath = record; }
|
|
|
|
bool isRecordJsonPath() const { return _recordJsonPath; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
void setJsonPath(std::string jsonPath) { _jsonPath = jsonPath; }
|
|
|
|
std::string getJsonPath() const { return _jsonPath; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* createNodeWithFlatBuffersFile(std::string_view filename);
|
|
|
|
ax::Node* nodeWithFlatBuffersFile(std::string_view fileName);
|
|
|
|
ax::Node* nodeWithFlatBuffers(const flatbuffers::NodeTree* nodetree);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
bool bindCallback(std::string_view callbackName,
|
|
|
|
std::string_view callbackType,
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::ui::Widget* sender,
|
|
|
|
ax::Node* handler);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
void registReaderObject(std::string_view className, ObjectFactory::Instance ins);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* createNodeWithFlatBuffersForSimulator(std::string_view filename);
|
|
|
|
ax::Node* nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree* nodetree);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
protected:
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* createNodeWithFlatBuffersFile(std::string_view filename, const ccNodeLoadCallback& callback);
|
|
|
|
ax::Node* nodeWithFlatBuffersFile(std::string_view fileName, const ccNodeLoadCallback& callback);
|
|
|
|
ax::Node* nodeWithFlatBuffers(const flatbuffers::NodeTree* nodetree, const ccNodeLoadCallback& callback);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* loadNode(const rapidjson::Value& json);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
void locateNodeWithMulresPosition(ax::Node* node, const rapidjson::Value& json);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
void initNode(ax::Node* node, const rapidjson::Value& json);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// load nodes
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* loadSimpleNode(const rapidjson::Value& json);
|
|
|
|
ax::Node* loadSubGraph(const rapidjson::Value& json);
|
|
|
|
ax::Node* loadSprite(const rapidjson::Value& json);
|
|
|
|
ax::Node* loadParticle(const rapidjson::Value& json);
|
|
|
|
ax::Node* loadTMXTiledMap(const rapidjson::Value& json);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// load gui
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Node* loadWidget(const rapidjson::Value& json);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
// load component
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Component* loadComponent(const rapidjson::Value& json);
|
|
|
|
ax::Component* loadComAudio(const rapidjson::Value& json);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
bool isWidget(std::string_view type);
|
|
|
|
bool isCustomWidget(std::string_view type);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2021-12-31 12:12:40 +08:00
|
|
|
std::string_view getGUIClassName(std::string_view name);
|
2022-08-08 18:02:17 +08:00
|
|
|
std::string_view getWidgetReaderClassName(ax::ui::Widget* widget);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
inline void reconstructNestNode(ax::Node* node);
|
2021-12-31 12:12:40 +08:00
|
|
|
static inline std::string_view getExtentionName(std::string_view name);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
typedef std::function<ax::Node*(const rapidjson::Value& json)> NodeCreateFunc;
|
2019-11-23 20:27:39 +08:00
|
|
|
typedef std::pair<std::string, NodeCreateFunc> Pair;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
std::unordered_map<std::string, NodeCreateFunc> _funcs;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-08-08 18:02:17 +08:00
|
|
|
typedef std::function<ax::Component*(const rapidjson::Value& json)> ComponentCreateFunc;
|
2019-11-23 20:27:39 +08:00
|
|
|
typedef std::pair<std::string, ComponentCreateFunc> ComponentPair;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
std::unordered_map<std::string, ComponentCreateFunc> _componentFuncs;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
bool _recordJsonPath;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string _jsonPath;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string _monoCocos2dxVersion;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Node* _rootNode;
|
2022-08-08 18:02:17 +08:00
|
|
|
ax::Vector<ax::Node*> _callbackHandlers;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
std::string _csBuildID;
|
|
|
|
};
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif /* defined(__cocos2d_libs__CSLoader__) */
|