[godot] Additional Godot 4.5 compatibility fixes

Fixes additional compatibility issues found when building against Godot 4.5:

1. String::parse_utf8() deprecated and removed in Godot 4.5
   - Replaced with String::utf8() for Godot 4.5+
   - Added version guards to maintain compatibility with older versions
   - Affected files: SpineAnimation, SpineAnimationTrack, SpineAtlasResource,
     SpineAttachment, SpineBoneData, SpineConstraintData, SpineEventData,
     SpineSkeletonDataResource, SpineSkin, SpineSlotData, SpineSprite

2. Editor header file locations changed in Godot 4.5
   - editor/editor_file_system.h -> editor/file_system/editor_file_system.h
   - editor/plugins/animation_*_editor_plugin.h -> editor/animation/animation_*_editor_plugin.h
   - Added version guards for correct include paths
   - Affected files: SpineAtlasResource, SpineAnimationTrack

These changes ensure spine-godot builds successfully with both Godot 4.5 and earlier versions.
This commit is contained in:
Mario Zechner 2025-11-17 14:49:40 +01:00
parent 938c72fa8f
commit 02dec24ab7
11 changed files with 81 additions and 0 deletions

View File

@ -48,7 +48,11 @@ void SpineAnimation::_bind_methods() {
String SpineAnimation::get_name() { String SpineAnimation::get_name() {
SPINE_CHECK(get_spine_object(), "") SPINE_CHECK(get_spine_object(), "")
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(get_spine_object()->getName().buffer());
#else
name.parse_utf8(get_spine_object()->getName().buffer()); name.parse_utf8(get_spine_object()->getName().buffer());
#endif
return name; return name;
} }

View File

@ -40,9 +40,14 @@
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
#include "editor/editor_node.h" #include "editor/editor_node.h"
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
#include "editor/animation/animation_player_editor_plugin.h"
#include "editor/animation/animation_tree_editor_plugin.h"
#else
#include "editor/plugins/animation_player_editor_plugin.h" #include "editor/plugins/animation_player_editor_plugin.h"
#include "editor/plugins/animation_tree_editor_plugin.h" #include "editor/plugins/animation_tree_editor_plugin.h"
#endif #endif
#endif
void SpineAnimationTrack::_bind_methods() { void SpineAnimationTrack::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_animation_name", "animation_name"), &SpineAnimationTrack::set_animation_name); ClassDB::bind_method(D_METHOD("set_animation_name", "animation_name"), &SpineAnimationTrack::set_animation_name);
@ -251,7 +256,11 @@ Ref<Animation> SpineAnimationTrack::create_animation(spine::Animation *animation
Ref<Animation> animation_ref; Ref<Animation> animation_ref;
INSTANTIATE(animation_ref); INSTANTIATE(animation_ref);
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(animation->getName().buffer());
#else
name.parse_utf8(animation->getName().buffer()); name.parse_utf8(animation->getName().buffer());
#endif
animation_ref->set_name(name + (loop ? "" : "_looped")); animation_ref->set_name(name + (loop ? "" : "_looped"));
#if VERSION_MAJOR > 3 #if VERSION_MAJOR > 3
// animation_ref->set_loop(!loop); // animation_ref->set_loop(!loop);
@ -301,7 +310,11 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite)
auto current_entry = animation_state->getCurrent(track_index); auto current_entry = animation_state->getCurrent(track_index);
bool should_set_mix = mix_duration >= 0; bool should_set_mix = mix_duration >= 0;
String other_name; String other_name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
if (current_entry) other_name = String::utf8(current_entry->getAnimation()->getName().buffer());
#else
if (current_entry) other_name.parse_utf8(current_entry->getAnimation()->getName().buffer()); if (current_entry) other_name.parse_utf8(current_entry->getAnimation()->getName().buffer());
#endif
bool should_set_animation = !current_entry || (animation_name != other_name || current_entry->getLoop() != loop); bool should_set_animation = !current_entry || (animation_name != other_name || current_entry->getLoop() != loop);
if (should_set_animation) { if (should_set_animation) {
@ -428,7 +441,11 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite)
auto current_entry = animation_state->getCurrent(track_index); auto current_entry = animation_state->getCurrent(track_index);
bool should_set_mix = mix_duration >= 0; bool should_set_mix = mix_duration >= 0;
String other_name; String other_name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
if (current_entry) other_name = String::utf8(current_entry->getAnimation()->getName().buffer());
#else
if (current_entry) other_name.parse_utf8(current_entry->getAnimation()->getName().buffer()); if (current_entry) other_name.parse_utf8(current_entry->getAnimation()->getName().buffer());
#endif
bool should_set_animation = !current_entry || (animation_name != other_name || current_entry->getLoop() != loop) || animation_changed; bool should_set_animation = !current_entry || (animation_name != other_name || current_entry->getLoop() != loop) || animation_changed;
animation_changed = false; animation_changed = false;

View File

@ -51,9 +51,13 @@
#ifdef SPINE_GODOT_EXTENSION #ifdef SPINE_GODOT_EXTENSION
#include <godot_cpp/classes/editor_file_system.hpp> #include <godot_cpp/classes/editor_file_system.hpp>
#else #else
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
#include "editor/file_system/editor_file_system.h"
#else
#include "editor/editor_file_system.h" #include "editor/editor_file_system.h"
#endif #endif
#endif #endif
#endif
#include <spine/TextureLoader.h> #include <spine/TextureLoader.h>
@ -143,7 +147,11 @@ public:
void load(spine::AtlasPage &page, const spine::String &path) override { void load(spine::AtlasPage &page, const spine::String &path) override {
String fixed_path; String fixed_path;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
fixed_path = String::utf8(path.buffer());
#else
fixed_path.parse_utf8(path.buffer()); fixed_path.parse_utf8(path.buffer());
#endif
bool is_resource = fix_path(fixed_path); bool is_resource = fix_path(fixed_path);
import_image_resource(fixed_path); import_image_resource(fixed_path);

View File

@ -42,7 +42,11 @@ SpineAttachment::~SpineAttachment() {
String SpineAttachment::get_attachment_name() { String SpineAttachment::get_attachment_name() {
SPINE_CHECK(get_spine_object(), "") SPINE_CHECK(get_spine_object(), "")
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(get_spine_object()->getName().buffer());
#else
name.parse_utf8(get_spine_object()->getName().buffer()); name.parse_utf8(get_spine_object()->getName().buffer());
#endif
return name; return name;
} }

View File

@ -69,7 +69,11 @@ int SpineBoneData::get_index() {
String SpineBoneData::get_bone_name() { String SpineBoneData::get_bone_name() {
SPINE_CHECK(get_spine_object(), "") SPINE_CHECK(get_spine_object(), "")
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(get_spine_object()->getName().buffer());
#else
name.parse_utf8(get_spine_object()->getName().buffer()); name.parse_utf8(get_spine_object()->getName().buffer());
#endif
return name; return name;
} }

View File

@ -42,7 +42,11 @@ void SpineConstraintData::_bind_methods() {
String SpineConstraintData::get_constraint_name() { String SpineConstraintData::get_constraint_name() {
SPINE_CHECK(get_spine_object(), "") SPINE_CHECK(get_spine_object(), "")
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(get_spine_object()->getName().buffer());
#else
name.parse_utf8(get_spine_object()->getName().buffer()); name.parse_utf8(get_spine_object()->getName().buffer());
#endif
return name; return name;
} }

View File

@ -49,7 +49,11 @@ void SpineEventData::_bind_methods() {
String SpineEventData::get_event_name() { String SpineEventData::get_event_name() {
SPINE_CHECK(get_spine_object(), "") SPINE_CHECK(get_spine_object(), "")
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(get_spine_object()->getName().buffer());
#else
name.parse_utf8(get_spine_object()->getName().buffer()); name.parse_utf8(get_spine_object()->getName().buffer());
#endif
return name; return name;
} }

View File

@ -396,7 +396,11 @@ void SpineSkeletonDataResource::get_animation_names(Vector<String> &animation_na
for (size_t i = 0; i < animations.size(); ++i) { for (size_t i = 0; i < animations.size(); ++i) {
auto animation = animations[i]; auto animation = animations[i];
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(animation->getName().buffer());
#else
name.parse_utf8(animation->getName().buffer()); name.parse_utf8(animation->getName().buffer());
#endif
animation_names.push_back(name); animation_names.push_back(name);
} }
} }
@ -413,7 +417,11 @@ void SpineSkeletonDataResource::get_skin_names(Vector<String> &skin_names) const
for (size_t i = 0; i < skins.size(); ++i) { for (size_t i = 0; i < skins.size(); ++i) {
auto skin = skins[i]; auto skin = skins[i];
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(skin->getName().buffer());
#else
name.parse_utf8(skin->getName().buffer()); name.parse_utf8(skin->getName().buffer());
#endif
skin_names.push_back(name); skin_names.push_back(name);
} }
} }
@ -430,7 +438,11 @@ void SpineSkeletonDataResource::get_slot_names(Vector<String> &slot_names) {
for (size_t i = 0; i < slots.size(); ++i) { for (size_t i = 0; i < slots.size(); ++i) {
auto slot = slots[i]; auto slot = slots[i];
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(slot->getName().buffer());
#else
name.parse_utf8(slot->getName().buffer()); name.parse_utf8(slot->getName().buffer());
#endif
slot_names.push_back(name); slot_names.push_back(name);
} }
} }
@ -447,7 +459,11 @@ void SpineSkeletonDataResource::get_bone_names(Vector<String> &bone_names) {
for (size_t i = 0; i < bones.size(); ++i) { for (size_t i = 0; i < bones.size(); ++i) {
auto bone = bones[i]; auto bone = bones[i];
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(bone->getName().buffer());
#else
name.parse_utf8(bone->getName().buffer()); name.parse_utf8(bone->getName().buffer());
#endif
bone_names.push_back(name); bone_names.push_back(name);
} }
} }
@ -632,7 +648,11 @@ SpineSkeletonDataResource::find_physics_constraint(
String SpineSkeletonDataResource::get_skeleton_name() const { String SpineSkeletonDataResource::get_skeleton_name() const {
SPINE_CHECK(skeleton_data, "") SPINE_CHECK(skeleton_data, "")
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(skeleton_data->getName().buffer());
#else
name.parse_utf8(skeleton_data->getName().buffer()); name.parse_utf8(skeleton_data->getName().buffer());
#endif
return name; return name;
} }

View File

@ -125,7 +125,11 @@ Array SpineSkin::find_attachments_for_slot(int slot_index) {
String SpineSkin::get_name() { String SpineSkin::get_name() {
SPINE_CHECK(get_spine_object(), "") SPINE_CHECK(get_spine_object(), "")
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(get_spine_object()->getName().buffer());
#else
name.parse_utf8(get_spine_object()->getName().buffer()); name.parse_utf8(get_spine_object()->getName().buffer());
#endif
return name; return name;
} }

View File

@ -54,7 +54,11 @@ int SpineSlotData::get_index() {
String SpineSlotData::get_name() { String SpineSlotData::get_name() {
SPINE_CHECK(get_spine_object(), String("")) SPINE_CHECK(get_spine_object(), String(""))
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(get_spine_object()->getName().buffer());
#else
name.parse_utf8(get_spine_object()->getName().buffer()); name.parse_utf8(get_spine_object()->getName().buffer());
#endif
return name; return name;
} }

View File

@ -1229,7 +1229,11 @@ void SpineSprite::draw() {
Vector<String> hover_text_lines; Vector<String> hover_text_lines;
if (hovered_slot) { if (hovered_slot) {
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(hovered_slot->getData().getName().buffer());
#else
name.parse_utf8(hovered_slot->getData().getName().buffer()); name.parse_utf8(hovered_slot->getData().getName().buffer());
#endif
hover_text_lines.push_back(String("Slot: ") + name); hover_text_lines.push_back(String("Slot: ") + name);
} }
@ -1239,7 +1243,11 @@ void SpineSprite::draw() {
draw_bone(hovered_bone, Color(debug_bones_color.r, debug_bones_color.g, debug_bones_color.b, 1)); draw_bone(hovered_bone, Color(debug_bones_color.r, debug_bones_color.g, debug_bones_color.b, 1));
debug_bones_thickness = thickness; debug_bones_thickness = thickness;
String name; String name;
#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5)
name = String::utf8(hovered_bone->getData().getName().buffer());
#else
name.parse_utf8(hovered_bone->getData().getName().buffer()); name.parse_utf8(hovered_bone->getData().getName().buffer());
#endif
hover_text_lines.push_back(String("Bone: ") + name); hover_text_lines.push_back(String("Bone: ") + name);
} }