scene_saver.cpp 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*************************************************************************/
  2. /* scene_saver.cpp */
  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. #include "scene_saver.h"
  30. #include "print_string.h"
  31. #ifdef OLD_SCENE_FORMAT_ENABLED
  32. SceneFormatSaver *SceneSaver::saver[MAX_SAVERS];
  33. int SceneSaver::saver_count=0;
  34. bool SceneFormatSaver::recognize(const String& p_extension) const {
  35. List<String> extensions;
  36. get_recognized_extensions(&extensions);
  37. for (List<String>::Element *E=extensions.front();E;E=E->next()) {
  38. if (E->get().nocasecmp_to(p_extension.extension())==0)
  39. return true;
  40. }
  41. return false;
  42. }
  43. Error SceneSaver::save(const String &p_path,const Node* p_scene,uint32_t p_flags,const Ref<OptimizedSaver> &p_optimizer) {
  44. String extension=p_path.extension();
  45. Error err=ERR_FILE_UNRECOGNIZED;
  46. bool recognized=false;
  47. for (int i=0;i<saver_count;i++) {
  48. if (!saver[i]->recognize(extension))
  49. continue;
  50. recognized=true;
  51. err = saver[i]->save(p_path,p_scene,p_flags,p_optimizer);
  52. if (err == OK )
  53. return OK;
  54. }
  55. if (err) {
  56. if (!recognized) {
  57. ERR_EXPLAIN("No saver format found for scene: "+p_path);
  58. } else {
  59. ERR_EXPLAIN("Couldn't save scene: "+p_path);
  60. }
  61. ERR_FAIL_V(err);
  62. }
  63. return err;
  64. }
  65. void SceneSaver::get_recognized_extensions(List<String> *p_extensions) {
  66. for (int i=0;i<saver_count;i++) {
  67. saver[i]->get_recognized_extensions(p_extensions);
  68. }
  69. }
  70. void SceneSaver::add_scene_format_saver(SceneFormatSaver *p_format_saver) {
  71. ERR_FAIL_COND( saver_count >= MAX_SAVERS );
  72. saver[saver_count++]=p_format_saver;
  73. }
  74. #endif