From 73a38df35577e12acb20cb1f149c0df822cee06c Mon Sep 17 00:00:00 2001 From: Luke Ingram Date: Wed, 1 Oct 2025 09:49:23 -0400 Subject: [PATCH] [godot] Current WIP to get Spine-Godot working. --- spine-godot/spine_godot/SpineAnimation.cpp | 6 +++- .../spine_godot/SpineAnimationTrack.cpp | 21 +++++++++-- .../spine_godot/SpineAtlasResource.cpp | 17 +++++++-- spine-godot/spine_godot/SpineAttachment.cpp | 6 +++- spine-godot/spine_godot/SpineBoneData.cpp | 6 +++- spine-godot/spine_godot/SpineCommon.h | 4 +-- .../spine_godot/SpineConstraintData.cpp | 6 +++- spine-godot/spine_godot/SpineEditorPlugin.h | 5 +++ spine-godot/spine_godot/SpineEvent.cpp | 2 +- spine-godot/spine_godot/SpineEventData.cpp | 10 ++++-- .../spine_godot/SpineSkeletonDataResource.cpp | 36 +++++++++++++++---- .../spine_godot/SpineSkeletonFileResource.cpp | 2 +- spine-godot/spine_godot/SpineSkin.cpp | 6 +++- spine-godot/spine_godot/SpineSlotData.cpp | 6 +++- spine-godot/spine_godot/SpineSprite.cpp | 12 +++++-- 15 files changed, 119 insertions(+), 26 deletions(-) diff --git a/spine-godot/spine_godot/SpineAnimation.cpp b/spine-godot/spine_godot/SpineAnimation.cpp index 84582a68c..61a5545e6 100644 --- a/spine-godot/spine_godot/SpineAnimation.cpp +++ b/spine-godot/spine_godot/SpineAnimation.cpp @@ -49,7 +49,11 @@ void SpineAnimation::_bind_methods() { String SpineAnimation::get_name() { SPINE_CHECK(get_spine_object(), "") String name; - name.parse_utf8(get_spine_object()->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(get_spine_object()->getName().buffer()); + #else + name.parse_utf8(get_spine_object()->getName().buffer()); + #endif return name; } diff --git a/spine-godot/spine_godot/SpineAnimationTrack.cpp b/spine-godot/spine_godot/SpineAnimationTrack.cpp index fd67a65b4..414333872 100644 --- a/spine-godot/spine_godot/SpineAnimationTrack.cpp +++ b/spine-godot/spine_godot/SpineAnimationTrack.cpp @@ -40,9 +40,14 @@ #ifdef TOOLS_ENABLED #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_tree_editor_plugin.h" #endif +#endif void SpineAnimationTrack::_bind_methods() { ClassDB::bind_method(D_METHOD("set_animation_name", "animation_name"), &SpineAnimationTrack::set_animation_name); @@ -243,7 +248,11 @@ Ref SpineAnimationTrack::create_animation(spine::Animation *animation Ref animation_ref; INSTANTIATE(animation_ref); String name; - name.parse_utf8(animation->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(animation->getName().buffer()); + #else + name.parse_utf8(animation->getName().buffer()); + #endif animation_ref->set_name(name + (loop ? "" : "_looped")); #if VERSION_MAJOR > 3 // animation_ref->set_loop(!loop); @@ -293,7 +302,11 @@ void SpineAnimationTrack::update_animation_state(const Variant &variant_sprite) auto current_entry = animation_state->getCurrent(track_index); bool should_set_mix = mix_duration >= 0; String other_name; - if (current_entry) other_name.parse_utf8(current_entry->getAnimation().getName().buffer()); + #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()); + #endif bool should_set_animation = !current_entry || (animation_name != other_name || current_entry->getLoop() != loop); 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); bool should_set_mix = mix_duration >= 0; 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()); + #endif bool should_set_animation = !current_entry || (animation_name != other_name || current_entry->getLoop() != loop) || animation_changed; animation_changed = false; diff --git a/spine-godot/spine_godot/SpineAtlasResource.cpp b/spine-godot/spine_godot/SpineAtlasResource.cpp index 482c20e2b..e0763bf2c 100644 --- a/spine-godot/spine_godot/SpineAtlasResource.cpp +++ b/spine-godot/spine_godot/SpineAtlasResource.cpp @@ -51,9 +51,13 @@ #ifdef SPINE_GODOT_EXTENSION #include #else +#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) +#include "editor/file_system/editor_file_system.h" +#else #include "editor/editor_file_system.h" #endif #endif +#endif #include @@ -146,7 +150,11 @@ public: void load(spine::AtlasPage &page, const spine::String &path) override { String fixed_path; - fixed_path.parse_utf8(path.buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + fixed_path = String::utf8(path.buffer()); + #else + fixed_path.parse_utf8(path.buffer()); + #endif bool is_resource = fix_path(fixed_path); import_image_resource(fixed_path); @@ -295,7 +303,9 @@ Error SpineAtlasResource::load_from_atlas_file_internal(const String &path, bool clear(); texture_loader = new GodotSpineTextureLoader(&textures, &normal_maps, &specular_maps, normal_map_prefix, specular_map_prefix, is_importing); auto atlas_utf8 = atlas_data.utf8(); - atlas = new spine::Atlas(atlas_utf8, atlas_utf8.length(), source_path.get_base_dir().utf8(), texture_loader); + auto dir_utf8 = source_path.get_base_dir().utf8(); + atlas = new spine::Atlas(atlas_utf8.ptr(), atlas_utf8.length(), dir_utf8.ptr(), texture_loader); + //atlas = new spine::Atlas(atlas_utf8, atlas_utf8.length(), source_path.get_base_dir().utf8(), texture_loader); if (atlas) return OK; clear(); @@ -338,7 +348,8 @@ Error SpineAtlasResource::load_from_file(const String &path) { clear(); texture_loader = new GodotSpineTextureLoader(&textures, &normal_maps, &specular_maps, normal_map_prefix, specular_map_prefix, false); auto utf8 = atlas_data.utf8(); - atlas = new spine::Atlas(utf8.ptr(), utf8.size(), source_path.get_base_dir().utf8(), texture_loader); + auto dir_utf8 = source_path.get_base_dir().utf8(); + atlas = new spine::Atlas(utf8.ptr(), utf8.size(), dir_utf8.ptr(), texture_loader); if (atlas) return OK; clear(); diff --git a/spine-godot/spine_godot/SpineAttachment.cpp b/spine-godot/spine_godot/SpineAttachment.cpp index 0161a43ad..87df45e74 100644 --- a/spine-godot/spine_godot/SpineAttachment.cpp +++ b/spine-godot/spine_godot/SpineAttachment.cpp @@ -42,7 +42,11 @@ SpineAttachment::~SpineAttachment() { String SpineAttachment::get_attachment_name() { SPINE_CHECK(get_spine_object(), "") String name; - name.parse_utf8(get_spine_object()->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(get_spine_object()->getName().buffer()); + #else + name.parse_utf8(get_spine_object()->getName().buffer()); + #endif return name; } diff --git a/spine-godot/spine_godot/SpineBoneData.cpp b/spine-godot/spine_godot/SpineBoneData.cpp index 2a218161c..a168ad7ca 100644 --- a/spine-godot/spine_godot/SpineBoneData.cpp +++ b/spine-godot/spine_godot/SpineBoneData.cpp @@ -54,7 +54,11 @@ int SpineBoneData::get_index() { String SpineBoneData::get_bone_name() { SPINE_CHECK(get_spine_object(), "") String name; - name.parse_utf8(get_spine_object()->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(get_spine_object()->getName().buffer()); + #else + name.parse_utf8(get_spine_object()->getName().buffer()); + #endif return name; } diff --git a/spine-godot/spine_godot/SpineCommon.h b/spine-godot/spine_godot/SpineCommon.h index 14ce5b229..7dc21df8d 100644 --- a/spine-godot/spine_godot/SpineCommon.h +++ b/spine-godot/spine_godot/SpineCommon.h @@ -100,8 +100,8 @@ using namespace godot; return ret; \ } -#define SPINE_STRING(x) spine::String((x).utf8()) -#define SPINE_STRING_TMP(x) spine::String((x).utf8(), true, false) +#define SPINE_STRING(x) spine::String((x).utf8().ptr()) +#define SPINE_STRING_TMP(x) spine::String((x).utf8().ptr(), true, false) // Can't do template classes with Godot's object model :( class SpineObjectWrapper : public REFCOUNTED { diff --git a/spine-godot/spine_godot/SpineConstraintData.cpp b/spine-godot/spine_godot/SpineConstraintData.cpp index 7ff974bc7..863c8a06d 100644 --- a/spine-godot/spine_godot/SpineConstraintData.cpp +++ b/spine-godot/spine_godot/SpineConstraintData.cpp @@ -39,7 +39,11 @@ void SpineConstraintData::_bind_methods() { String SpineConstraintData::get_constraint_name() { SPINE_CHECK(get_spine_object(), "") String name; - name.parse_utf8(get_spine_object()->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(get_spine_object()->getName().buffer()); + #else + name.parse_utf8(get_spine_object()->getName().buffer()); + #endif return name; } diff --git a/spine-godot/spine_godot/SpineEditorPlugin.h b/spine-godot/spine_godot/SpineEditorPlugin.h index d84f8ff99..5b1b35a84 100644 --- a/spine-godot/spine_godot/SpineEditorPlugin.h +++ b/spine-godot/spine_godot/SpineEditorPlugin.h @@ -44,9 +44,14 @@ #include #else #include "editor/editor_node.h" +#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) +#include "editor/inspector/editor_properties.h" +#include "editor/inspector/editor_properties_array_dict.h" +#else #include "editor/editor_properties.h" #include "editor/editor_properties_array_dict.h" #endif +#endif class SpineAtlasResourceImportPlugin : public EditorImportPlugin { GDCLASS(SpineAtlasResourceImportPlugin, EditorImportPlugin) diff --git a/spine-godot/spine_godot/SpineEvent.cpp b/spine-godot/spine_godot/SpineEvent.cpp index 3cf68d63b..3a50148cb 100644 --- a/spine-godot/spine_godot/SpineEvent.cpp +++ b/spine-godot/spine_godot/SpineEvent.cpp @@ -85,7 +85,7 @@ String SpineEvent::get_string_value() { void SpineEvent::set_string_value(const String &v) { SPINE_CHECK(get_spine_object(), ) - get_spine_object()->setString(spine::String(v.utf8())); + get_spine_object()->setString(spine::String(v.utf8().ptr())); } float SpineEvent::get_volume() { diff --git a/spine-godot/spine_godot/SpineEventData.cpp b/spine-godot/spine_godot/SpineEventData.cpp index 43c2893b9..0df62af9a 100644 --- a/spine-godot/spine_godot/SpineEventData.cpp +++ b/spine-godot/spine_godot/SpineEventData.cpp @@ -49,7 +49,11 @@ void SpineEventData::_bind_methods() { String SpineEventData::get_event_name() { SPINE_CHECK(get_spine_object(), "") String name; - name.parse_utf8(get_spine_object()->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(get_spine_object()->getName().buffer()); + #else + name.parse_utf8(get_spine_object()->getName().buffer()); + #endif return name; } @@ -80,7 +84,7 @@ String SpineEventData::get_string_value() { void SpineEventData::set_string_value(const String &v) { SPINE_CHECK(get_spine_object(), ) - get_spine_object()->setString(spine::String(v.utf8())); + get_spine_object()->setString(spine::String(v.utf8().ptr())); } String SpineEventData::get_audio_path() { @@ -90,7 +94,7 @@ String SpineEventData::get_audio_path() { void SpineEventData::set_audio_path(const String &v) { SPINE_CHECK(get_spine_object(), ) - get_spine_object()->setAudioPath(spine::String(v.utf8())); + get_spine_object()->setAudioPath(spine::String(v.utf8().ptr())); } float SpineEventData::get_volume() { diff --git a/spine-godot/spine_godot/SpineSkeletonDataResource.cpp b/spine-godot/spine_godot/SpineSkeletonDataResource.cpp index fec05a063..636f4ddfe 100644 --- a/spine-godot/spine_godot/SpineSkeletonDataResource.cpp +++ b/spine-godot/spine_godot/SpineSkeletonDataResource.cpp @@ -48,9 +48,13 @@ #ifdef SPINE_GODOT_EXTENSION #include #else +#if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) +#include "editor/file_system/editor_file_system.h" +#else #include "editor/editor_file_system.h" #endif #endif +#endif void SpineAnimationMix::_bind_methods() { ClassDB::bind_method(D_METHOD("set_from", "from"), &SpineAnimationMix::set_from); @@ -290,7 +294,7 @@ void SpineSkeletonDataResource::load_resources(spine::Atlas *atlas, const String spine::SkeletonData *data; if (!EMPTY(json)) { spine::SkeletonJson skeletonJson(*atlas); - data = skeletonJson.readSkeletonData(json.utf8()); + data = skeletonJson.readSkeletonData(json.utf8().ptr()); if (!data) { ERR_PRINT(String("Error while loading skeleton data: ") + get_path()); ERR_PRINT(String("Error message: ") + skeletonJson.getError().buffer()); @@ -343,7 +347,11 @@ void SpineSkeletonDataResource::get_animation_names(Vector &animation_na for (size_t i = 0; i < animations.size(); ++i) { auto animation = animations[i]; String name; - name.parse_utf8(animation->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(animation->getName().buffer()); + #else + name.parse_utf8(animation->getName().buffer()); + #endif animation_names.push_back(name); } } @@ -359,7 +367,11 @@ void SpineSkeletonDataResource::get_skin_names(Vector &skin_names) const for (size_t i = 0; i < skins.size(); ++i) { auto skin = skins[i]; String name; - name.parse_utf8(skin->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(skin->getName().buffer()); + #else + name.parse_utf8(skin->getName().buffer()); + #endif skin_names.push_back(name); } } @@ -375,7 +387,11 @@ void SpineSkeletonDataResource::get_slot_names(Vector &slot_names) { for (size_t i = 0; i < slots.size(); ++i) { auto slot = slots[i]; String name; - name.parse_utf8(slot->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(slot->getName().buffer()); + #else + name.parse_utf8(slot->getName().buffer()); + #endif slot_names.push_back(name); } } @@ -391,7 +407,11 @@ void SpineSkeletonDataResource::get_bone_names(Vector &bone_names) { for (size_t i = 0; i < bones.size(); ++i) { auto bone = bones[i]; String name; - name.parse_utf8(bone->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(bone->getName().buffer()); + #else + name.parse_utf8(bone->getName().buffer()); + #endif bone_names.push_back(name); } } @@ -539,7 +559,11 @@ Ref SpineSkeletonDataResource::find_physics_constrai String SpineSkeletonDataResource::get_skeleton_name() const { SPINE_CHECK(skeleton_data, "") String name; - name.parse_utf8(skeleton_data->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(skeleton_data->getName().buffer()); + #else + name.parse_utf8(skeleton_data->getName().buffer()); + #endif return name; } diff --git a/spine-godot/spine_godot/SpineSkeletonFileResource.cpp b/spine-godot/spine_godot/SpineSkeletonFileResource.cpp index 830c61d94..966dc648d 100644 --- a/spine-godot/spine_godot/SpineSkeletonFileResource.cpp +++ b/spine-godot/spine_godot/SpineSkeletonFileResource.cpp @@ -135,7 +135,7 @@ Error SpineSkeletonFileResource::load_from_file(const String &path) { json = FileAccess::get_file_as_string(path, &error); if (error != OK) return error; #endif - if (!checkJson(json.utf8())) return ERR_INVALID_DATA; + if (!checkJson(json.utf8().ptr())) return ERR_INVALID_DATA; } else { #ifdef SPINE_GODOT_EXTENSION binary = FileAccess::get_file_as_bytes(path); diff --git a/spine-godot/spine_godot/SpineSkin.cpp b/spine-godot/spine_godot/SpineSkin.cpp index 88d602e03..7fcf71747 100644 --- a/spine-godot/spine_godot/SpineSkin.cpp +++ b/spine-godot/spine_godot/SpineSkin.cpp @@ -125,7 +125,11 @@ Array SpineSkin::find_attachments_for_slot(int slot_index) { String SpineSkin::get_name() { SPINE_CHECK(get_spine_object(), "") String name; - name.parse_utf8(get_spine_object()->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(get_spine_object()->getName().buffer()); + #else + name.parse_utf8(get_spine_object()->getName().buffer()); + #endif return name; } diff --git a/spine-godot/spine_godot/SpineSlotData.cpp b/spine-godot/spine_godot/SpineSlotData.cpp index 29b0f24e0..20e5fc308 100644 --- a/spine-godot/spine_godot/SpineSlotData.cpp +++ b/spine-godot/spine_godot/SpineSlotData.cpp @@ -54,7 +54,11 @@ int SpineSlotData::get_index() { String SpineSlotData::get_name() { SPINE_CHECK(get_spine_object(), String("")) String name; - name.parse_utf8(get_spine_object()->getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(get_spine_object()->getName().buffer()); + #else + name.parse_utf8(get_spine_object()->getName().buffer()); + #endif return name; } diff --git a/spine-godot/spine_godot/SpineSprite.cpp b/spine-godot/spine_godot/SpineSprite.cpp index 8845a9d53..80fa9b66b 100644 --- a/spine-godot/spine_godot/SpineSprite.cpp +++ b/spine-godot/spine_godot/SpineSprite.cpp @@ -1220,7 +1220,11 @@ void SpineSprite::draw() { Vector hover_text_lines; if (hovered_slot) { String name; - name.parse_utf8(hovered_slot->getData().getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(hovered_slot->getData().getName().buffer()); + #else + name.parse_utf8(hovered_slot->getData().getName().buffer()); + #endif hover_text_lines.push_back(String("Slot: ") + name); } @@ -1230,7 +1234,11 @@ void SpineSprite::draw() { draw_bone(hovered_bone, Color(debug_bones_color.r, debug_bones_color.g, debug_bones_color.b, 1)); debug_bones_thickness = thickness; String name; - name.parse_utf8(hovered_bone->getData().getName().buffer()); + #if (VERSION_MAJOR >= 4 && VERSION_MINOR >= 5) + name = String::utf8(hovered_bone->getData().getName().buffer()); + #else + name.parse_utf8(hovered_bone->getData().getName().buffer()); + #endif hover_text_lines.push_back(String("Bone: ") + name); }