2014-10-09 18:28:09 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __cocos2d_libs__CSLoader__
|
|
|
|
#define __cocos2d_libs__CSLoader__
|
|
|
|
|
|
|
|
#include "cocostudio/DictionaryHelper.h"
|
|
|
|
#include "cocostudio/CocosStudioExport.h"
|
|
|
|
#include "cocos2d.h"
|
2014-11-27 16:49:19 +08:00
|
|
|
#include "base/ObjectFactory.h"
|
2014-10-09 18:28:09 +08:00
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
namespace flatbuffers
|
2014-10-09 18:28:09 +08:00
|
|
|
{
|
2014-12-15 02:04:14 +08:00
|
|
|
class FlatBufferBuilder;
|
2014-11-21 15:15:38 +08:00
|
|
|
|
|
|
|
struct NodeTree;
|
|
|
|
|
|
|
|
struct WidgetOptions;
|
|
|
|
struct SingleNodeOptions;
|
|
|
|
struct SpriteOptions;
|
|
|
|
struct ParticleSystemOptions;
|
|
|
|
struct TMXTiledMapOptions;
|
|
|
|
struct ProjectNodeOptions;
|
|
|
|
|
|
|
|
struct ComponentOptions;
|
|
|
|
struct ComAudioOptions;
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
class ComAudio;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace cocostudio
|
|
|
|
{
|
|
|
|
namespace timeline
|
|
|
|
{
|
|
|
|
class ActionTimeline;
|
2014-11-17 21:05:20 +08:00
|
|
|
class ActionTimelineNode;
|
2014-10-09 18:28:09 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2015-03-12 17:36:39 +08:00
|
|
|
typedef std::function<void(Ref*)> ccNodeLoadCallback;
|
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
class CC_STUDIO_DLL CSLoader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static CSLoader* getInstance();
|
|
|
|
static void destroyInstance();
|
|
|
|
|
|
|
|
CSLoader();
|
|
|
|
void purge();
|
|
|
|
|
|
|
|
void init();
|
|
|
|
|
|
|
|
static cocos2d::Node* createNode(const std::string& filename);
|
2015-03-12 17:36:39 +08:00
|
|
|
static cocos2d::Node* createNode(const std::string& filename, const ccNodeLoadCallback& callback);
|
2014-10-09 18:28:09 +08:00
|
|
|
static cocostudio::timeline::ActionTimeline* createTimeline(const std::string& filename);
|
2014-11-17 21:05:20 +08:00
|
|
|
|
2015-01-12 10:55:15 +08:00
|
|
|
/*
|
2014-11-17 21:05:20 +08:00
|
|
|
static cocostudio::timeline::ActionTimelineNode* createActionTimelineNode(const std::string& filename);
|
|
|
|
static cocostudio::timeline::ActionTimelineNode* createActionTimelineNode(const std::string& filename, int startIndex, int endIndex, bool loop);
|
2015-01-12 10:55:15 +08:00
|
|
|
*/
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
cocos2d::Node* createNodeFromJson(const std::string& filename);
|
|
|
|
cocos2d::Node* loadNodeWithFile(const std::string& fileName);
|
|
|
|
cocos2d::Node* loadNodeWithContent(const std::string& content);
|
|
|
|
|
|
|
|
void setRecordJsonPath(bool record) { _recordJsonPath = record; }
|
|
|
|
bool isRecordJsonPath() const { return _recordJsonPath; }
|
|
|
|
|
|
|
|
void setJsonPath(std::string jsonPath) { _jsonPath = jsonPath; }
|
|
|
|
std::string getJsonPath() const { return _jsonPath; }
|
|
|
|
|
2014-11-21 15:15:38 +08:00
|
|
|
cocos2d::Node* createNodeWithFlatBuffersFile(const std::string& filename);
|
|
|
|
cocos2d::Node* nodeWithFlatBuffersFile(const std::string& fileName);
|
|
|
|
cocos2d::Node* nodeWithFlatBuffers(const flatbuffers::NodeTree* nodetree);
|
2014-10-09 18:28:09 +08:00
|
|
|
|
2014-11-27 16:49:19 +08:00
|
|
|
bool bindCallback(const std::string& callbackName,
|
|
|
|
const std::string& callbackType,
|
|
|
|
cocos2d::ui::Widget* sender,
|
|
|
|
cocos2d::Node* handler);
|
2014-10-09 18:28:09 +08:00
|
|
|
|
2014-11-27 16:49:19 +08:00
|
|
|
void registReaderObject(const std::string& className,
|
|
|
|
ObjectFactory::Instance ins);
|
2014-10-09 18:28:09 +08:00
|
|
|
|
2014-12-08 14:32:33 +08:00
|
|
|
cocos2d::Node* createNodeWithFlatBuffersForSimulator(const std::string& filename);
|
|
|
|
cocos2d::Node* nodeWithFlatBuffersForSimulator(const flatbuffers::NodeTree* nodetree);
|
2014-12-22 15:38:47 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
protected:
|
2015-03-12 17:36:39 +08:00
|
|
|
|
|
|
|
cocos2d::Node* createNodeWithFlatBuffersFile(const std::string& filename, const ccNodeLoadCallback& callback);
|
|
|
|
cocos2d::Node* nodeWithFlatBuffersFile(const std::string& fileName, const ccNodeLoadCallback& callback);
|
|
|
|
cocos2d::Node* nodeWithFlatBuffers(const flatbuffers::NodeTree* nodetree, const ccNodeLoadCallback& callback);
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
cocos2d::Node* loadNode(const rapidjson::Value& json);
|
|
|
|
|
|
|
|
void locateNodeWithMulresPosition(cocos2d::Node* node, const rapidjson::Value& json);
|
|
|
|
|
|
|
|
void initNode(cocos2d::Node* node, const rapidjson::Value& json);
|
|
|
|
|
|
|
|
// load nodes
|
|
|
|
cocos2d::Node* loadSimpleNode(const rapidjson::Value& json);
|
|
|
|
cocos2d::Node* loadSubGraph (const rapidjson::Value& json);
|
|
|
|
cocos2d::Node* loadSprite (const rapidjson::Value& json);
|
|
|
|
cocos2d::Node* loadParticle (const rapidjson::Value& json);
|
|
|
|
cocos2d::Node* loadTMXTiledMap(const rapidjson::Value& json);
|
|
|
|
|
|
|
|
// load gui
|
|
|
|
cocos2d::Node* loadWidget(const rapidjson::Value& json);
|
|
|
|
|
|
|
|
// load component
|
|
|
|
cocos2d::Component* loadComponent(const rapidjson::Value& json);
|
2015-03-12 17:36:39 +08:00
|
|
|
cocos2d::Component* loadComAudio(const rapidjson::Value& json);
|
2014-10-09 18:28:09 +08:00
|
|
|
|
|
|
|
bool isWidget(const std::string& type);
|
|
|
|
bool isCustomWidget(const std::string& type);
|
|
|
|
|
|
|
|
std::string getGUIClassName(const std::string &name);
|
|
|
|
std::string getWidgetReaderClassName(cocos2d::ui::Widget *widget);
|
|
|
|
|
|
|
|
typedef std::function<cocos2d::Node*(const rapidjson::Value& json)> NodeCreateFunc;
|
|
|
|
typedef std::pair<std::string, NodeCreateFunc> Pair;
|
|
|
|
|
|
|
|
std::unordered_map<std::string, NodeCreateFunc> _funcs;
|
|
|
|
|
|
|
|
typedef std::function<cocos2d::Component*(const rapidjson::Value& json)> ComponentCreateFunc;
|
|
|
|
typedef std::pair<std::string, ComponentCreateFunc> ComponentPair;
|
|
|
|
|
|
|
|
std::unordered_map<std::string, ComponentCreateFunc> _componentFuncs;
|
|
|
|
|
|
|
|
bool _recordJsonPath;
|
|
|
|
|
|
|
|
std::string _jsonPath;
|
|
|
|
|
|
|
|
std::string _monoCocos2dxVersion;
|
2014-11-27 16:49:19 +08:00
|
|
|
|
|
|
|
Node* _rootNode;
|
2015-03-04 17:29:40 +08:00
|
|
|
cocos2d::Vector<cocos2d::Node*> _callbackHandlers;
|
|
|
|
|
2014-12-31 16:01:11 +08:00
|
|
|
std::string _csBuildID;
|
2015-03-12 17:36:39 +08:00
|
|
|
|
2014-10-09 18:28:09 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
|
|
|
#endif /* defined(__cocos2d_libs__CSLoader__) */
|