mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-16 20:11:47 +08:00
[godot] Closes #2747, rewrote the way we sync on-disk asset changes
This commit is contained in:
parent
c879d7a01c
commit
15cac5f9fc
@ -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") {
|
||||
|
||||
@ -32,10 +32,26 @@
|
||||
|
||||
#ifdef SPINE_GODOT_EXTENSION
|
||||
#include <godot_cpp/classes/encoded_object_as_id.hpp>
|
||||
#include <godot_cpp/classes/engine.hpp>
|
||||
#include <godot_cpp/classes/editor_interface.hpp>
|
||||
#else
|
||||
#if VERSION_MAJOR > 3
|
||||
#include "core/config/engine.h"
|
||||
#include "editor/editor_interface.h"
|
||||
#else
|
||||
#include "core/engine.h"
|
||||
#endif
|
||||
#include <core/io/marshalls.h>
|
||||
#endif
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
#ifdef SPINE_GODOT_EXTENSION
|
||||
#include <godot_cpp/classes/editor_file_system.hpp>
|
||||
#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<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();
|
||||
}
|
||||
|
||||
@ -275,22 +374,6 @@ 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();
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
};
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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"
|
||||
Loading…
x
Reference in New Issue
Block a user