Skip to content

Commit

Permalink
Merge branch '4.1' into 4.2-beta
Browse files Browse the repository at this point in the history
  • Loading branch information
badlogic committed Oct 5, 2023
2 parents 5c0bb6e + b70aa0c commit e8e0c29
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
23 changes: 23 additions & 0 deletions spine-godot/spine_godot/SpineAtlasResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ void SpineAtlasResource::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "source_path"), "", "get_source_path");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "textures"), "", "get_textures");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "normal_maps"), "", "get_normal_maps");

ADD_SIGNAL(MethodInfo("skeleton_atlas_changed"));
}

SpineAtlasResource::SpineAtlasResource() : atlas(nullptr), texture_loader(nullptr), normal_map_prefix("n") {
Expand Down Expand Up @@ -230,6 +232,27 @@ Error SpineAtlasResource::save_to_file(const String &path) {
return OK;
}

Error SpineAtlasResource::copy_from(const Ref<Resource> &p_resource) {
auto error = Resource::copy_from(p_resource);
if (error != OK) return error;

const Ref<SpineAtlasResource> &spineAtlas = static_cast<const Ref<SpineAtlasResource> &>(p_resource);
this->clear();
this->atlas = spineAtlas->atlas;
spineAtlas->atlas = nullptr;
this->texture_loader = spineAtlas->texture_loader;
spineAtlas->texture_loader = nullptr;

this->source_path = spineAtlas->source_path;
this->atlas_data = spineAtlas->atlas_data;
this->normal_map_prefix = spineAtlas->normal_map_prefix;
this->textures = spineAtlas->textures;
this->normal_maps = spineAtlas->normal_maps;
emit_signal(SNAME("skeleton_file_changed"));

return OK;
}

#if VERSION_MAJOR > 3
RES SpineAtlasResourceFormatLoader::load(const String &path, const String &original_path, Error *error, bool use_sub_threads, float *progress, CacheMode cache_mode) {
#else
Expand Down
2 changes: 2 additions & 0 deletions spine-godot/spine_godot/SpineAtlasResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ class SpineAtlasResource : public Resource {

Error save_to_file(const String &path);// .spatlas

virtual Error copy_from(const Ref<Resource> &p_resource);

String get_source_path();

Array get_textures();
Expand Down
19 changes: 19 additions & 0 deletions spine-godot/spine_godot/SpineSkeletonDataResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void SpineSkeletonDataResource::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_images_path"), &SpineSkeletonDataResource::get_images_path);
ClassDB::bind_method(D_METHOD("get_audio_path"), &SpineSkeletonDataResource::get_audio_path);
ClassDB::bind_method(D_METHOD("get_fps"), &SpineSkeletonDataResource::get_fps);
ClassDB::bind_method(D_METHOD("update_skeleton_data"), &SpineSkeletonDataResource::update_skeleton_data);

ADD_SIGNAL(MethodInfo("skeleton_data_changed"));
ADD_SIGNAL(MethodInfo("_internal_spine_objects_invalidated"));
Expand Down Expand Up @@ -190,6 +191,15 @@ bool SpineSkeletonDataResource::is_skeleton_data_loaded() const {

void SpineSkeletonDataResource::set_atlas_res(const Ref<SpineAtlasResource> &atlas) {
atlas_res = atlas;
if (atlas_res.is_valid()) {
#if VERSION_MAJOR > 3
if (!atlas_res->is_connected(SNAME("skeleton_atlas_changed"), callable_mp(this, &SpineSkeletonDataResource::update_skeleton_data)))
atlas_res->connect(SNAME("skeleton_atlas_changed"), callable_mp(this, &SpineSkeletonDataResource::update_skeleton_data));
#else
if (!atlas_res->is_connected(SNAME("skeleton_atlas_changed"), this, SNAME("update_skeleton_data")))
atlas_res->connect(SNAME("skeleton_atlas_changed"), this, SNAME("update_skeleton_data"));
#endif
}
update_skeleton_data();
}

Expand All @@ -199,6 +209,15 @@ Ref<SpineAtlasResource> SpineSkeletonDataResource::get_atlas_res() {

void SpineSkeletonDataResource::set_skeleton_file_res(const Ref<SpineSkeletonFileResource> &skeleton_file) {
skeleton_file_res = skeleton_file;
if (skeleton_file_res.is_valid()) {
#if VERSION_MAJOR > 3
if (!skeleton_file_res->is_connected(SNAME("skeleton_file_changed"), callable_mp(this, &SpineSkeletonDataResource::update_skeleton_data)))
skeleton_file_res->connect(SNAME("skeleton_file_changed"), callable_mp(this, &SpineSkeletonDataResource::update_skeleton_data));
#else
if (!skeleton_file_res->is_connected(SNAME("skeleton_file_changed"), this, SNAME("update_skeleton_data")))
skeleton_file_res->connect(SNAME("skeleton_file_changed"), this, SNAME("update_skeleton_data"));
#endif
}
update_skeleton_data();
}

Expand Down
13 changes: 13 additions & 0 deletions spine-godot/spine_godot/SpineSkeletonFileResource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
*****************************************************************************/

#include "SpineSkeletonFileResource.h"
#include "core/error/error_list.h"
#include "core/error/error_macros.h"
#if VERSION_MAJOR > 3
#include "core/io/file_access.h"
#else
Expand Down Expand Up @@ -85,6 +87,7 @@ static char *readString(BinaryInput *input) {
}

void SpineSkeletonFileResource::_bind_methods() {
ADD_SIGNAL(MethodInfo("skeleton_file_changed"));
}

static bool checkVersion(const char *version) {
Expand Down Expand Up @@ -157,6 +160,16 @@ Error SpineSkeletonFileResource::save_to_file(const String &path) {
return OK;
}

Error SpineSkeletonFileResource::copy_from(const Ref<Resource> &p_resource) {
auto error = Resource::copy_from(p_resource);
if (error != OK) return error;
const Ref<SpineSkeletonFileResource> &spineFile = static_cast<const Ref<SpineSkeletonFileResource> &>(p_resource);
this->json = spineFile->json;
this->binary = spineFile->binary;
emit_signal(SNAME("skeleton_file_changed"));
return OK;
}

#if VERSION_MAJOR > 3
RES SpineSkeletonFileResourceFormatLoader::load(const String &path, const String &original_path, Error *error, bool use_sub_threads, float *progress, CacheMode cache_mode) {
#else
Expand Down
2 changes: 2 additions & 0 deletions spine-godot/spine_godot/SpineSkeletonFileResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class SpineSkeletonFileResource : public Resource {
Error load_from_file(const String &path);

Error save_to_file(const String &path);

virtual Error copy_from(const Ref<Resource> &p_resource);
};

class SpineSkeletonFileResourceFormatLoader : public ResourceFormatLoader {
Expand Down

0 comments on commit e8e0c29

Please sign in to comment.