From 15cac5f9fcd8558c1e53139d461e3d31b2130ad2 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 26 Feb 2025 13:36:10 +0100 Subject: [PATCH] [godot] Closes #2747, rewrote the way we sync on-disk asset changes --- .../spine_godot/SpineAtlasResource.cpp | 2 - .../spine_godot/SpineSkeletonDataResource.cpp | 149 ++++++++++++++---- .../spine_godot/SpineSkeletonDataResource.h | 8 + .../spine_godot/SpineSkeletonFileResource.cpp | 1 - .../spine_godot_extension.dev.gdextension | 18 --- 5 files changed, 124 insertions(+), 54 deletions(-) delete mode 100644 spine-godot/spine_godot_extension.dev.gdextension diff --git a/spine-godot/spine_godot/SpineAtlasResource.cpp b/spine-godot/spine_godot/SpineAtlasResource.cpp index 0e59817ae..9ae73db0b 100644 --- a/spine-godot/spine_godot/SpineAtlasResource.cpp +++ b/spine-godot/spine_godot/SpineAtlasResource.cpp @@ -217,8 +217,6 @@ 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") { diff --git a/spine-godot/spine_godot/SpineSkeletonDataResource.cpp b/spine-godot/spine_godot/SpineSkeletonDataResource.cpp index 73e594db3..7637e41c0 100644 --- a/spine-godot/spine_godot/SpineSkeletonDataResource.cpp +++ b/spine-godot/spine_godot/SpineSkeletonDataResource.cpp @@ -32,10 +32,26 @@ #ifdef SPINE_GODOT_EXTENSION #include +#include +#include #else +#if VERSION_MAJOR > 3 +#include "core/config/engine.h" +#include "editor/editor_interface.h" +#else +#include "core/engine.h" +#endif #include #endif +#ifdef TOOLS_ENABLED +#ifdef SPINE_GODOT_EXTENSION +#include +#else +#include "editor/editor_file_system.h" +#endif +#endif + void SpineAnimationMix::_bind_methods() { ClassDB::bind_method(D_METHOD("set_from", "from"), &SpineAnimationMix::set_from); @@ -175,16 +191,115 @@ void SpineSkeletonDataResource::_bind_methods() { #endif ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animation_mixes"), "set_animation_mixes", "get_animation_mixes"); + +#ifdef TOOLS_ENABLED +#if VERSION_MAJOR > 3 + ClassDB::bind_method(D_METHOD("_on_resources_reimported", "resources"), + &SpineSkeletonDataResource::_on_resources_reimported); +#else + ClassDB::bind_method(D_METHOD("_on_resources_reimported", "resources"), + &SpineSkeletonDataResource::_on_resources_reimported); +#endif +#endif +} + +EditorFileSystem *get_editor_file_system() { +#ifdef SPINE_GODOT_EXTENSION + EditorInterface *editor_interface = EditorInterface::get_singleton(); + if (editor_interface) { + return editor_interface->get_resource_filesystem(); + } + return nullptr; +#else + return EditorFileSystem::get_singleton(); +#endif } SpineSkeletonDataResource::SpineSkeletonDataResource() - : default_mix(0), skeleton_data(nullptr), animation_state_data(nullptr) {} + : default_mix(0), skeleton_data(nullptr), animation_state_data(nullptr) { + +#ifdef TOOLS_ENABLED +#if VERSION_MAJOR > 3 + if (Engine::get_singleton()->is_editor_hint()) { + EditorFileSystem *efs = get_editor_file_system(); + if (efs) { + efs->connect("resources_reimported", callable_mp(this, &SpineSkeletonDataResource::_on_resources_reimported)); + } + } +#else + if (Engine::get_singleton()->is_editor_hint()) { + EditorFileSystem *efs = EditorFileSystem::get_singleton(); + if (efs) { + efs->connect("resources_reimported", this, "_on_resources_reimported"); + } + } +#endif +#endif +} SpineSkeletonDataResource::~SpineSkeletonDataResource() { +#ifdef TOOLS_ENABLED +#if VERSION_MAJOR > 3 + if (Engine::get_singleton()->is_editor_hint()) { + EditorFileSystem *efs = get_editor_file_system(); + if (efs && efs->is_connected("resources_reimported", callable_mp(this, &SpineSkeletonDataResource::_on_resources_reimported))) { + efs->disconnect("resources_reimported", callable_mp(this, &SpineSkeletonDataResource::_on_resources_reimported)); + } + } +#else + if (Engine::get_singleton()->is_editor_hint()) { + EditorFileSystem *efs = EditorFileSystem::get_singleton(); + if (efs && efs->is_connected("resources_reimported", this, "_on_resources_reimported")) { + efs->disconnect("resources_reimported", this, "_on_resources_reimported"); + } + } +#endif +#endif + delete skeleton_data; delete animation_state_data; } +#ifdef TOOLS_ENABLED +#if VERSION_MAJOR > 3 +void SpineSkeletonDataResource::_on_resources_reimported(const PackedStringArray &resources) { + for (int i = 0; i < resources.size(); i++) { + if (atlas_res.is_valid() && atlas_res->get_path() == resources[i]) { + print_line("Atlas resource was reimported: " + resources[i]); + #ifdef SPINE_GODOT_EXTENSION + atlas_res = ResourceLoader::get_singleton()->load(resources[i], "SpineAtlasResource", ResourceLoader::CACHE_MODE_IGNORE); + #else + atlas_res = ResourceLoader::load(resources[i], "SpineAtlasResource", ResourceFormatLoader::CACHE_MODE_IGNORE); + #endif + update_skeleton_data(); + } else if (skeleton_file_res.is_valid() && skeleton_file_res->get_path() == resources[i]) { + print_line("Skeleton file resource was reimported: " + resources[i]); + #ifdef SPINE_GODOT_EXTENSION + skeleton_file_res = ResourceLoader::get_singleton()->load(resources[i], "SpineSkeletonFileResource", ResourceLoader::CACHE_MODE_IGNORE); + #else + skeleton_file_res = ResourceLoader::load(resources[i], "SpineSkeletonFileResource", ResourceFormatLoader::CACHE_MODE_IGNORE); + #endif + update_skeleton_data(); + } + } +} +#else +void SpineSkeletonDataResource::_on_resources_reimported(const PoolStringArray &resources) { + for (int i = 0; i < resources.size(); i++) { + if (atlas_res.is_valid() && atlas_res->get_path() == resources[i]) { + print_line("Atlas resource was reimported: " + resources[i]); + atlas_res = ResourceLoader::load(resources[i]); + update_skeleton_data(); + } else if (skeleton_file_res.is_valid() && skeleton_file_res->get_path() == resources[i]) { + print_line("Skeleton file resource was reimported: " + resources[i]); + skeleton_file_res = ResourceLoader::load(resources[i]); + update_skeleton_data(); + } + } +} +#endif +#endif + void SpineSkeletonDataResource::update_skeleton_data() { if (skeleton_data) { delete skeleton_data; @@ -249,22 +364,6 @@ bool SpineSkeletonDataResource::is_skeleton_data_loaded() const { void SpineSkeletonDataResource::set_atlas_res( const Ref &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(); } @@ -275,22 +374,6 @@ Ref SpineSkeletonDataResource::get_atlas_res() { void SpineSkeletonDataResource::set_skeleton_file_res( const Ref &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(); } diff --git a/spine-godot/spine_godot/SpineSkeletonDataResource.h b/spine-godot/spine_godot/SpineSkeletonDataResource.h index 28f542fd0..77838d9ca 100644 --- a/spine-godot/spine_godot/SpineSkeletonDataResource.h +++ b/spine-godot/spine_godot/SpineSkeletonDataResource.h @@ -209,4 +209,12 @@ public: float get_reference_scale() const; void set_reference_scale(float reference_scale); + +#ifdef TOOLS_ENABLED +#if VERSION_MAJOR > 3 +void _on_resources_reimported(const PackedStringArray &resources); +#else +void _on_resources_reimported(const PoolStringArray &resources); +#endif +#endif }; diff --git a/spine-godot/spine_godot/SpineSkeletonFileResource.cpp b/spine-godot/spine_godot/SpineSkeletonFileResource.cpp index 93d13fba2..b5404fc59 100644 --- a/spine-godot/spine_godot/SpineSkeletonFileResource.cpp +++ b/spine-godot/spine_godot/SpineSkeletonFileResource.cpp @@ -95,7 +95,6 @@ static char *readString(BinaryInput *input) { void SpineSkeletonFileResource::_bind_methods() { ClassDB::bind_method(D_METHOD("load_from_file", "path"), &SpineSkeletonFileResource::load_from_file); - ADD_SIGNAL(MethodInfo("skeleton_file_changed")); } static bool checkVersion(const char *version) { diff --git a/spine-godot/spine_godot_extension.dev.gdextension b/spine-godot/spine_godot_extension.dev.gdextension deleted file mode 100644 index d4d2d8495..000000000 --- a/spine-godot/spine_godot_extension.dev.gdextension +++ /dev/null @@ -1,18 +0,0 @@ -[configuration] - -entry_symbol = "spine_godot_library_init" -compatibility_minimum = "4.1" - -[libraries] - -macos.editor = "res://bin/macos/macos.framework/libspine_godot.macos.dev.editor" -macos.debug = "res://bin/macos/macos.framework/libspine_godot.macos.dev.template_debug" -macos.release = "res://bin/macos/macos.framework/libspine_godot.macos.template_release" - -windows.editor.x86_64 = "res://bin/windows/libspine_godot.windows.editor.dev.x86_64.dll" -windows.debug.x86_64 = "res://bin/windows/libspine_godot.windows.template_debug.dev.x86_64.dll" -windows.release.x86_64 = "res://bin/windows/libspine_godot.windows.template_release.dev.x86_64.dll" - -linux.editor.x86_64 = "res://bin/linux/libspine_godot.linux.editor.dev.x86_64.so" -linux.debug.x86_64 = "res://bin/linux/libspine_godot.linux.template_debug.dev.x86_64.so" -linux.release.x86_64 = "res://bin/linux/libspine_godot.linux.template_release.dev.x86_64.so" \ No newline at end of file