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.
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
2020-10-21 10:12:00 +08:00
|
|
|
#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"
|
2020-10-21 10:12:00 +08:00
|
|
|
#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.
|
|
|
|
static bool onLoadObjectAssetDummy(cocos2d::Node*, cocos2d::ResourceData& assets, int index)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
static cocos2d::Node* createArmatureNode()
|
|
|
|
{
|
|
|
|
return cocostudio::Armature::create();
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
static cocos2d::ParticleSystemQuad* createParticleSystemQuad(std::string_view path)
|
2021-12-25 10:04:45 +08:00
|
|
|
{
|
2020-10-17 16:32:16 +08:00
|
|
|
return cocos2d::ParticleSystemQuad::create(path);
|
|
|
|
}
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
static cocos2d::Node* createNestingNode(std::string)
|
|
|
|
{
|
2020-10-17 16:32:16 +08:00
|
|
|
return cocos2d::Node::create();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
|
namespace cocos2d
|
|
|
|
{
|
|
|
|
namespace wext
|
|
|
|
{
|
|
|
|
bool (*onBeforeLoadObjectAsset)(cocos2d::Node*,
|
|
|
|
cocos2d::ResourceData& assets,
|
2021-12-28 11:00:34 +08:00
|
|
|
int index /*= 0*/) = &onLoadObjectAssetDummy;
|
2021-12-25 10:04:45 +08:00
|
|
|
bool (*onAfterLoadObjectAsset)(cocos2d::Node*,
|
|
|
|
cocos2d::ResourceData& assets,
|
2021-12-28 11:00:34 +08:00
|
|
|
int index /*= 0*/) = &onLoadObjectAssetDummy;
|
|
|
|
void (*onLoadSpriteFramesWithFile)(std::string& file) = nullptr;
|
2021-12-26 23:26:34 +08:00
|
|
|
void (*onNestingNodeLoading)(std::string_view filePath) = nullptr;
|
|
|
|
void (*onNestingNodeLoaded)(cocos2d::Node*, std::string_view filePath) = nullptr;
|
2021-12-25 10:04:45 +08:00
|
|
|
cocos2d::Node* (*aNode)();
|
|
|
|
cocos2d::ui::Widget* (*aWidget)();
|
|
|
|
cocos2d::Sprite* (*aSprite)();
|
|
|
|
cocos2d::ui::ImageView* (*aImageView)();
|
|
|
|
cocos2d::ui::Button* (*aButton)();
|
|
|
|
cocos2d::ui::CheckBox* (*aCheckBox)();
|
|
|
|
cocos2d::ui::Slider* (*aSlider)();
|
|
|
|
cocos2d::ui::LoadingBar* (*aLoadingBar)();
|
|
|
|
cocos2d::ui::Text* (*aText)();
|
|
|
|
cocos2d::ui::TextField* (*aTextField)();
|
|
|
|
cocos2d::ui::TextAtlas* (*aTextAtlas)();
|
|
|
|
cocos2d::ui::TextBMFont* (*aTextBMFont)();
|
|
|
|
cocos2d::ui::Layout* (*aLayout)();
|
|
|
|
cocos2d::ui::ScrollView* (*aScrollView)();
|
|
|
|
cocos2d::ui::ListView* (*aListView)();
|
|
|
|
cocos2d::ui::PageView* (*aPageView)();
|
2021-12-27 13:52:08 +08:00
|
|
|
cocos2d::ParticleSystemQuad* (*aParticleSystemQuad)(std::string_view);
|
2021-12-25 10:04:45 +08:00
|
|
|
cocos2d::Node* (*aArmatureNode)();
|
|
|
|
cocostudio::timeline::SkeletonNode* (*aSkeletonNode)();
|
|
|
|
cocostudio::timeline::BoneNode* (*aBoneNode)();
|
|
|
|
cocos2d::Node* (*aNestingNode)(std::string);
|
|
|
|
|
|
|
|
// 3d stubs
|
|
|
|
cocos2d::Node* (*aNode3D)();
|
|
|
|
cocos2d::Node* (*aGameNode3D)();
|
|
|
|
cocos2d::Node* (*aLight3D)();
|
|
|
|
cocos2d::Camera* (*aCamera)();
|
|
|
|
cocos2d::Sprite3D* (*aSprite3D)();
|
|
|
|
cocos2d::Node* (*aParticleSystem3D)();
|
|
|
|
|
|
|
|
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
|
|
|
|
}; // namespace cocos2d
|
2020-10-17 16:32:16 +08:00
|
|
|
|
|
|
|
cocos2d::ResourceData cocos2d::wext::makeResourceData(const flatbuffers::ResourceData* orig)
|
|
|
|
{
|
|
|
|
cocos2d::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;
|
|
|
|
}
|
|
|
|
|
2021-12-26 23:26:34 +08:00
|
|
|
cocos2d::ResourceData cocos2d::wext::makeResourceData(std::string_view path, int type)
|
2020-10-17 16:32:16 +08:00
|
|
|
{
|
|
|
|
cocos2d::ResourceData fileData;
|
|
|
|
fileData.file = path;
|
|
|
|
fileData.type = type;
|
|
|
|
return fileData;
|
|
|
|
}
|
|
|
|
|
|
|
|
cocos2d::ResourceData cocos2d::wext::makeResourceData(std::string&& path, int type)
|
|
|
|
{
|
|
|
|
cocos2d::ResourceData fileData;
|
|
|
|
fileData.file = std::move(path);
|
|
|
|
fileData.type = type;
|
|
|
|
return fileData;
|
|
|
|
}
|