SpineAtlasResource.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /******************************************************************************
  2. * Spine Runtimes License Agreement
  3. * Last updated April 5, 2025. Replaces all prior versions.
  4. *
  5. * Copyright (c) 2013-2025, Esoteric Software LLC
  6. *
  7. * Integration of the Spine Runtimes into software or otherwise creating
  8. * derivative works of the Spine Runtimes is permitted under the terms and
  9. * conditions of Section 2 of the Spine Editor License Agreement:
  10. * http://esotericsoftware.com/spine-editor-license
  11. *
  12. * Otherwise, it is permitted to integrate the Spine Runtimes into software
  13. * or otherwise create derivative works of the Spine Runtimes (collectively,
  14. * "Products"), provided that each user of the Products must obtain their own
  15. * Spine Editor license and redistribution of the Products in any form must
  16. * include this license and copyright notice.
  17. *
  18. * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
  19. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
  24. * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  27. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *****************************************************************************/
  29. #pragma once
  30. #include "SpineCommon.h"
  31. #ifdef SPINE_GODOT_EXTENSION
  32. #include <godot_cpp/classes/resource.hpp>
  33. #include <godot_cpp/classes/resource_loader.hpp>
  34. #include <godot_cpp/classes/resource_format_loader.hpp>
  35. #include <godot_cpp/classes/resource_saver.hpp>
  36. #include <godot_cpp/classes/resource_format_saver.hpp>
  37. #include <spine/Atlas.h>
  38. #else
  39. #include "core/io/resource_loader.h"
  40. #include "core/io/resource_saver.h"
  41. #include "core/io/image_loader.h"
  42. #include <spine/Atlas.h>
  43. #endif
  44. class GodotSpineTextureLoader;
  45. class SpineAtlasResource : public Resource {
  46. GDCLASS(SpineAtlasResource, Resource)
  47. void clear();
  48. protected:
  49. static void _bind_methods();
  50. mutable spine::Atlas *atlas;
  51. mutable GodotSpineTextureLoader *texture_loader;
  52. String source_path;
  53. String atlas_data;
  54. String normal_map_prefix;
  55. String specular_map_prefix;
  56. Array textures;
  57. Array normal_maps;
  58. Array specular_maps;
  59. public:
  60. SpineAtlasResource();
  61. ~SpineAtlasResource() override;
  62. spine::Atlas *get_spine_atlas() { return atlas; }
  63. void set_normal_texture_prefix(const String &prefix) { normal_map_prefix = prefix; }
  64. void set_specular_texture_prefix(const String &prefix) { specular_map_prefix = prefix; }
  65. Error load_from_atlas_file(const String &path);// .atlas
  66. Error load_from_atlas_file_internal(const String &path, bool is_importing);// .atlas
  67. Error load_from_file(const String &path);// .spatlas
  68. Error save_to_file(const String &path);// .spatlas
  69. #ifndef SPINE_GODOT_EXTENSION
  70. #if VERSION_MAJOR > 3
  71. virtual Error copy_from(const Ref<Resource> &p_resource);
  72. #endif
  73. #endif
  74. String get_source_path();
  75. Array get_textures();
  76. Array get_normal_maps();
  77. Array get_specular_maps();
  78. void clear_native_data() const {
  79. this->atlas = nullptr;
  80. this->texture_loader = nullptr;
  81. }
  82. };
  83. class SpineAtlasResourceFormatLoader : public ResourceFormatLoader {
  84. GDCLASS(SpineAtlasResourceFormatLoader, ResourceFormatLoader)
  85. public:
  86. #ifdef SPINE_GODOT_EXTENSION
  87. static void _bind_methods(){};
  88. PackedStringArray _get_recognized_extensions();
  89. bool _handles_type(const StringName &type);
  90. String _get_resource_type(const String &path);
  91. Variant _load(const String &path, const String &original_path, bool use_sub_threads, int32_t cache_mode);
  92. #else
  93. #if VERSION_MAJOR > 3
  94. RES load(const String &path, const String &original_path, Error *error, bool use_sub_threads, float *progress, CacheMode cache_mode) override;
  95. #else
  96. #if VERSION_MINOR > 5
  97. RES load(const String &path, const String &original_path, Error *error, bool no_subresource_cache = false) override;
  98. #else
  99. RES load(const String &path, const String &original_path, Error *error) override;
  100. #endif
  101. #endif
  102. void get_recognized_extensions(List<String> *extensions) const override;
  103. bool handles_type(const String &type) const override;
  104. String get_resource_type(const String &path) const override;
  105. #endif
  106. };
  107. class SpineAtlasResourceFormatSaver : public ResourceFormatSaver {
  108. GDCLASS(SpineAtlasResourceFormatSaver, ResourceFormatSaver)
  109. public:
  110. #ifdef SPINE_GODOT_EXTENSION
  111. static void _bind_methods(){};
  112. Error _save(const Ref<Resource> &resource, const String &path, uint32_t flags) override;
  113. bool _recognize(const Ref<Resource> &resource);
  114. PackedStringArray _get_recognized_extensions(const Ref<Resource> &resource);
  115. #else
  116. #if VERSION_MAJOR > 3
  117. Error save(const RES &resource, const String &path, uint32_t flags) override;
  118. #else
  119. Error save(const String &path, const RES &resource, uint32_t flags) override;
  120. #endif
  121. void get_recognized_extensions(const RES &resource, List<String> *extensions) const override;
  122. bool recognize(const RES &resource) const override;
  123. #endif
  124. };