axmol/extensions/cocostudio/WidgetReader/NodeReaderProtocol.cpp

155 lines
5.0 KiB
C++
Raw Normal View History

2020-10-17 16:32:16 +08:00
//
// NodeReaderProtocol.cpp
// cocos2d_libs
2021-12-25 10:04:45 +08:00
//
2020-10-17 16:32:16 +08:00
// Created by pipu on 14/11/18.
//
//
#include "WidgetReader/NodeReaderProtocol.h"
2021-12-25 10:04:45 +08:00
#include "CSParseBinary_generated.h" // flatbuffers::ResourceData, it's ok for all revision of loaders
2020-10-17 16:32:16 +08:00
#include "cocos2d.h"
#include "ui/CocosGUI.h"
#include "CCArmature.h"
#include "ActionTimeline/CCSkeletonNode.h"
2020-10-17 16:32:16 +08:00
// x-studio spec, csb batch load support, assets hook functions.
2022-08-08 18:02:17 +08:00
static bool onLoadObjectAssetDummy(ax::Node*, ax::ResourceData& assets, int index)
2020-10-17 16:32:16 +08:00
{
return false;
}
2021-12-25 10:04:45 +08:00
template <typename _T>
2020-10-17 16:32:16 +08:00
static _T* object_create_func()
{
return _T::create();
}
2022-08-08 18:02:17 +08:00
static ax::Node* createArmatureNode()
2020-10-17 16:32:16 +08:00
{
return cocostudio::Armature::create();
}
2022-08-08 18:02:17 +08:00
static ax::ParticleSystemQuad* createParticleSystemQuad(std::string_view path)
2021-12-25 10:04:45 +08:00
{
2022-08-08 18:02:17 +08:00
return ax::ParticleSystemQuad::create(path);
2020-10-17 16:32:16 +08:00
}
2022-08-08 18:02:17 +08:00
static ax::Node* createNestingNode(std::string)
2021-12-25 10:04:45 +08:00
{
2022-08-08 18:02:17 +08:00
return ax::Node::create();
2020-10-17 16:32:16 +08:00
}
2021-12-25 10:04:45 +08:00
static void onLoadSpriteFramesWithFileDummy(std::string&) {}
2020-10-17 16:32:16 +08:00
2020-10-19 23:21:40 +08:00
namespace cocostudio
{
2021-12-25 10:04:45 +08:00
NodeReaderProtocol::NodeReaderProtocol(){};
NodeReaderProtocol::~NodeReaderProtocol(){};
void NodeReaderProtocol::setCurrentCustomClassName(const char* className){};
} // namespace cocostudio
NS_AX_BEGIN
2021-12-25 10:04:45 +08:00
namespace wext
{
2022-08-08 18:02:17 +08:00
bool (*onBeforeLoadObjectAsset)(ax::Node*,
ax::ResourceData& assets,
int index /*= 0*/) = &onLoadObjectAssetDummy;
2022-08-08 18:02:17 +08:00
bool (*onAfterLoadObjectAsset)(ax::Node*,
ax::ResourceData& assets,
int index /*= 0*/) = &onLoadObjectAssetDummy;
void (*onLoadSpriteFramesWithFile)(std::string& file) = nullptr;
void (*onNestingNodeLoading)(std::string_view filePath) = nullptr;
2022-08-08 18:02:17 +08:00
void (*onNestingNodeLoaded)(ax::Node*, std::string_view filePath) = nullptr;
ax::Node* (*aNode)();
ax::ui::Widget* (*aWidget)();
ax::Sprite* (*aSprite)();
ax::ui::ImageView* (*aImageView)();
ax::ui::Button* (*aButton)();
ax::ui::CheckBox* (*aCheckBox)();
ax::ui::Slider* (*aSlider)();
ax::ui::LoadingBar* (*aLoadingBar)();
ax::ui::Text* (*aText)();
ax::ui::TextField* (*aTextField)();
ax::ui::TextAtlas* (*aTextAtlas)();
ax::ui::TextBMFont* (*aTextBMFont)();
ax::ui::Layout* (*aLayout)();
ax::ui::ScrollView* (*aScrollView)();
ax::ui::ListView* (*aListView)();
ax::ui::PageView* (*aPageView)();
ax::ParticleSystemQuad* (*aParticleSystemQuad)(std::string_view);
ax::Node* (*aArmatureNode)();
2021-12-25 10:04:45 +08:00
cocostudio::timeline::SkeletonNode* (*aSkeletonNode)();
cocostudio::timeline::BoneNode* (*aBoneNode)();
2022-08-08 18:02:17 +08:00
ax::Node* (*aNestingNode)(std::string);
2021-12-25 10:04:45 +08:00
// 3d stubs
2022-08-08 18:02:17 +08:00
ax::Node* (*aNode3D)();
ax::Node* (*aGameNode3D)();
ax::Node* (*aLight3D)();
ax::Camera* (*aCamera)();
ax::MeshRenderer* (*aSprite3D)();
ax::Node* (*aParticleSystem3D)();
2021-12-25 10:04:45 +08:00
void resetReaderAllHooks()
{
onLoadSpriteFramesWithFile = onLoadSpriteFramesWithFileDummy;
onBeforeLoadObjectAsset = onLoadObjectAssetDummy;
onAfterLoadObjectAsset = onLoadObjectAssetDummy;
onNestingNodeLoaded = nullptr;
onNestingNodeLoading = nullptr;
aNode = object_create_func<Node>;
aSprite = object_create_func<Sprite>;
aWidget = object_create_func<ui::Widget>;
aImageView = object_create_func<ui::ImageView>;
aButton = object_create_func<ui::Button>;
aCheckBox = object_create_func<ui::CheckBox>;
aSlider = object_create_func<ui::Slider>;
aLoadingBar = object_create_func<ui::LoadingBar>;
aText = object_create_func<ui::Text>;
aTextField = object_create_func<ui::TextField>;
aTextAtlas = object_create_func<ui::TextAtlas>;
aTextBMFont = object_create_func<ui::TextBMFont>;
aLayout = object_create_func<ui::Layout>;
aScrollView = object_create_func<ui::ScrollView>;
aListView = object_create_func<ui::ListView>;
aPageView = object_create_func<ui::PageView>;
aSkeletonNode = object_create_func<cocostudio::timeline::SkeletonNode>;
aBoneNode = object_create_func<cocostudio::timeline::BoneNode>;
aArmatureNode = createArmatureNode;
aParticleSystemQuad = &createParticleSystemQuad;
aNestingNode = createNestingNode;
2020-10-19 23:21:40 +08:00
}
2021-12-25 10:04:45 +08:00
static uint8_t _AUTO_INIT_VARS = (resetReaderAllHooks(), 0);
} // namespace wext
2022-08-08 18:02:17 +08:00
NS_AX_END // namespace axys
2020-10-17 16:32:16 +08:00
2022-08-08 18:02:17 +08:00
ax::ResourceData ax::wext::makeResourceData(const flatbuffers::ResourceData* orig)
2020-10-17 16:32:16 +08:00
{
2022-08-08 18:02:17 +08:00
ax::ResourceData fileData;
2021-12-25 10:04:45 +08:00
fileData.file = orig->path()->c_str();
2020-10-17 16:32:16 +08:00
fileData.plist = orig->plistFile()->c_str();
2021-12-25 10:04:45 +08:00
fileData.type = orig->resourceType();
2020-10-17 16:32:16 +08:00
return fileData;
}
2022-08-08 18:02:17 +08:00
ax::ResourceData ax::wext::makeResourceData(std::string_view path, int type)
2020-10-17 16:32:16 +08:00
{
2022-08-08 18:02:17 +08:00
ax::ResourceData fileData;
2020-10-17 16:32:16 +08:00
fileData.file = path;
fileData.type = type;
return fileData;
}
2022-08-08 18:02:17 +08:00
ax::ResourceData ax::wext::makeResourceData(std::string&& path, int type)
2020-10-17 16:32:16 +08:00
{
2022-08-08 18:02:17 +08:00
ax::ResourceData fileData;
2020-10-17 16:32:16 +08:00
fileData.file = std::move(path);
fileData.type = type;
return fileData;
}