scene_format_object.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*************************************************************************/
  2. /* scene_format_object.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #ifndef SCENE_FORMAT_OBJECT_H
  30. #define SCENE_FORMAT_OBJECT_H
  31. #include "scene/main/node.h"
  32. #include "scene/io/scene_saver.h"
  33. #include "scene/io/scene_loader.h"
  34. #include "io/object_saver.h"
  35. #include "io/object_loader.h"
  36. /**
  37. @author Juan Linietsky <[email protected]>
  38. */
  39. #ifdef OLD_SCENE_FORMAT_ENABLED
  40. class SceneFormatSaverObject : public SceneFormatSaver {
  41. void save_node(const Node* p_root,const Node* p_node,const Node* p_owner,ObjectFormatSaver *p_saver,String p_base_path,uint32_t p_flags,Map<const Node*,uint32_t>& owner_id) const;
  42. public:
  43. virtual Error save(const String &p_path,const Node* p_scenezz,uint32_t p_flags=0,const Ref<OptimizedSaver> &p_optimizer=Ref<OptimizedSaver>());
  44. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  45. virtual ~SceneFormatSaverObject() {}
  46. };
  47. class SceneFormatLoaderObject : public SceneFormatLoader {
  48. struct ConnectionItem {
  49. Node *node;
  50. NodePath target;
  51. StringName method;
  52. StringName signal;
  53. Vector<Variant> binds;
  54. bool realtime;
  55. };
  56. Node* load_node(Object *obj, const Variant& meta, Node *p_root, ObjectFormatLoader *p_loader,List<ConnectionItem>& connections,Error& r_err,bool p_root_scene_hint,Map<uint32_t,Node*>& owner_map);
  57. void _apply_connections(List<ConnectionItem>& connections);
  58. void _apply_meta(Node *node, const Variant& meta, ObjectFormatLoader *p_loader,List<ConnectionItem>& connections,Error& r_err,Map<uint32_t,Node*>& owner_map);
  59. public:
  60. virtual Ref<SceneInteractiveLoader> load_interactive(const String &p_path,bool p_root_scene_hint=false);
  61. virtual Node* load(const String &p_path,bool p_save_root_state=false);
  62. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  63. };
  64. class SceneInteractiveLoaderObject : public SceneInteractiveLoader {
  65. OBJ_TYPE(SceneInteractiveLoaderObject,SceneInteractiveLoader);
  66. struct ConnectionItem {
  67. Node *node;
  68. NodePath target;
  69. StringName method;
  70. StringName signal;
  71. Vector<Variant> binds;
  72. bool realtime;
  73. };
  74. ObjectFormatLoader *loader;
  75. String path;
  76. String node_path;
  77. String local_path;
  78. Error error;
  79. bool save_instance_state;
  80. List<ConnectionItem> connections;
  81. Map<uint32_t,Node*> owner_map;
  82. Node *root;
  83. int stage_max;
  84. int stage;
  85. Node* load_node(Object *obj, const Variant& meta, Node *p_root, ObjectFormatLoader *p_loader,List<ConnectionItem>& connections,Error& r_err,bool p_root_scene_hint,Map<uint32_t,Node*>& owner_map);
  86. void _apply_connections(List<ConnectionItem>& connections);
  87. void _apply_meta(Node *node, const Variant& meta, ObjectFormatLoader *p_loader,List<ConnectionItem>& connections,Error& r_err,Map<uint32_t,Node*>& owner_map);
  88. friend class SceneFormatLoaderObject;
  89. public:
  90. virtual void set_local_path(const String& p_local_path);
  91. virtual Node *get_scene();
  92. virtual Error poll();
  93. virtual int get_stage() const;
  94. virtual int get_stage_count() const;
  95. SceneInteractiveLoaderObject(const String &p_path,bool p_save_root_state=false);
  96. };
  97. #endif
  98. #endif