FlatBuffersSerialize.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /****************************************************************************
  2. Copyright (c) 2013 cocos2d-x.org
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __cocos2d_libs__FlatBuffersSerialize__
  21. #define __cocos2d_libs__FlatBuffersSerialize__
  22. #include <string>
  23. #include <vector>
  24. #include "ExtensionMacros.h"
  25. #include "editor-support/cocostudio/CocosStudioExport.h"
  26. #include "platform/CCPlatformMacros.h"
  27. #include "ui/UIWidget.h"
  28. namespace flatbuffers
  29. {
  30. class FlatBufferBuilder;
  31. template<typename T> struct Offset;
  32. struct String;
  33. struct CSParseBinary;
  34. struct NodeTree;
  35. struct WidgetOptions;
  36. struct SingleNodeOptions;
  37. struct SpriteOptions;
  38. struct ParticleSystemOptions;
  39. struct TMXTiledMapOptions;
  40. struct ButtonOptions;
  41. struct CheckBoxOptions;
  42. struct ImageViewOptions;
  43. struct TextBMFontOptions;
  44. struct TextOptions;
  45. struct TextFieldOptions;
  46. struct LoadingBarOptions;
  47. struct SliderOptions;
  48. struct PanelOptions;
  49. struct ScrollViewOptions;
  50. struct PageViewOptions;
  51. struct ListViewOptions;
  52. struct ProjectNodeOptions;
  53. struct ComponentOptions;
  54. struct ComAudioOptions;
  55. struct TextAtlasOptions;
  56. struct NodeAction;
  57. struct AnimationInfo;
  58. struct TimeLine;
  59. struct Frame;
  60. struct PointFrame;
  61. struct ScaleFrame;
  62. struct ColorFrame;
  63. struct TextureFrame;
  64. struct EventFrame;
  65. struct IntFrame;
  66. struct BoolFrame;
  67. struct InnerActionFrame;
  68. struct EasingData;
  69. struct BlendFrame;
  70. }
  71. namespace tinyxml2
  72. {
  73. class XMLElement;
  74. }
  75. namespace cocostudio {
  76. class CC_STUDIO_DLL FlatBuffersSerialize
  77. {
  78. public:
  79. static FlatBuffersSerialize* getInstance();
  80. /** @deprecated Use method destroyInstance() instead */
  81. CC_DEPRECATED_ATTRIBUTE static void purge();
  82. static void destroyInstance();
  83. FlatBuffersSerialize();
  84. ~FlatBuffersSerialize();
  85. void deleteFlatBufferBuilder();
  86. std::string test(const std::string& xmlFileName,
  87. const std::string& flatbuffersFileName);
  88. /* serialize flat buffers with XML */
  89. std::string serializeFlatBuffersWithXMLFile(const std::string& xmlFileName,
  90. const std::string& flatbuffersFileName);
  91. // NodeTree
  92. flatbuffers::Offset<flatbuffers::NodeTree> createNodeTree(const tinyxml2::XMLElement* objectData,
  93. std::string classType);
  94. // NodeAction
  95. flatbuffers::Offset<flatbuffers::NodeAction> createNodeAction(const tinyxml2::XMLElement* objectData);
  96. flatbuffers::Offset<flatbuffers::TimeLine> createTimeLine(const tinyxml2::XMLElement* objectData);
  97. flatbuffers::Offset<flatbuffers::PointFrame> createPointFrame(const tinyxml2::XMLElement* objectData);
  98. flatbuffers::Offset<flatbuffers::ScaleFrame> createScaleFrame(const tinyxml2::XMLElement* objectData);
  99. flatbuffers::Offset<flatbuffers::ColorFrame> createColorFrame(const tinyxml2::XMLElement* objectData);
  100. flatbuffers::Offset<flatbuffers::TextureFrame> createTextureFrame(const tinyxml2::XMLElement* objectData);
  101. flatbuffers::Offset<flatbuffers::EventFrame> createEventFrame(const tinyxml2::XMLElement* objectData);
  102. flatbuffers::Offset<flatbuffers::IntFrame> createIntFrame(const tinyxml2::XMLElement* objectData);
  103. flatbuffers::Offset<flatbuffers::BoolFrame> createBoolFrame(const tinyxml2::XMLElement* objectData);
  104. flatbuffers::Offset<flatbuffers::InnerActionFrame> createInnerActionFrame(const tinyxml2::XMLElement* objectData);
  105. flatbuffers::Offset<flatbuffers::BlendFrame> createBlendFrame(const tinyxml2::XMLElement* objectData);
  106. flatbuffers::Offset<flatbuffers::EasingData> createEasingData(const tinyxml2::XMLElement* objectData);
  107. //Animation Info
  108. flatbuffers::Offset<flatbuffers::AnimationInfo> createAnimationInfo(const tinyxml2::XMLElement* objectData);
  109. /**/
  110. int getResourceType(std::string key);
  111. std::string getGUIClassName(const std::string &name);
  112. std::string getWidgetReaderClassName(cocos2d::ui::Widget *widget);
  113. /* create flat buffers with XML */
  114. flatbuffers::FlatBufferBuilder* createFlatBuffersWithXMLFileForSimulator(const std::string& xmlFileName);
  115. flatbuffers::Offset<flatbuffers::NodeTree> createNodeTreeForSimulator(const tinyxml2::XMLElement* objectData,
  116. std::string classType);
  117. flatbuffers::Offset<flatbuffers::ProjectNodeOptions> createProjectNodeOptionsForSimulator(const tinyxml2::XMLElement* objectData);
  118. /**/
  119. std::string getCsdVersion() { return _csdVersion; }
  120. /* Serialize language XML file to Flat Buffers file. */
  121. std::string serializeFlatBuffersWithXMLFileForLanguageData(const std::string& xmlFilePath,
  122. const std::string& flatBuffersFilePath,
  123. const std::string& languageName);
  124. public:
  125. std::vector<flatbuffers::Offset<flatbuffers::String>> _textures;
  126. std::vector<flatbuffers::Offset<flatbuffers::String>> _texturePngs;
  127. bool _isSimulator;
  128. private:
  129. flatbuffers::FlatBufferBuilder* _builder;
  130. flatbuffers::Offset<flatbuffers::CSParseBinary>* _csparsebinary;
  131. std::string _csdVersion;
  132. };
  133. }
  134. #endif /* defined(__cocos2d_libs__FlatBuffersSerialize__) */