This commit is contained in:
badlogic 2022-04-21 14:06:34 +02:00
commit 5e8ec2fab7
70 changed files with 1805 additions and 1524 deletions

2
.gitignore vendored
View File

@ -170,3 +170,5 @@ spine-godot/spine_godot/spine-cpp
spine-godot/spine_godot/__pycache__ spine-godot/spine_godot/__pycache__
spine-godot/example/.import spine-godot/example/.import
spine-godot/spine_godot/*.obj spine-godot/spine_godot/*.obj
*.bc
spine-godot/example/.godot

1
spine-godot/build.bat Normal file
View File

@ -0,0 +1 @@
cd godot & git apply ../livepp.patch & scons target=debug custom_modules=..\spine_godot vsproj=yes livepp=%LIVEPP% --jobs=16 & cd ..

5
spine-godot/build.sh Executable file
View File

@ -0,0 +1,5 @@
#/bin/sh
set -e
pushd godot
scons compiledb=yes custom_modules="../spine_godot" -j16
popd

View File

@ -1,8 +1,19 @@
[gd_resource type="SpineSkeletonDataResource" load_steps=3 format=2] [gd_resource type="SpineSkeletonDataResource" load_steps=5 format=2]
[ext_resource path="res://assets/spineboy/spineboy.atlas" type="SpineAtlasResource" id=1] [ext_resource path="res://assets/spineboy/spineboy.atlas" type="SpineAtlasResource" id=1]
[ext_resource path="res://assets/spineboy/spineboy-pro.json" type="SpineSkeletonFileResource" id=2] [ext_resource path="res://assets/spineboy/spineboy-pro.json" type="SpineSkeletonFileResource" id=2]
[sub_resource type="SpineAnimationMix" id=1]
from = "idle"
to = "run"
mix = 0.2
[sub_resource type="SpineAnimationMix" id=2]
from = "run"
to = "idle"
mix = 0.2
[resource] [resource]
atlas_res = ExtResource( 1 ) atlas_res = ExtResource( 1 )
skeleton_file_res = ExtResource( 2 ) skeleton_file_res = ExtResource( 2 )
animation_mixes = [ SubResource( 1 ), SubResource( 2 ) ]

View File

@ -2,17 +2,21 @@ extends SpineSprite
func _ready(): func _ready():
var data = get_skeleton().get_data() var data = get_skeleton().get_data()
var customSkin = SpineSkin.new().init("custom-skin") var custom_skin = SpineSkin.new().init("custom-skin")
var skinBase = data.find_skin("skin-base") var skin_base = data.find_skin("skin-base")
customSkin.add_skin(skinBase) custom_skin.add_skin(skin_base)
customSkin.add_skin(data.find_skin("nose/short")) custom_skin.add_skin(data.find_skin("nose/short"))
customSkin.add_skin(data.find_skin("eyelids/girly")) custom_skin.add_skin(data.find_skin("eyelids/girly"))
customSkin.add_skin(data.find_skin("eyes/violet")) custom_skin.add_skin(data.find_skin("eyes/violet"))
customSkin.add_skin(data.find_skin("hair/brown")) custom_skin.add_skin(data.find_skin("hair/brown"))
customSkin.add_skin(data.find_skin("clothes/hoodie-orange")) custom_skin.add_skin(data.find_skin("clothes/hoodie-orange"))
customSkin.add_skin(data.find_skin("legs/pants-jeans")) custom_skin.add_skin(data.find_skin("legs/pants-jeans"))
customSkin.add_skin(data.find_skin("accessories/bag")) custom_skin.add_skin(data.find_skin("accessories/bag"))
customSkin.add_skin(data.find_skin("accessories/hat-red-yellow")) custom_skin.add_skin(data.find_skin("accessories/hat-red-yellow"))
get_skeleton().set_skin(customSkin); get_skeleton().set_skin(custom_skin);
for el in custom_skin.get_attachments():
var entry: SpineSkinEntry = el
print(str(entry.get_slot_index()) + " " + entry.get_name())
get_animation_state().set_animation("dance", true, 0) get_animation_state().set_animation("dance", true, 0)

View File

@ -6,7 +6,7 @@
[node name="Node2D" type="Node2D"] [node name="Node2D" type="Node2D"]
[node name="MixAndMatch" type="SpineSprite" parent="."] [node name="MixAndMatch" type="SpineSprite" parent="."]
position = Vector2( 775.779, 516.856 ) position = Vector2( 532.982, 480.287 )
scale = Vector2( 0.441932, 0.441932 ) scale = Vector2( 0.441932, 0.441932 )
skeleton_data_res = ExtResource( 1 ) skeleton_data_res = ExtResource( 1 )
script = ExtResource( 2 ) script = ExtResource( 2 )

View File

@ -3,7 +3,7 @@ extends SpineSprite
func _ready(): func _ready():
get_animation_state().set_animation("idle", true, 0) get_animation_state().set_animation("idle", true, 0)
func _process(delta): func _process(_delta):
if Input.is_action_just_pressed("ui_left"): if Input.is_action_just_pressed("ui_left"):
get_animation_state().set_animation("run", true, 0) get_animation_state().set_animation("run", true, 0)
get_skeleton().set_scale_x(-1) get_skeleton().set_scale_x(-1)

View File

@ -4,4 +4,4 @@ xcopy /E /I .idea godot\.idea
copy custom.py godot copy custom.py godot
rmdir spine_godot\spine-cpp /s /q rmdir spine_godot\spine-cpp /s /q
xcopy /E /I ..\spine-cpp\spine-cpp spine_godot\spine-cpp xcopy /E /I ..\spine-cpp\spine-cpp spine_godot\spine-cpp
cd godot & git apply ../livepp.patch & scons target=debug custom_modules=..\spine_godot vsproj=yes livepp=%LIVEPP% --jobs=16 & cd .. build.bat

View File

@ -1,10 +1,23 @@
#!/bin/bash #!/bin/bash
set -e set -e
if [ "$#" -eq 0 ]; then
echo "Usage: ./setup.sh <godot_branch_or_tag>"
echo
echo "e.g.:"
echo " ./setup.sh 3.4.4-stable"
echo " ./setup.sh master"
read version
exit 1
fi
branch=${1%/}
rm -rf godot rm -rf godot
git clone --depth 1 https://github.com/godotengine/godot.git -b 3.4.4-stable git clone --depth 1 https://github.com/godotengine/godot.git -b $branch
cp -r .idea godot cp -r .idea godot
cp custom.py godot cp custom.py godot
cp -r ../spine-cpp/spine-cpp spine_godot cp -r ../spine-cpp/spine-cpp spine_godot
pushd godot rm -rf example/.import
scons compiledb=yes custom_modules="../spine_godot" -j16 rm -rf example/.godot
popd ./build.sh

View File

@ -29,17 +29,18 @@
#include "GodotSpineExtension.h" #include "GodotSpineExtension.h"
#include "core/os/memory.h" #include "core/os/memory.h"
#include "core/version.h"
#if VERSION_MAJOR > 3
#include "core/io/file_access.h"
#else
#include "core/os/file_access.h" #include "core/os/file_access.h"
#endif
#include <spine/SpineString.h> #include <spine/SpineString.h>
spine::SpineExtension *spine::getDefaultExtension() { spine::SpineExtension *spine::getDefaultExtension() {
return new GodotSpineExtension(); return new GodotSpineExtension();
} }
GodotSpineExtension::GodotSpineExtension() {}
GodotSpineExtension::~GodotSpineExtension() {}
void *GodotSpineExtension::_alloc(size_t size, const char *file, int line) { void *GodotSpineExtension::_alloc(size_t size, const char *file, int line) {
return memalloc(size); return memalloc(size);
} }

View File

@ -33,11 +33,6 @@
#include <spine/Extension.h> #include <spine/Extension.h>
class GodotSpineExtension : public spine::SpineExtension { class GodotSpineExtension : public spine::SpineExtension {
public:
GodotSpineExtension();
virtual ~GodotSpineExtension();
protected: protected:
virtual void *_alloc(size_t size, const char *file, int line); virtual void *_alloc(size_t size, const char *file, int line);

View File

@ -1,8 +1,15 @@
Import('env') Import('env')
env_spine_runtime = env.Clone()
# Need to add the include path to env so the vsproj generator consumes it. # Need to add the include path to env so the vsproj generator consumes it.
env.Append(CPPPATH=["#../spine_godot/spine-cpp/include"]) if env["vsproj"]:
env.Append(CPPPATH=["#../spine_godot/spine-cpp/include"])
env_spine_runtime = env.Clone()
env_spine_runtime.Append(CPPPATH=["#../spine_godot/spine-cpp/include"]) env_spine_runtime.Append(CPPPATH=["#../spine_godot/spine-cpp/include"])
env_spine_runtime.add_source_files(env.modules_sources, "spine-cpp/src/spine/*.cpp") env_spine_runtime.add_source_files(env.modules_sources, "spine-cpp/src/spine/*.cpp")
env_spine_runtime.add_source_files(env.modules_sources, "*.cpp") env_spine_runtime.add_source_files(env.modules_sources, "*.cpp")
# Needed on Clang to not have a gazillion -Winconsistent-missing-override warnings for GDCLASS
# I do not understand why other modules using GDCLASS do not have this issue when compiling.
if not env_spine_runtime.msvc:
env_spine_runtime.Append(CXXFLAGS=["-Wno-inconsistent-missing-override"])

View File

@ -27,13 +27,13 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
#include "common.h"
#include "SpineAnimation.h" #include "SpineAnimation.h"
#include "SpineSkeleton.h" #include "SpineSkeleton.h"
#include "SpineEvent.h" #include "SpineEvent.h"
#include "SpineTimeline.h" #include "SpineTimeline.h"
#if VERSION_MAJOR == 3
#include "core/method_bind_ext.gen.inc" #include "core/method_bind_ext.gen.inc"
#endif
void SpineAnimation::_bind_methods() { void SpineAnimation::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_name"), &SpineAnimation::get_name); ClassDB::bind_method(D_METHOD("get_name"), &SpineAnimation::get_name);
@ -48,9 +48,6 @@ void SpineAnimation::_bind_methods() {
SpineAnimation::SpineAnimation() : animation(nullptr) { SpineAnimation::SpineAnimation() : animation(nullptr) {
} }
SpineAnimation::~SpineAnimation() {
}
String SpineAnimation::get_name() { String SpineAnimation::get_name() {
SPINE_CHECK(animation, "") SPINE_CHECK(animation, "")
return animation->getName().buffer(); return animation->getName().buffer();

View File

@ -30,16 +30,16 @@
#ifndef GODOT_SPINEANIMATION_H #ifndef GODOT_SPINEANIMATION_H
#define GODOT_SPINEANIMATION_H #define GODOT_SPINEANIMATION_H
#include "SpineCommon.h"
#include "SpineConstant.h" #include "SpineConstant.h"
#include "core/reference.h"
#include <spine/Animation.h> #include <spine/Animation.h>
class SpineEvent; class SpineEvent;
class SpineSkeleton; class SpineSkeleton;
class SpineTimeline; class SpineTimeline;
class SpineAnimation : public Reference { class SpineAnimation : public REFCOUNTED {
GDCLASS(SpineAnimation, Reference); GDCLASS(SpineAnimation, REFCOUNTED);
private: private:
spine::Animation *animation; spine::Animation *animation;
@ -49,9 +49,8 @@ protected:
public: public:
SpineAnimation(); SpineAnimation();
~SpineAnimation();
void set_spine_object(spine::Animation *animation) { this->animation = animation; } void set_spine_object(spine::Animation *_animation) { this->animation = _animation; }
spine::Animation *get_spine_object() { return animation; } spine::Animation *get_spine_object() { return animation; }

View File

@ -27,7 +27,6 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
#include "common.h"
#include "SpineAnimationState.h" #include "SpineAnimationState.h"
void SpineAnimationState::_bind_methods() { void SpineAnimationState::_bind_methods() {
@ -54,7 +53,7 @@ SpineAnimationState::~SpineAnimationState() {
delete animation_state; delete animation_state;
} }
void SpineAnimationState::set_skeleton_data_res(Ref<SpineSkeletonDataResource> data_res) { void SpineAnimationState::set_skeleton_data_res(const Ref<SpineSkeletonDataResource> &data_res) {
delete animation_state; delete animation_state;
animation_state = nullptr; animation_state = nullptr;
skeleton_data_res = data_res; skeleton_data_res = data_res;
@ -62,10 +61,6 @@ void SpineAnimationState::set_skeleton_data_res(Ref<SpineSkeletonDataResource> d
animation_state = new spine::AnimationState(skeleton_data_res->get_animation_state_data()); animation_state = new spine::AnimationState(skeleton_data_res->get_animation_state_data());
} }
Ref<SpineSkeletonDataResource> SpineAnimationState::get_skeleton_data_res() const {
return skeleton_data_res;
}
void SpineAnimationState::update(float delta) { void SpineAnimationState::update(float delta) {
SPINE_CHECK(animation_state,) SPINE_CHECK(animation_state,)
animation_state->update(delta); animation_state->update(delta);

View File

@ -30,11 +30,12 @@
#ifndef GODOT_SPINEANIMATIONSTATE_H #ifndef GODOT_SPINEANIMATIONSTATE_H
#define GODOT_SPINEANIMATIONSTATE_H #define GODOT_SPINEANIMATIONSTATE_H
#include "SpineCommon.h"
#include "SpineSkeleton.h" #include "SpineSkeleton.h"
#include "SpineTrackEntry.h" #include "SpineTrackEntry.h"
class SpineAnimationState : public Reference { class SpineAnimationState : public REFCOUNTED {
GDCLASS(SpineAnimationState, Reference) GDCLASS(SpineAnimationState, REFCOUNTED)
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -49,9 +50,7 @@ public:
spine::AnimationState *get_spine_object() { return animation_state; } spine::AnimationState *get_spine_object() { return animation_state; }
void set_skeleton_data_res(Ref<SpineSkeletonDataResource> skeleton_data_res); void set_skeleton_data_res(const Ref<SpineSkeletonDataResource> &skeleton_data_res);
Ref<SpineSkeletonDataResource> get_skeleton_data_res() const;
void update(float delta); void update(float delta);

View File

@ -27,11 +27,10 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
#include "core/io/json.h"
#include "scene/resources/texture.h"
#include "SpineAtlasResource.h" #include "SpineAtlasResource.h"
#include "SpineRendererObject.h" #include "SpineRendererObject.h"
#include "core/io/json.h"
#include "scene/resources/texture.h"
#include <spine/TextureLoader.h> #include <spine/TextureLoader.h>
class GodotSpineTextureLoader : public spine::TextureLoader { class GodotSpineTextureLoader : public spine::TextureLoader {
@ -44,7 +43,7 @@ public:
GodotSpineTextureLoader(Array *_textures, Array *_normal_maps, const String &normal_map_prefix) : textures(_textures), normal_maps(_normal_maps), normal_map_prefix(normal_map_prefix) { GodotSpineTextureLoader(Array *_textures, Array *_normal_maps, const String &normal_map_prefix) : textures(_textures), normal_maps(_normal_maps), normal_map_prefix(normal_map_prefix) {
} }
String fix_path(const String &path) { static String fix_path(const String &path) {
if (path.size() > 5 && path[4] == '/' && path[5] == '/') return path; if (path.size() > 5 && path[4] == '/' && path[5] == '/') return path;
const String prefix = "res:/"; const String prefix = "res:/";
auto i = path.find(prefix); auto i = path.find(prefix);
@ -52,7 +51,7 @@ public:
if (sub_str_pos < 0) return path; if (sub_str_pos < 0) return path;
auto res = path.substr(sub_str_pos); auto res = path.substr(sub_str_pos);
if (res.size() > 0) { if (!EMPTY(res)) {
if (res[0] != '/') { if (res[0] != '/') {
return prefix + "/" + res; return prefix + "/" + res;
} else { } else {
@ -62,12 +61,16 @@ public:
return path; return path;
} }
virtual void load(spine::AtlasPage &page, const spine::String &path) { void load(spine::AtlasPage &page, const spine::String &path) override {
Error error = OK; Error error = OK;
auto fixed_path = fix_path(String(path.buffer())); auto fixed_path = fix_path(String(path.buffer()));
#if VERSION_MAJOR > 3
Ref<Texture2D> texture = ResourceLoader::load(fixed_path, "", ResourceFormatLoader::CACHE_MODE_REUSE, &error);
#else
Ref<Texture> texture = ResourceLoader::load(fixed_path, "", false, &error); Ref<Texture> texture = ResourceLoader::load(fixed_path, "", false, &error);
if (error != OK) { #endif
if (error != OK || !texture.is_valid()) {
ERR_PRINT(vformat("Can't load texture: \"%s\"", String(path.buffer()))); ERR_PRINT(vformat("Can't load texture: \"%s\"", String(path.buffer())));
auto renderer_object = memnew(SpineRendererObject); auto renderer_object = memnew(SpineRendererObject);
renderer_object->texture = Ref<Texture>(nullptr); renderer_object->texture = Ref<Texture>(nullptr);
@ -81,8 +84,7 @@ public:
renderer_object->texture = texture; renderer_object->texture = texture;
renderer_object->normal_map = Ref<Texture>(nullptr); renderer_object->normal_map = Ref<Texture>(nullptr);
String temp_path = fixed_path; String new_path = vformat("%s/%s_%s", fixed_path.get_base_dir(), normal_map_prefix, fixed_path.get_file());
String new_path = vformat("%s/%s_%s", temp_path.get_base_dir(), normal_map_prefix, temp_path.get_file());
if (ResourceLoader::exists(new_path)) { if (ResourceLoader::exists(new_path)) {
Ref<Texture> normal_map = ResourceLoader::load(new_path); Ref<Texture> normal_map = ResourceLoader::load(new_path);
normal_maps->append(normal_map); normal_maps->append(normal_map);
@ -94,7 +96,7 @@ public:
page.height = texture->get_height(); page.height = texture->get_height();
} }
virtual void unload(void *data) { void unload(void *data) override {
auto renderer_object = (SpineRendererObject *) data; auto renderer_object = (SpineRendererObject *) data;
Ref<Texture> &texture = renderer_object->texture; Ref<Texture> &texture = renderer_object->texture;
if (texture.is_valid()) texture.unref(); if (texture.is_valid()) texture.unref();
@ -160,16 +162,22 @@ Error SpineAtlasResource::load_from_atlas_file(const String &path) {
} }
Error SpineAtlasResource::load_from_file(const String &path) { Error SpineAtlasResource::load_from_file(const String &path) {
Error err; Error error;
String json_string = FileAccess::get_file_as_string(path, &err); String json_string = FileAccess::get_file_as_string(path, &error);
if (err != OK) return err; if (error != OK) return error;
#if VERSION_MAJOR > 3
JSON json;
error = json.parse(json_string);
if (error != OK) return error;
Variant result = json.get_data();
#else
String error_string; String error_string;
int error_line; int error_line;
JSON json;
Variant result; Variant result;
err = json.parse(json_string, result, error_string, error_line); error = JSON::parse(json_string, result, error_string, error_line);
if (err != OK) return err; if (error != OK) return error;
#endif
Dictionary content = Dictionary(result); Dictionary content = Dictionary(result);
source_path = content["source_path"]; source_path = content["source_path"];
@ -187,22 +195,37 @@ Error SpineAtlasResource::load_from_file(const String &path) {
Error SpineAtlasResource::save_to_file(const String &path) { Error SpineAtlasResource::save_to_file(const String &path) {
Error err; Error err;
#if VERSION_MAJOR > 3
Ref<FileAccess> file = FileAccess::open(path, FileAccess::WRITE, &err);
if (err != OK) return err;
#else
FileAccess *file = FileAccess::open(path, FileAccess::WRITE, &err); FileAccess *file = FileAccess::open(path, FileAccess::WRITE, &err);
if (err != OK) { if (err != OK) {
if (file) file->close(); if (file) file->close();
return err; return err;
} }
#endif
Dictionary content; Dictionary content;
content["source_path"] = source_path; content["source_path"] = source_path;
content["atlas_data"] = atlas_data; content["atlas_data"] = atlas_data;
content["normal_texture_prefix"] = normal_map_prefix; content["normal_texture_prefix"] = normal_map_prefix;
#if VERSION_MAJOR > 3
JSON json;
file->store_string(json.stringify(content));
file->flush();
#else
file->store_string(JSON::print(content)); file->store_string(JSON::print(content));
file->close(); file->close();
#endif
return OK; 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
RES SpineAtlasResourceFormatLoader::load(const String &path, const String &original_path, Error *error) { RES SpineAtlasResourceFormatLoader::load(const String &path, const String &original_path, Error *error) {
#endif
Ref<SpineAtlasResource> atlas = memnew(SpineAtlasResource); Ref<SpineAtlasResource> atlas = memnew(SpineAtlasResource);
atlas->load_from_file(path); atlas->load_from_file(path);
if (error) *error = OK; if (error) *error = OK;
@ -224,7 +247,7 @@ bool SpineAtlasResourceFormatLoader::handles_type(const String &type) const {
} }
Error SpineAtlasResourceFormatSaver::save(const String &path, const RES &resource, uint32_t flags) { Error SpineAtlasResourceFormatSaver::save(const String &path, const RES &resource, uint32_t flags) {
Ref<SpineAtlasResource> res = resource.get_ref_ptr(); Ref<SpineAtlasResource> res = resource;
return res->save_to_file(path); return res->save_to_file(path);
} }

View File

@ -30,11 +30,13 @@
#ifndef GODOT_SPINEATLASRESOURCE_H #ifndef GODOT_SPINEATLASRESOURCE_H
#define GODOT_SPINEATLASRESOURCE_H #define GODOT_SPINEATLASRESOURCE_H
#include "SpineCommon.h"
#include "core/io/resource_loader.h" #include "core/io/resource_loader.h"
#include "core/io/resource_saver.h" #include "core/io/resource_saver.h"
#include "core/io/image_loader.h" #include "core/io/image_loader.h"
#include <spine/Atlas.h> #include <spine/Atlas.h>
class GodotSpineTextureLoader; class GodotSpineTextureLoader;
class SpineAtlasResource : public Resource { class SpineAtlasResource : public Resource {
@ -57,10 +59,7 @@ protected:
public: public:
SpineAtlasResource(); SpineAtlasResource();
~SpineAtlasResource() override;
virtual ~SpineAtlasResource();
String &get_atlas_data() { return atlas_data; }
spine::Atlas *get_spine_atlas() { return atlas; } spine::Atlas *get_spine_atlas() { return atlas; }
@ -83,20 +82,24 @@ class SpineAtlasResourceFormatLoader : public ResourceFormatLoader {
GDCLASS(SpineAtlasResourceFormatLoader, ResourceFormatLoader) GDCLASS(SpineAtlasResourceFormatLoader, ResourceFormatLoader)
public: public:
virtual RES load(const String &path, const String &original_path, Error *error = nullptr); #if VERSION_MAJOR > 3
RES load(const String &path, const String &original_path, Error *error, bool use_sub_threads, float *progress, CacheMode cache_mode) override;
#else
RES load(const String &path, const String &original_path, Error *error) override;
#endif
virtual void get_recognized_extensions(List<String> *extensions) const; void get_recognized_extensions(List<String> *extensions) const override;
virtual bool handles_type(const String &type) const; bool handles_type(const String &type) const override;
virtual String get_resource_type(const String &path) const; String get_resource_type(const String &path) const override;
}; };
class SpineAtlasResourceFormatSaver : public ResourceFormatSaver { class SpineAtlasResourceFormatSaver : public ResourceFormatSaver {
GDCLASS(SpineAtlasResourceFormatSaver, ResourceFormatSaver) GDCLASS(SpineAtlasResourceFormatSaver, ResourceFormatSaver)
public: public:
Error save(const String &path, const RES &resource, uint32_t flags = 0) override; Error save(const String &path, const RES &resource, uint32_t flags) override;
void get_recognized_extensions(const RES &resource, List<String> *extensions) const override; void get_recognized_extensions(const RES &resource, List<String> *extensions) const override;

View File

@ -28,7 +28,7 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineAttachment.h" #include "SpineAttachment.h"
#include "common.h" #include "SpineCommon.h"
void SpineAttachment::_bind_methods() { void SpineAttachment::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_attachment_name"), &SpineAttachment::get_attachment_name); ClassDB::bind_method(D_METHOD("get_attachment_name"), &SpineAttachment::get_attachment_name);

View File

@ -30,11 +30,12 @@
#ifndef GODOT_SPINEATTACHMENT_H #ifndef GODOT_SPINEATTACHMENT_H
#define GODOT_SPINEATTACHMENT_H #define GODOT_SPINEATTACHMENT_H
#include "SpineCommon.h"
#include <spine/spine.h> #include <spine/spine.h>
#include "core/reference.h"
class SpineAttachment : public Reference {
GDCLASS(SpineAttachment, Reference) class SpineAttachment : public REFCOUNTED {
GDCLASS(SpineAttachment, REFCOUNTED)
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -44,7 +45,7 @@ private:
public: public:
SpineAttachment(); SpineAttachment();
~SpineAttachment(); ~SpineAttachment() override;
void set_spine_object(spine::Attachment *_attachment) { void set_spine_object(spine::Attachment *_attachment) {
attachment = _attachment; attachment = _attachment;

View File

@ -30,7 +30,7 @@
#include "SpineBone.h" #include "SpineBone.h"
#include "SpineSprite.h" #include "SpineSprite.h"
#include "SpineSkeleton.h" #include "SpineSkeleton.h"
#include "common.h" #include "SpineCommon.h"
void SpineBone::_bind_methods() { void SpineBone::_bind_methods() {
ClassDB::bind_method(D_METHOD("update_world_transform"), &SpineBone::update_world_transform); ClassDB::bind_method(D_METHOD("update_world_transform"), &SpineBone::update_world_transform);
@ -101,8 +101,6 @@ void SpineBone::_bind_methods() {
SpineBone::SpineBone() : bone(nullptr), sprite(nullptr) {} SpineBone::SpineBone() : bone(nullptr), sprite(nullptr) {}
SpineBone::~SpineBone() {}
void SpineBone::set_spine_sprite(SpineSprite* _sprite) { void SpineBone::set_spine_sprite(SpineSprite* _sprite) {
this->sprite = _sprite; this->sprite = _sprite;
} }
@ -429,12 +427,11 @@ void SpineBone::set_active(bool v) {
} }
// External feature functions // External feature functions
void SpineBone::apply_world_transform_2d(Variant o) { void SpineBone::apply_world_transform_2d(const Variant &o) {
SPINE_CHECK(bone,) SPINE_CHECK(bone,)
if (o.get_type() == Variant::OBJECT) { if (o.get_type() == Variant::OBJECT) {
auto node = (Node *) o; auto node2d = Object::cast_to<Node2D>(o.operator Object*());
if (node->is_class("Node2D")) { if (node2d) {
auto node2d = (Node2D *) node;
// In godot the y-axis is nag to spine // In godot the y-axis is nag to spine
node2d->set_transform(Transform2D( node2d->set_transform(Transform2D(
get_a(), get_c(), get_a(), get_c(),

View File

@ -30,16 +30,16 @@
#ifndef GODOT_SPINEBONE_H #ifndef GODOT_SPINEBONE_H
#define GODOT_SPINEBONE_H #define GODOT_SPINEBONE_H
#include <scene/2d/node_2d.h> #include "SpineCommon.h"
#include <spine/spine.h>
#include "SpineBoneData.h" #include "SpineBoneData.h"
#include "scene/2d/node_2d.h"
#include <spine/Bone.h>
class SpineSkeleton; class SpineSkeleton;
class SpineSprite; class SpineSprite;
class SpineBone : public Reference { class SpineBone : public REFCOUNTED {
GDCLASS(SpineBone, Reference) GDCLASS(SpineBone, REFCOUNTED)
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -50,7 +50,6 @@ private:
public: public:
SpineBone(); SpineBone();
~SpineBone();
void set_spine_object(spine::Bone *_bone) { bone = _bone; } void set_spine_object(spine::Bone *_bone) { bone = _bone; }
@ -177,7 +176,7 @@ public:
void set_active(bool v); void set_active(bool v);
// External feature functions // External feature functions
void apply_world_transform_2d(Variant o); void apply_world_transform_2d(const Variant &o);
Transform2D get_godot_transform(); Transform2D get_godot_transform();

View File

@ -28,7 +28,7 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineBoneData.h" #include "SpineBoneData.h"
#include "common.h" #include "SpineCommon.h"
void SpineBoneData::_bind_methods() { void SpineBoneData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_index"), &SpineBoneData::get_index); ClassDB::bind_method(D_METHOD("get_index"), &SpineBoneData::get_index);
@ -61,9 +61,6 @@ void SpineBoneData::_bind_methods() {
SpineBoneData::SpineBoneData() : bone_data(nullptr) { SpineBoneData::SpineBoneData() : bone_data(nullptr) {
} }
SpineBoneData::~SpineBoneData() {
}
int SpineBoneData::get_index() { int SpineBoneData::get_index() {
SPINE_CHECK(bone_data, 0) SPINE_CHECK(bone_data, 0)
return bone_data->getIndex(); return bone_data->getIndex();
@ -76,11 +73,11 @@ String SpineBoneData::get_bone_name() {
Ref<SpineBoneData> SpineBoneData::get_parent() { Ref<SpineBoneData> SpineBoneData::get_parent() {
SPINE_CHECK(bone_data, nullptr) SPINE_CHECK(bone_data, nullptr)
auto p = bone_data->getParent(); auto parent = bone_data->getParent();
if (p == nullptr) return nullptr; if (!parent) return nullptr;
Ref<SpineBoneData> gd_bone_data(memnew(SpineBoneData)); Ref<SpineBoneData> parent_ref(memnew(SpineBoneData));
gd_bone_data->set_spine_object(p); parent_ref->set_spine_object(parent);
return gd_bone_data; return parent_ref;
} }
float SpineBoneData::get_length() { float SpineBoneData::get_length() {

View File

@ -30,12 +30,12 @@
#ifndef GODOT_SPINEBONEDATA_H #ifndef GODOT_SPINEBONEDATA_H
#define GODOT_SPINEBONEDATA_H #define GODOT_SPINEBONEDATA_H
#include "core/reference.h" #include "SpineCommon.h"
#include "SpineConstant.h" #include "SpineConstant.h"
#include <spine/BoneData.h> #include <spine/BoneData.h>
class SpineBoneData : public Reference { class SpineBoneData : public REFCOUNTED {
GDCLASS(SpineBoneData, Reference); GDCLASS(SpineBoneData, REFCOUNTED);
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -45,7 +45,6 @@ private:
public: public:
SpineBoneData(); SpineBoneData();
~SpineBoneData();
void set_spine_object(spine::BoneData *_bone_data) { bone_data = _bone_data; } void set_spine_object(spine::BoneData *_bone_data) { bone_data = _bone_data; }

View File

@ -28,7 +28,6 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineCollisionShapeProxy.h" #include "SpineCollisionShapeProxy.h"
#include "SpineSprite.h" #include "SpineSprite.h"
void SpineCollisionShapeProxy::_bind_methods() { void SpineCollisionShapeProxy::_bind_methods() {
@ -100,7 +99,7 @@ void SpineCollisionShapeProxy::set_slot(const String &slotName) {
spine::Slot *SpineCollisionShapeProxy::get_spine_slot(const String &slotName) const { spine::Slot *SpineCollisionShapeProxy::get_spine_slot(const String &slotName) const {
auto sprite = get_spine_sprite(); auto sprite = get_spine_sprite();
if (sprite == NULL || slot_name.empty()) return NULL; if (sprite == NULL || EMPTY(slot_name)) return NULL;
if (!sprite->get_skeleton().is_valid()) return NULL; if (!sprite->get_skeleton().is_valid()) return NULL;
spine::Skeleton *skeleton = sprite->get_skeleton()->get_spine_object(); spine::Skeleton *skeleton = sprite->get_skeleton()->get_spine_object();
spine::Slot *slot = skeleton->findSlot(spine::String(slot_name.utf8())); spine::Slot *slot = skeleton->findSlot(spine::String(slot_name.utf8()));
@ -156,7 +155,7 @@ void SpineCollisionShapeProxy::_get_property_list(List<PropertyInfo> *p_list) co
p.name = "Slot"; p.name = "Slot";
p.type = Variant::STRING; p.type = Variant::STRING;
get_slot_names(slot_names); get_slot_names(slot_names);
if (slot_names.empty()) if (EMPTY(slot_names))
slot_names.push_back("None"); slot_names.push_back("None");
p.hint_string = String(",").join(slot_names); p.hint_string = String(",").join(slot_names);
p.hint = PROPERTY_HINT_ENUM; p.hint = PROPERTY_HINT_ENUM;
@ -189,6 +188,6 @@ void SpineCollisionShapeProxy::get_slot_names(Vector<String> &slot_names) const
for (size_t i = 0; i < slots.size(); ++i) { for (size_t i = 0; i < slots.size(); ++i) {
auto slot = (Ref<SpineSlot>) slots[i]; auto slot = (Ref<SpineSlot>) slots[i];
if (slot.is_valid()) if (slot.is_valid())
slot_names.set(i, slot->get_data()->get_slot_name()); slot_names.set(i, slot->get_data()->get_name());
} }
} }

View File

@ -31,7 +31,7 @@
#define GODOT_SPINECOLLISIONSHAPEPROXY_H #define GODOT_SPINECOLLISIONSHAPEPROXY_H
#include "scene/2d/collision_polygon_2d.h" #include "scene/2d/collision_polygon_2d.h"
#include <spine/spine.h> #include <spine/Slot.h>
class SpineSprite; class SpineSprite;
class SpineAnimationState; class SpineAnimationState;

View File

@ -30,7 +30,25 @@
#ifndef SPINE_COMMON_H #ifndef SPINE_COMMON_H
#define SPINE_COMMON_H #define SPINE_COMMON_H
#include "core/version.h"
#if VERSION_MAJOR > 3
#include "core/core_bind.h"
#include "core/error/error_macros.h"
#define REFCOUNTED RefCounted
#define EMPTY(x) ((x).is_empty())
#define EMPTY_PTR(x) ((x)->is_empty())
#define INSTANTIATE(x) (x).instantiate()
#define NOTIFY_PROPERTY_LIST_CHANGED() notify_property_list_changed()
#else
#include "core/object.h"
#include "core/reference.h"
#include "core/error_macros.h" #include "core/error_macros.h"
#define REFCOUNTED Reference
#define EMPTY(x) ((x).empty())
#define EMPTY_PTR(x) ((x)->empty())
#define INSTANTIATE(x) (x).instance()
#define NOTIFY_PROPERTY_LIST_CHANGED() property_list_changed_notify()
#endif
#define SPINE_CHECK(obj, ret) \ #define SPINE_CHECK(obj, ret) \
if (!(obj)) { \ if (!(obj)) { \
@ -38,4 +56,6 @@
return ret; \ return ret; \
} }
#define SPINE_STRING(x) spine::String((x).utf8())
#endif #endif

View File

@ -64,4 +64,20 @@ void SpineConstant::_bind_methods() {
BIND_ENUM_CONSTANT(TransformMode_NoRotationOrReflection) BIND_ENUM_CONSTANT(TransformMode_NoRotationOrReflection)
BIND_ENUM_CONSTANT(TransformMode_NoScale) BIND_ENUM_CONSTANT(TransformMode_NoScale)
BIND_ENUM_CONSTANT(TransformMode_NoScaleOrReflection) BIND_ENUM_CONSTANT(TransformMode_NoScaleOrReflection)
BIND_ENUM_CONSTANT(PositionMode_Fixed)
BIND_ENUM_CONSTANT(PositionMode_Percent)
BIND_ENUM_CONSTANT(SpacingMode_Length)
BIND_ENUM_CONSTANT(SpacingMode_Fixed)
BIND_ENUM_CONSTANT(SpacingMode_Percent)
BIND_ENUM_CONSTANT(RotateMode_Tangent)
BIND_ENUM_CONSTANT(RotateMode_Chain)
BIND_ENUM_CONSTANT(RotateMode_ChainScale)
BIND_ENUM_CONSTANT(BlendMode_Normal)
BIND_ENUM_CONSTANT(BlendMode_Additive)
BIND_ENUM_CONSTANT(BlendMode_Multiply)
BIND_ENUM_CONSTANT(BlendMode_Screen)
} }

View File

@ -30,7 +30,7 @@
#ifndef GODOT_SPINECONSTANT_H #ifndef GODOT_SPINECONSTANT_H
#define GODOT_SPINECONSTANT_H #define GODOT_SPINECONSTANT_H
#include "core/object.h" #include "SpineCommon.h"
class SpineConstant : public Object { class SpineConstant : public Object {
GDCLASS(SpineConstant, Object); GDCLASS(SpineConstant, Object);
@ -81,11 +81,39 @@ public:
TransformMode_NoScale, TransformMode_NoScale,
TransformMode_NoScaleOrReflection TransformMode_NoScaleOrReflection
}; };
enum PositionMode {
PositionMode_Fixed = 0,
PositionMode_Percent
};
enum SpacingMode {
SpacingMode_Length = 0,
SpacingMode_Fixed,
SpacingMode_Percent
};
enum RotateMode {
RotateMode_Tangent = 0,
RotateMode_Chain,
RotateMode_ChainScale
};
enum BlendMode {
BlendMode_Normal = 0,
BlendMode_Additive,
BlendMode_Multiply,
BlendMode_Screen
};
}; };
VARIANT_ENUM_CAST(SpineConstant::MixBlend); VARIANT_ENUM_CAST(SpineConstant::MixBlend)
VARIANT_ENUM_CAST(SpineConstant::MixDirection); VARIANT_ENUM_CAST(SpineConstant::MixDirection)
VARIANT_ENUM_CAST(SpineConstant::PropertyId); VARIANT_ENUM_CAST(SpineConstant::PropertyId)
VARIANT_ENUM_CAST(SpineConstant::TransformMode); VARIANT_ENUM_CAST(SpineConstant::TransformMode)
VARIANT_ENUM_CAST(SpineConstant::PositionMode)
VARIANT_ENUM_CAST(SpineConstant::SpacingMode)
VARIANT_ENUM_CAST(SpineConstant::RotateMode)
VARIANT_ENUM_CAST(SpineConstant::BlendMode)
#endif//GODOT_SPINECONSTANT_H #endif//GODOT_SPINECONSTANT_H

View File

@ -28,8 +28,8 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineConstraintData.h" #include "SpineConstraintData.h"
#include "SpineCommon.h"
#include <spine/ConstraintData.h> #include <spine/ConstraintData.h>
#include "common.h"
void SpineConstraintData::_bind_methods() { void SpineConstraintData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_constraint_name"), &SpineConstraintData::get_constraint_name); ClassDB::bind_method(D_METHOD("get_constraint_name"), &SpineConstraintData::get_constraint_name);
@ -42,9 +42,6 @@ void SpineConstraintData::_bind_methods() {
SpineConstraintData::SpineConstraintData() : constraint_data(nullptr) { SpineConstraintData::SpineConstraintData() : constraint_data(nullptr) {
} }
SpineConstraintData::~SpineConstraintData() {
}
String SpineConstraintData::get_constraint_name() { String SpineConstraintData::get_constraint_name() {
SPINE_CHECK(constraint_data, "") SPINE_CHECK(constraint_data, "")
return constraint_data->getName().buffer(); return constraint_data->getName().buffer();

View File

@ -30,14 +30,11 @@
#ifndef GODOT_SPINECONSTRAINTDATA_H #ifndef GODOT_SPINECONSTRAINTDATA_H
#define GODOT_SPINECONSTRAINTDATA_H #define GODOT_SPINECONSTRAINTDATA_H
#include "core/reference.h" #include "SpineCommon.h"
#include <spine/ConstraintData.h>
namespace spine { class SpineConstraintData : public REFCOUNTED {
class ConstraintData; GDCLASS(SpineConstraintData, REFCOUNTED);
}
class SpineConstraintData : public Reference {
GDCLASS(SpineConstraintData, Reference);
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -46,7 +43,6 @@ protected:
public: public:
SpineConstraintData(); SpineConstraintData();
~SpineConstraintData();
void set_spine_object(spine::ConstraintData *_constraint_data) { void set_spine_object(spine::ConstraintData *_constraint_data) {
constraint_data = _constraint_data; constraint_data = _constraint_data;

View File

@ -29,7 +29,6 @@
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
#include "SpineEditorPlugin.h" #include "SpineEditorPlugin.h"
#include "SpineAtlasResource.h" #include "SpineAtlasResource.h"
#include "SpineSkeletonFileResource.h" #include "SpineSkeletonFileResource.h"
@ -43,7 +42,11 @@ Error SpineAtlasResourceImportPlugin::import(const String &source_file, const St
return error; return error;
} }
#if VERSION_MAJOR > 3
void SpineAtlasResourceImportPlugin::get_import_options(const String &path, List<ImportOption> *options, int preset) const {
#else
void SpineAtlasResourceImportPlugin::get_import_options(List<ImportOption> *options, int preset) const { void SpineAtlasResourceImportPlugin::get_import_options(List<ImportOption> *options, int preset) const {
#endif
if (preset == 0) { if (preset == 0) {
ImportOption op; ImportOption op;
op.option.name = "normal_map_prefix"; op.option.name = "normal_map_prefix";
@ -79,15 +82,16 @@ SpineEditorPlugin::SpineEditorPlugin(EditorNode *node) {
add_inspector_plugin(memnew(SpineSkeletonDataResourceInspectorPlugin)); add_inspector_plugin(memnew(SpineSkeletonDataResourceInspectorPlugin));
} }
SpineEditorPlugin::~SpineEditorPlugin() {
}
bool SpineSkeletonDataResourceInspectorPlugin::can_handle(Object *object) { bool SpineSkeletonDataResourceInspectorPlugin::can_handle(Object *object) {
return object->is_class("SpineSkeletonDataResource"); return object->is_class("SpineSkeletonDataResource");
} }
#if VERSION_MAJOR > 3
bool SpineSkeletonDataResourceInspectorPlugin:: parse_property(Object *object, const Variant::Type type, const String &path, const PropertyHint hint, const String &hint_text, const uint32_t usage, const bool wide) {
#else
bool SpineSkeletonDataResourceInspectorPlugin::parse_property(Object *object, Variant::Type type, const String &path, bool SpineSkeletonDataResourceInspectorPlugin::parse_property(Object *object, Variant::Type type, const String &path,
PropertyHint hint, const String &hint_text, int usage) { PropertyHint hint, const String &hint_text, int usage) {
#endif
if (path == "animation_mixes") { if (path == "animation_mixes") {
Ref<SpineSkeletonDataResource> skeleton_data = Object::cast_to<SpineSkeletonDataResource>(object); Ref<SpineSkeletonDataResource> skeleton_data = Object::cast_to<SpineSkeletonDataResource>(object);
if (!skeleton_data.is_valid() || !skeleton_data->is_skeleton_data_loaded()) return true; if (!skeleton_data.is_valid() || !skeleton_data->is_skeleton_data_loaded()) return true;
@ -100,7 +104,7 @@ bool SpineSkeletonDataResourceInspectorPlugin::parse_property(Object *object, Va
} }
SpineEditorPropertyAnimationMixes::SpineEditorPropertyAnimationMixes(): skeleton_data(nullptr), container(nullptr), updating(false) { SpineEditorPropertyAnimationMixes::SpineEditorPropertyAnimationMixes(): skeleton_data(nullptr), container(nullptr), updating(false) {
array_object.instance(); INSTANTIATE(array_object);
} }
void SpineEditorPropertyAnimationMixes::_bind_methods() { void SpineEditorPropertyAnimationMixes::_bind_methods() {
@ -128,13 +132,17 @@ void SpineEditorPropertyAnimationMixes::delete_mix(int64_t idx) {
if (!skeleton_data.is_valid() || !skeleton_data->is_skeleton_data_loaded() || updating) return; if (!skeleton_data.is_valid() || !skeleton_data->is_skeleton_data_loaded() || updating) return;
auto mixes = skeleton_data->get_animation_mixes().duplicate(); auto mixes = skeleton_data->get_animation_mixes().duplicate();
mixes.remove(idx); #if VERSION_MAJOR > 3
mixes.remove_at((int)idx);
#else
mixes.remove((int)idx);
#endif
emit_changed(get_edited_property(), mixes); emit_changed(get_edited_property(), mixes);
} }
void SpineEditorPropertyAnimationMixes::update_mix_property(int64_t index) { void SpineEditorPropertyAnimationMixes::update_mix_property(int64_t index) {
if (index < 0 || index > mix_properties.size()) return; if (index < 0 || index > mix_properties.size()) return;
mix_properties[index]->update_property(); mix_properties[(int)index]->update_property();
} }
void SpineEditorPropertyAnimationMixes::update_property() { void SpineEditorPropertyAnimationMixes::update_property() {
@ -184,31 +192,39 @@ void SpineEditorPropertyAnimationMixes::update_property() {
auto delete_button = memnew(Button); auto delete_button = memnew(Button);
hbox->add_child(delete_button); hbox->add_child(delete_button);
delete_button->set_text("Remove"); delete_button->set_text("Remove");
#if VERSION_MAJOR > 3
delete_button->connect("pressed", callable_mp(this, &SpineEditorPropertyAnimationMixes::delete_mix), varray(i));
#else
delete_button->connect("pressed", this, "delete_mix", varray(i)); delete_button->connect("pressed", this, "delete_mix", varray(i));
#endif
} }
auto add_mix_button = memnew(Button); auto add_mix_button = memnew(Button);
add_mix_button->set_text("Add mix"); add_mix_button->set_text("Add mix");
#if VERSION_MAJOR > 3
add_mix_button->connect("pressed", callable_mp(this, &SpineEditorPropertyAnimationMixes::add_mix));
#else
add_mix_button->connect("pressed", this, "add_mix"); add_mix_button->connect("pressed", this, "add_mix");
#endif
container->add_child(add_mix_button); container->add_child(add_mix_button);
updating = false; updating = false;
} }
SpineEditorPropertyAnimationMix::SpineEditorPropertyAnimationMix(): skeleton_data(nullptr), container(nullptr), updating(false) { SpineEditorPropertyAnimationMix::SpineEditorPropertyAnimationMix(): mixes_property(nullptr), skeleton_data(nullptr), index(0), container(nullptr), updating(false) {
} }
void SpineEditorPropertyAnimationMix::setup(SpineEditorPropertyAnimationMixes *mixes_property, Ref<SpineSkeletonDataResource> skeleton_data, int index) { void SpineEditorPropertyAnimationMix::setup(SpineEditorPropertyAnimationMixes *_mixes_property, const Ref<SpineSkeletonDataResource> &_skeleton_data, int _index) {
this->mixes_property = mixes_property; this->mixes_property = _mixes_property;
this->skeleton_data = skeleton_data; this->skeleton_data = _skeleton_data;
this->index = index; this->index = _index;
} }
void SpineEditorPropertyAnimationMix::_bind_methods() { void SpineEditorPropertyAnimationMix::_bind_methods() {
ClassDB::bind_method(D_METHOD("data_changed"), &SpineEditorPropertyAnimationMix::data_changed); ClassDB::bind_method(D_METHOD("data_changed"), &SpineEditorPropertyAnimationMix::data_changed);
} }
void SpineEditorPropertyAnimationMix::data_changed(const String &property, Variant value, const String &name, bool changing) { void SpineEditorPropertyAnimationMix::data_changed(const String &property, const Variant &value, const String &name, bool changing) {
auto mix = Object::cast_to<SpineAnimationMix>(get_edited_object()->get(get_edited_property())); auto mix = Object::cast_to<SpineAnimationMix>(get_edited_object()->get(get_edited_property()));
UndoRedo *undo_redo = EditorNode::get_undo_redo(); UndoRedo *undo_redo = EditorNode::get_undo_redo();
@ -260,7 +276,11 @@ void SpineEditorPropertyAnimationMix::update_property() {
from_enum->setup(animation_names); from_enum->setup(animation_names);
from_enum->set_object_and_property(mix, "from"); from_enum->set_object_and_property(mix, "from");
from_enum->update_property(); from_enum->update_property();
#if VERSION_MAJOR > 3
from_enum->connect("property_changed", callable_mp(this, &SpineEditorPropertyAnimationMix::data_changed));
#else
from_enum->connect("property_changed", this, "data_changed"); from_enum->connect("property_changed", this, "data_changed");
#endif
container->add_child(from_enum); container->add_child(from_enum);
auto to_enum = memnew(EditorPropertyTextEnum); auto to_enum = memnew(EditorPropertyTextEnum);
@ -270,7 +290,11 @@ void SpineEditorPropertyAnimationMix::update_property() {
to_enum->setup(animation_names); to_enum->setup(animation_names);
to_enum->set_object_and_property(mix, "to"); to_enum->set_object_and_property(mix, "to");
to_enum->update_property(); to_enum->update_property();
#if VERSION_MAJOR > 3
to_enum->connect("property_changed", callable_mp(this, &SpineEditorPropertyAnimationMix::data_changed));
#else
to_enum->connect("property_changed", this, "data_changed"); to_enum->connect("property_changed", this, "data_changed");
#endif
container->add_child(to_enum); container->add_child(to_enum);
auto mix_float = memnew(EditorPropertyFloat); auto mix_float = memnew(EditorPropertyFloat);
@ -280,7 +304,11 @@ void SpineEditorPropertyAnimationMix::update_property() {
mix_float->setup(0, 9999999, 0.001, true, false, false, false); mix_float->setup(0, 9999999, 0.001, true, false, false, false);
mix_float->set_object_and_property(mix, "mix"); mix_float->set_object_and_property(mix, "mix");
mix_float->update_property(); mix_float->update_property();
#if VERSION_MAJOR > 3
mix_float->connect("property_changed", callable_mp(this, &SpineEditorPropertyAnimationMix::data_changed));
#else
mix_float->connect("property_changed", this, "data_changed"); mix_float->connect("property_changed", this, "data_changed");
#endif
container->add_child(mix_float); container->add_child(mix_float);
updating = false; updating = false;

View File

@ -29,12 +29,13 @@
#ifndef GODOT_SPINEEDITORPLUGIN_H #ifndef GODOT_SPINEEDITORPLUGIN_H
#define GODOT_SPINEEDITORPLUGIN_H #define GODOT_SPINEEDITORPLUGIN_H
#include "editor/editor_properties_array_dict.h"
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
#include "editor/editor_node.h" #include "SpineCommon.h"
#include "SpineSprite.h" #include "SpineSprite.h"
#include "editor/editor_node.h"
#include "editor/editor_properties.h" #include "editor/editor_properties.h"
#include "editor/editor_properties_array_dict.h"
class SpineAtlasResourceImportPlugin : public EditorImportPlugin { class SpineAtlasResourceImportPlugin : public EditorImportPlugin {
GDCLASS(SpineAtlasResourceImportPlugin, EditorImportPlugin) GDCLASS(SpineAtlasResourceImportPlugin, EditorImportPlugin)
@ -54,9 +55,17 @@ public:
String get_resource_type() const override { return "SpineAtlasResource"; } String get_resource_type() const override { return "SpineAtlasResource"; }
#if VERSION_MAJOR > 3
int get_import_order() const override { return IMPORT_ORDER_DEFAULT; }
void get_import_options(const String &path, List<ImportOption> *options, int preset) const override;
bool get_option_visibility(const String &path, const String &option, const Map<StringName, Variant> &options) const override { return true; }
#else
void get_import_options(List<ImportOption> *options, int preset) const override; void get_import_options(List<ImportOption> *options, int preset) const override;
bool get_option_visibility(const String &option, const Map<StringName, Variant> &options) const override { return true; } bool get_option_visibility(const String &option, const Map<StringName, Variant> &options) const override { return true; }
#endif
Error import(const String &source_file, const String &save_path, const Map<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) override; Error import(const String &source_file, const String &save_path, const Map<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) override;
}; };
@ -79,10 +88,17 @@ public:
String get_resource_type() const override { return "SpineSkeletonFileResource"; } String get_resource_type() const override { return "SpineSkeletonFileResource"; }
void get_import_options(List<ImportOption> *options, int preset) const override {} #if VERSION_MAJOR > 3
int get_import_order() const override { return IMPORT_ORDER_DEFAULT; }
void get_import_options(const String &path, List<ImportOption> *options, int preset) const override { }
bool get_option_visibility(const String &path, const String &option, const Map<StringName, Variant> &options) const override { return true; }
#else
void get_import_options(List<ImportOption> *options, int preset) const override { }
bool get_option_visibility(const String &option, const Map<StringName, Variant> &options) const override { return true; } bool get_option_visibility(const String &option, const Map<StringName, Variant> &options) const override { return true; }
#endif
Error import(const String &source_file, const String &save_path, const Map<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) override; Error import(const String &source_file, const String &save_path, const Map<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) override;
}; };
@ -104,10 +120,17 @@ public:
String get_resource_type() const override { return "SpineSkeletonFileResource"; } String get_resource_type() const override { return "SpineSkeletonFileResource"; }
void get_import_options(List<ImportOption> *options, int preset) const override {} #if VERSION_MAJOR > 3
int get_import_order() const override { return IMPORT_ORDER_DEFAULT; }
void get_import_options(const String &path, List<ImportOption> *options, int preset) const override { }
bool get_option_visibility(const String &path, const String &option, const Map<StringName, Variant> &options) const override { return true; }
#else
void get_import_options(List<ImportOption> *options, int preset) const override { }
bool get_option_visibility(const String &option, const Map<StringName, Variant> &options) const override { return true; } bool get_option_visibility(const String &option, const Map<StringName, Variant> &options) const override { return true; }
#endif
Error import(const String &source_file, const String &save_path, const Map<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) override; Error import(const String &source_file, const String &save_path, const Map<StringName, Variant> &options, List<String> *platform_variants, List<String> *gen_files, Variant *metadata) override;
}; };
@ -115,12 +138,9 @@ class SpineEditorPlugin : public EditorPlugin {
GDCLASS(SpineEditorPlugin, EditorPlugin) GDCLASS(SpineEditorPlugin, EditorPlugin)
public: public:
SpineEditorPlugin(EditorNode *node); explicit SpineEditorPlugin(EditorNode *node);
~SpineEditorPlugin();
String get_name() const override { return "SpineEditorPlugin"; } String get_name() const override { return "SpineEditorPlugin"; }
bool has_main_screen() const { return false; }
}; };
class SpineSkeletonDataResourceInspectorPlugin: public EditorInspectorPlugin { class SpineSkeletonDataResourceInspectorPlugin: public EditorInspectorPlugin {
@ -130,7 +150,11 @@ public:
SpineSkeletonDataResourceInspectorPlugin() = default; SpineSkeletonDataResourceInspectorPlugin() = default;
bool can_handle(Object *object) override; bool can_handle(Object *object) override;
#if VERSION_MAJOR > 3
bool parse_property(Object *object, Variant::Type type, const String &path, PropertyHint hint, const String &hint_text, uint32_t usage, bool wide) override;
#else
bool parse_property(Object *object, Variant::Type type, const String &path, PropertyHint hint, const String &hint_text, int usage) override; bool parse_property(Object *object, Variant::Type type, const String &path, PropertyHint hint, const String &hint_text, int usage) override;
#endif
}; };
class SpineEditorPropertyAnimationMix; class SpineEditorPropertyAnimationMix;
@ -150,8 +174,8 @@ class SpineEditorPropertyAnimationMixes: public EditorProperty {
void update_mix_property(int64_t index); void update_mix_property(int64_t index);
public: public:
SpineEditorPropertyAnimationMixes(); SpineEditorPropertyAnimationMixes();
void setup(Ref<SpineSkeletonDataResource> skeleton_data) { this->skeleton_data = skeleton_data; }; void setup(const Ref<SpineSkeletonDataResource> &_skeleton_data) { this->skeleton_data = _skeleton_data; };
virtual void update_property(); void update_property() override;
}; };
class SpineEditorPropertyAnimationMix: public EditorProperty { class SpineEditorPropertyAnimationMix: public EditorProperty {
@ -164,11 +188,11 @@ class SpineEditorPropertyAnimationMix: public EditorProperty {
bool updating; bool updating;
static void _bind_methods(); static void _bind_methods();
void data_changed(const String &property, Variant value, const String &name, bool changing); void data_changed(const String &property, const Variant &value, const String &name, bool changing);
public: public:
SpineEditorPropertyAnimationMix(); SpineEditorPropertyAnimationMix();
void setup(SpineEditorPropertyAnimationMixes *mixes_property, Ref<SpineSkeletonDataResource> skeleton_data, int index); void setup(SpineEditorPropertyAnimationMixes *mixes_property, const Ref<SpineSkeletonDataResource> &skeleton_data, int index);
virtual void update_property(); void update_property() override;
}; };
#endif #endif

View File

@ -28,8 +28,7 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineEvent.h" #include "SpineEvent.h"
#include <spine/Event.h> #include "SpineCommon.h"
#include "common.h"
void SpineEvent::_bind_methods() { void SpineEvent::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_data"), &SpineEvent::get_data); ClassDB::bind_method(D_METHOD("get_data"), &SpineEvent::get_data);
@ -49,9 +48,6 @@ void SpineEvent::_bind_methods() {
SpineEvent::SpineEvent() : event(nullptr) { SpineEvent::SpineEvent() : event(nullptr) {
} }
SpineEvent::~SpineEvent() {
}
Ref<SpineEventData> SpineEvent::get_data() { Ref<SpineEventData> SpineEvent::get_data() {
SPINE_CHECK(event, nullptr) SPINE_CHECK(event, nullptr)
Ref<SpineEventData> event_data(memnew(SpineEventData)); Ref<SpineEventData> event_data(memnew(SpineEventData));

View File

@ -30,12 +30,12 @@
#ifndef GODOT_SPINEEVENT_H #ifndef GODOT_SPINEEVENT_H
#define GODOT_SPINEEVENT_H #define GODOT_SPINEEVENT_H
#include "SpineCommon.h"
#include "SpineEventData.h" #include "SpineEventData.h"
#include "core/reference.h"
#include <spine/Event.h> #include <spine/Event.h>
class SpineEvent : public Reference { class SpineEvent : public REFCOUNTED {
GDCLASS(SpineEvent, Reference) GDCLASS(SpineEvent, REFCOUNTED)
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -45,7 +45,6 @@ private:
public: public:
SpineEvent(); SpineEvent();
~SpineEvent();
void set_spine_object(spine::Event *_event) { event = _event; } void set_spine_object(spine::Event *_event) { event = _event; }

View File

@ -28,7 +28,7 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineEventData.h" #include "SpineEventData.h"
#include "common.h" #include "SpineCommon.h"
void SpineEventData::_bind_methods() { void SpineEventData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_event_name"), &SpineEventData::get_event_name); ClassDB::bind_method(D_METHOD("get_event_name"), &SpineEventData::get_event_name);
@ -47,9 +47,6 @@ void SpineEventData::_bind_methods() {
SpineEventData::SpineEventData() : event_data(nullptr) { SpineEventData::SpineEventData() : event_data(nullptr) {
} }
SpineEventData::~SpineEventData() {
}
String SpineEventData::get_event_name() { String SpineEventData::get_event_name() {
SPINE_CHECK(event_data, "") SPINE_CHECK(event_data, "")
return event_data->getName().buffer(); return event_data->getName().buffer();

View File

@ -30,11 +30,11 @@
#ifndef GODOT_SPINEEVENTDATA_H #ifndef GODOT_SPINEEVENTDATA_H
#define GODOT_SPINEEVENTDATA_H #define GODOT_SPINEEVENTDATA_H
#include "core/reference.h" #include "SpineCommon.h"
#include <spine/EventData.h> #include <spine/EventData.h>
class SpineEventData : public Reference { class SpineEventData : public REFCOUNTED {
GDCLASS(SpineEventData, Reference); GDCLASS(SpineEventData, REFCOUNTED);
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -44,7 +44,6 @@ private:
public: public:
SpineEventData(); SpineEventData();
~SpineEventData();
void set_spine_object(spine::EventData *_event_data) { event_data = _event_data; } void set_spine_object(spine::EventData *_event_data) { event_data = _event_data; }

View File

@ -29,7 +29,7 @@
#include "SpineIkConstraint.h" #include "SpineIkConstraint.h"
#include "SpineBone.h" #include "SpineBone.h"
#include "common.h" #include "SpineCommon.h"
void SpineIkConstraint::_bind_methods() { void SpineIkConstraint::_bind_methods() {
ClassDB::bind_method(D_METHOD("update"), &SpineIkConstraint::update); ClassDB::bind_method(D_METHOD("update"), &SpineIkConstraint::update);
@ -55,9 +55,6 @@ void SpineIkConstraint::_bind_methods() {
SpineIkConstraint::SpineIkConstraint() : ik_constraint(nullptr) { SpineIkConstraint::SpineIkConstraint() : ik_constraint(nullptr) {
} }
SpineIkConstraint::~SpineIkConstraint() {
}
void SpineIkConstraint::update() { void SpineIkConstraint::update() {
SPINE_CHECK(ik_constraint,) SPINE_CHECK(ik_constraint,)
ik_constraint->update(); ik_constraint->update();
@ -154,7 +151,7 @@ void SpineIkConstraint::set_softness(float v) {
} }
bool SpineIkConstraint::is_active() { bool SpineIkConstraint::is_active() {
SPINE_CHECK(ik_constraint, nullptr) SPINE_CHECK(ik_constraint, false)
return ik_constraint->isActive(); return ik_constraint->isActive();
} }
void SpineIkConstraint::set_active(bool v) { void SpineIkConstraint::set_active(bool v) {

View File

@ -35,8 +35,8 @@
class SpineBone; class SpineBone;
class SpineIkConstraint : public Reference { class SpineIkConstraint : public REFCOUNTED {
GDCLASS(SpineIkConstraint, Reference); GDCLASS(SpineIkConstraint, REFCOUNTED);
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -46,7 +46,6 @@ private:
public: public:
SpineIkConstraint(); SpineIkConstraint();
~SpineIkConstraint();
void set_spine_object(spine::IkConstraint *_ik_constraint) { ik_constraint = _ik_constraint; } void set_spine_object(spine::IkConstraint *_ik_constraint) { ik_constraint = _ik_constraint; }

View File

@ -28,8 +28,7 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineIkConstraintData.h" #include "SpineIkConstraintData.h"
#include "SpineCommon.h"
#include "common.h"
void SpineIkConstraintData::_bind_methods() { void SpineIkConstraintData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_bones"), &SpineIkConstraintData::get_bones); ClassDB::bind_method(D_METHOD("get_bones"), &SpineIkConstraintData::get_bones);
@ -49,9 +48,6 @@ void SpineIkConstraintData::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_softness", "v"), &SpineIkConstraintData::set_softness); ClassDB::bind_method(D_METHOD("set_softness", "v"), &SpineIkConstraintData::set_softness);
} }
SpineIkConstraintData::SpineIkConstraintData() {}
SpineIkConstraintData::~SpineIkConstraintData() {}
Array SpineIkConstraintData::get_bones() { Array SpineIkConstraintData::get_bones() {
Array result; Array result;
SPINE_CHECK(constraint_data, result) SPINE_CHECK(constraint_data, result)

View File

@ -43,9 +43,6 @@ protected:
static void _bind_methods(); static void _bind_methods();
public: public:
SpineIkConstraintData();
~SpineIkConstraintData();
Array get_bones(); Array get_bones();
Ref<SpineBoneData> get_target(); Ref<SpineBoneData> get_target();

View File

@ -28,9 +28,10 @@
*****************************************************************************/ *****************************************************************************/
#include "SpinePathConstraint.h" #include "SpinePathConstraint.h"
#include "SpineBone.h"
#include "SpineCommon.h"
void SpinePathConstraint::_bind_methods() { void SpinePathConstraint::_bind_methods() {
// ClassDB::bind_method(D_METHOD("apply"), &SpinePathConstraint::apply);
ClassDB::bind_method(D_METHOD("update"), &SpinePathConstraint::update); ClassDB::bind_method(D_METHOD("update"), &SpinePathConstraint::update);
ClassDB::bind_method(D_METHOD("get_order"), &SpinePathConstraint::get_order); ClassDB::bind_method(D_METHOD("get_order"), &SpinePathConstraint::get_order);
ClassDB::bind_method(D_METHOD("get_position"), &SpinePathConstraint::get_position); ClassDB::bind_method(D_METHOD("get_position"), &SpinePathConstraint::get_position);
@ -51,95 +52,111 @@ void SpinePathConstraint::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_active", "v"), &SpinePathConstraint::set_active); ClassDB::bind_method(D_METHOD("set_active", "v"), &SpinePathConstraint::set_active);
} }
SpinePathConstraint::SpinePathConstraint() : path_constraint(NULL) {} SpinePathConstraint::SpinePathConstraint() : path_constraint(nullptr) {
SpinePathConstraint::~SpinePathConstraint() {} }
// void SpinePathConstraint::apply(){
// path_constraint->apply();
// }
void SpinePathConstraint::update() { void SpinePathConstraint::update() {
SPINE_CHECK(path_constraint,)
path_constraint->update(); path_constraint->update();
} }
int SpinePathConstraint::get_order() { int SpinePathConstraint::get_order() {
SPINE_CHECK(path_constraint, 0)
return path_constraint->getOrder(); return path_constraint->getOrder();
} }
float SpinePathConstraint::get_position() { float SpinePathConstraint::get_position() {
SPINE_CHECK(path_constraint, 0)
return path_constraint->getPosition(); return path_constraint->getPosition();
} }
void SpinePathConstraint::set_position(float v) { void SpinePathConstraint::set_position(float v) {
SPINE_CHECK(path_constraint,)
path_constraint->setPosition(v); path_constraint->setPosition(v);
} }
float SpinePathConstraint::get_spacing() { float SpinePathConstraint::get_spacing() {
SPINE_CHECK(path_constraint, 0)
return path_constraint->getSpacing(); return path_constraint->getSpacing();
} }
void SpinePathConstraint::set_spacing(float v) { void SpinePathConstraint::set_spacing(float v) {
SPINE_CHECK(path_constraint,)
path_constraint->setSpacing(v); path_constraint->setSpacing(v);
} }
float SpinePathConstraint::get_mix_rotate() { float SpinePathConstraint::get_mix_rotate() {
SPINE_CHECK(path_constraint, 0)
return path_constraint->getMixRotate(); return path_constraint->getMixRotate();
} }
void SpinePathConstraint::set_mix_rotate(float v) { void SpinePathConstraint::set_mix_rotate(float v) {
SPINE_CHECK(path_constraint,)
path_constraint->setMixRotate(v); path_constraint->setMixRotate(v);
} }
float SpinePathConstraint::get_mix_x() { float SpinePathConstraint::get_mix_x() {
SPINE_CHECK(path_constraint, 0)
return path_constraint->getMixX(); return path_constraint->getMixX();
} }
void SpinePathConstraint::set_mix_x(float v) { void SpinePathConstraint::set_mix_x(float v) {
SPINE_CHECK(path_constraint,)
path_constraint->setMixX(v); path_constraint->setMixX(v);
} }
float SpinePathConstraint::get_mix_y() { float SpinePathConstraint::get_mix_y() {
SPINE_CHECK(path_constraint, 0)
return path_constraint->getMixY(); return path_constraint->getMixY();
} }
void SpinePathConstraint::set_mix_y(float v) { void SpinePathConstraint::set_mix_y(float v) {
SPINE_CHECK(path_constraint,)
path_constraint->setMixY(v); path_constraint->setMixY(v);
} }
Array SpinePathConstraint::get_bones() { Array SpinePathConstraint::get_bones() {
auto &bs = path_constraint->getBones(); Array result;
Array gd_bs; SPINE_CHECK(path_constraint, result)
gd_bs.resize(bs.size()); auto &bones = path_constraint->getBones();
for (size_t i = 0; i < bs.size(); ++i) { result.resize((int)bones.size());
auto b = bs[i]; for (int i = 0; i < bones.size(); ++i) {
if (b == NULL) gd_bs[i] = Ref<SpineBone>(NULL); auto bone = bones[i];
Ref<SpineBone> gd_b(memnew(SpineBone)); Ref<SpineBone> bone_ref(memnew(SpineBone));
gd_b->set_spine_object(b); bone_ref->set_spine_object(bone);
gd_bs[i] = gd_b; result[i] = bone_ref;
} }
return gd_bs; return result;
} }
Ref<SpineSlot> SpinePathConstraint::get_target() { Ref<SpineSlot> SpinePathConstraint::get_target() {
auto s = path_constraint->getTarget(); SPINE_CHECK(path_constraint, nullptr)
if (s == NULL) return NULL; auto target = path_constraint->getTarget();
Ref<SpineSlot> gd_s(memnew(SpineSlot)); if (!target) return nullptr;
gd_s->set_spine_object(s); Ref<SpineSlot> target_ref(memnew(SpineSlot));
return gd_s; target_ref->set_spine_object(target);
return target_ref;
} }
void SpinePathConstraint::set_target(Ref<SpineSlot> v) { void SpinePathConstraint::set_target(Ref<SpineSlot> v) {
if (v.is_valid()) { SPINE_CHECK(path_constraint,)
path_constraint->setTarget(v->get_spine_object()); path_constraint->setTarget(v.is_valid() ? v->get_spine_object() : nullptr);
} else {
path_constraint->setTarget(NULL);
}
} }
Ref<SpinePathConstraintData> SpinePathConstraint::get_data() { Ref<SpinePathConstraintData> SpinePathConstraint::get_data() {
auto &sd = path_constraint->getData(); SPINE_CHECK(path_constraint, nullptr)
Ref<SpinePathConstraintData> gd_sd(memnew(SpinePathConstraintData)); auto &data = path_constraint->getData();
gd_sd->set_spine_object(&sd); Ref<SpinePathConstraintData> data_ref(memnew(SpinePathConstraintData));
return gd_sd; data_ref->set_spine_object(&data);
return data_ref;
} }
bool SpinePathConstraint::is_active() { bool SpinePathConstraint::is_active() {
SPINE_CHECK(path_constraint, false)
return path_constraint->isActive(); return path_constraint->isActive();
} }
void SpinePathConstraint::set_active(bool v) { void SpinePathConstraint::set_active(bool v) {
SPINE_CHECK(path_constraint,)
path_constraint->setActive(v); path_constraint->setActive(v);
} }

View File

@ -30,16 +30,12 @@
#ifndef GODOT_SPINEPATHCONSTRAINT_H #ifndef GODOT_SPINEPATHCONSTRAINT_H
#define GODOT_SPINEPATHCONSTRAINT_H #define GODOT_SPINEPATHCONSTRAINT_H
#include "core/variant_parser.h"
#include <spine/spine.h>
#include "SpineBone.h"
#include "SpineSlot.h"
#include "SpinePathConstraintData.h" #include "SpinePathConstraintData.h"
#include "SpineSlot.h"
#include <spine/PathConstraint.h>
class SpinePathConstraint : public Reference { class SpinePathConstraint : public REFCOUNTED {
GDCLASS(SpinePathConstraint, Reference); GDCLASS(SpinePathConstraint, REFCOUNTED);
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -49,45 +45,44 @@ private:
public: public:
SpinePathConstraint(); SpinePathConstraint();
~SpinePathConstraint();
inline void set_spine_object(spine::PathConstraint *pc) { void set_spine_object(spine::PathConstraint *_path_constraint) { path_constraint = _path_constraint; }
path_constraint = pc; spine::PathConstraint *get_spine_object() { return path_constraint; }
}
inline spine::PathConstraint *get_spine_object() {
return path_constraint;
}
// The spine-runtime-cpp 4.0 seems to not have a apply function implementation.
// void apply();
void update(); void update();
int get_order(); int get_order();
float get_position(); float get_position();
void set_position(float v); void set_position(float v);
float get_spacing(); float get_spacing();
void set_spacing(float v); void set_spacing(float v);
float get_mix_rotate(); float get_mix_rotate();
void set_mix_rotate(float v); void set_mix_rotate(float v);
float get_mix_x(); float get_mix_x();
void set_mix_x(float v); void set_mix_x(float v);
float get_mix_y(); float get_mix_y();
void set_mix_y(float v); void set_mix_y(float v);
Array get_bones(); Array get_bones();
Ref<SpineSlot> get_target(); Ref<SpineSlot> get_target();
void set_target(Ref<SpineSlot> v); void set_target(Ref<SpineSlot> v);
Ref<SpinePathConstraintData> get_data(); Ref<SpinePathConstraintData> get_data();
bool is_active(); bool is_active();
void set_active(bool v); void set_active(bool v);
}; };

View File

@ -28,141 +28,145 @@
*****************************************************************************/ *****************************************************************************/
#include "SpinePathConstraintData.h" #include "SpinePathConstraintData.h"
#include "SpineCommon.h"
void SpinePathConstraintData::_bind_methods() { void SpinePathConstraintData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_all_bone_data"), &SpinePathConstraintData::get_bones); ClassDB::bind_method(D_METHOD("get_bones"), &SpinePathConstraintData::get_bones);
ClassDB::bind_method(D_METHOD("get_target"), &SpinePathConstraintData::get_target); ClassDB::bind_method(D_METHOD("get_target"), &SpinePathConstraintData::get_target);
ClassDB::bind_method(D_METHOD("set_target", "V"), &SpinePathConstraintData::set_target); ClassDB::bind_method(D_METHOD("set_target", "v"), &SpinePathConstraintData::set_target);
ClassDB::bind_method(D_METHOD("get_position_mode"), &SpinePathConstraintData::get_position_mode); ClassDB::bind_method(D_METHOD("get_position_mode"), &SpinePathConstraintData::get_position_mode);
ClassDB::bind_method(D_METHOD("set_position_mode", "V"), &SpinePathConstraintData::set_position_mode); ClassDB::bind_method(D_METHOD("set_position_mode", "v"), &SpinePathConstraintData::set_position_mode);
ClassDB::bind_method(D_METHOD("get_spacing_mode"), &SpinePathConstraintData::get_spacing_mode); ClassDB::bind_method(D_METHOD("get_spacing_mode"), &SpinePathConstraintData::get_spacing_mode);
ClassDB::bind_method(D_METHOD("set_spacing_mode", "V"), &SpinePathConstraintData::set_spacing_mode); ClassDB::bind_method(D_METHOD("set_spacing_mode", "v"), &SpinePathConstraintData::set_spacing_mode);
ClassDB::bind_method(D_METHOD("get_rotate_mode"), &SpinePathConstraintData::get_rotate_mode); ClassDB::bind_method(D_METHOD("get_rotate_mode"), &SpinePathConstraintData::get_rotate_mode);
ClassDB::bind_method(D_METHOD("set_rotate_mode", "V"), &SpinePathConstraintData::set_rotate_mode); ClassDB::bind_method(D_METHOD("set_rotate_mode", "v"), &SpinePathConstraintData::set_rotate_mode);
ClassDB::bind_method(D_METHOD("get_offset_rotation"), &SpinePathConstraintData::get_offset_rotation); ClassDB::bind_method(D_METHOD("get_offset_rotation"), &SpinePathConstraintData::get_offset_rotation);
ClassDB::bind_method(D_METHOD("set_offset_rotation", "V"), &SpinePathConstraintData::set_offset_rotation); ClassDB::bind_method(D_METHOD("set_offset_rotation", "v"), &SpinePathConstraintData::set_offset_rotation);
ClassDB::bind_method(D_METHOD("get_position"), &SpinePathConstraintData::get_position); ClassDB::bind_method(D_METHOD("get_position"), &SpinePathConstraintData::get_position);
ClassDB::bind_method(D_METHOD("set_position", "V"), &SpinePathConstraintData::set_position); ClassDB::bind_method(D_METHOD("set_position", "v"), &SpinePathConstraintData::set_position);
ClassDB::bind_method(D_METHOD("get_spacing"), &SpinePathConstraintData::get_spacing); ClassDB::bind_method(D_METHOD("get_spacing"), &SpinePathConstraintData::get_spacing);
ClassDB::bind_method(D_METHOD("set_spacing", "V"), &SpinePathConstraintData::set_spacing); ClassDB::bind_method(D_METHOD("set_spacing", "v"), &SpinePathConstraintData::set_spacing);
ClassDB::bind_method(D_METHOD("get_mix_rotate"), &SpinePathConstraintData::get_mix_rotate); ClassDB::bind_method(D_METHOD("get_mix_rotate"), &SpinePathConstraintData::get_mix_rotate);
ClassDB::bind_method(D_METHOD("set_mix_rotate", "V"), &SpinePathConstraintData::set_mix_rotate); ClassDB::bind_method(D_METHOD("set_mix_rotate", "v"), &SpinePathConstraintData::set_mix_rotate);
ClassDB::bind_method(D_METHOD("get_mix_x"), &SpinePathConstraintData::get_mix_x); ClassDB::bind_method(D_METHOD("get_mix_x"), &SpinePathConstraintData::get_mix_x);
ClassDB::bind_method(D_METHOD("set_mix_x", "V"), &SpinePathConstraintData::set_mix_x); ClassDB::bind_method(D_METHOD("set_mix_x", "v"), &SpinePathConstraintData::set_mix_x);
ClassDB::bind_method(D_METHOD("get_mix_y"), &SpinePathConstraintData::get_mix_y); ClassDB::bind_method(D_METHOD("get_mix_y"), &SpinePathConstraintData::get_mix_y);
ClassDB::bind_method(D_METHOD("set_mix_y", "V"), &SpinePathConstraintData::set_mix_y); ClassDB::bind_method(D_METHOD("set_mix_y", "v"), &SpinePathConstraintData::set_mix_y);
BIND_ENUM_CONSTANT(POSITIONMODE_FIXED);
BIND_ENUM_CONSTANT(POSITIONMODE_PERCENT);
BIND_ENUM_CONSTANT(SPACINGMODE_LENGTH);
BIND_ENUM_CONSTANT(SPACINGMODE_FIXED);
BIND_ENUM_CONSTANT(SPACINGMODE_PERCENT);
BIND_ENUM_CONSTANT(ROTATEMODE_TANGENT);
BIND_ENUM_CONSTANT(ROTATEMODE_CHAIN);
BIND_ENUM_CONSTANT(ROTATEMODE_CHAINSCALE);
} }
SpinePathConstraintData::SpinePathConstraintData() {}
SpinePathConstraintData::~SpinePathConstraintData() {}
Array SpinePathConstraintData::get_bones() { Array SpinePathConstraintData::get_bones() {
auto bs = get_spine_constraint_data()->getBones(); Array result;
Array gd_bs; SPINE_CHECK(get_spine_constraint_data(), result)
gd_bs.resize(bs.size()); auto bones = get_spine_constraint_data()->getBones();
for (size_t i = 0; i < bs.size(); ++i) { result.resize((int)bones.size());
if (bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL); for (int i = 0; i < bones.size(); ++i) {
else { Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
Ref<SpineBoneData> gd_b(memnew(SpineBoneData)); bone_ref->set_spine_object(bones[i]);
gd_b->set_spine_object(bs[i]); result[i] = bone_ref;
gd_bs[i] = gd_b;
}
} }
return gd_bs; return result;
} }
Ref<SpineSlotData> SpinePathConstraintData::get_target() { Ref<SpineSlotData> SpinePathConstraintData::get_target() {
auto s = get_spine_constraint_data()->getTarget(); SPINE_CHECK(get_spine_constraint_data(), nullptr)
if (s == NULL) return NULL; auto slot = get_spine_constraint_data()->getTarget();
Ref<SpineSlotData> gd_s(memnew(SpineSlotData)); if (!slot) return nullptr;
gd_s->set_spine_object(s); Ref<SpineSlotData> slot_ref(memnew(SpineSlotData));
return gd_s; slot_ref->set_spine_object(slot);
return slot_ref;
} }
void SpinePathConstraintData::set_target(Ref<SpineSlotData> v) { void SpinePathConstraintData::set_target(Ref<SpineSlotData> v) {
if (v.is_valid()) { SPINE_CHECK(get_spine_constraint_data(),)
get_spine_constraint_data()->setTarget(v->get_spine_object()); get_spine_constraint_data()->setTarget(v.is_valid() ? v->get_spine_object() : nullptr);
} else {
get_spine_constraint_data()->setTarget(NULL);
}
} }
SpinePathConstraintData::PositionMode SpinePathConstraintData::get_position_mode() { SpineConstant::PositionMode SpinePathConstraintData::get_position_mode() {
auto m = (int) get_spine_constraint_data()->getPositionMode(); SPINE_CHECK(get_spine_constraint_data(), SpineConstant::PositionMode_Fixed)
return (PositionMode) m; return (SpineConstant::PositionMode) get_spine_constraint_data()->getPositionMode();
}
void SpinePathConstraintData::set_position_mode(PositionMode v) {
auto m = (int) v;
get_spine_constraint_data()->setPositionMode((spine::PositionMode) m);
} }
SpinePathConstraintData::SpacingMode SpinePathConstraintData::get_spacing_mode() { void SpinePathConstraintData::set_position_mode(SpineConstant::PositionMode v) {
auto m = (int) get_spine_constraint_data()->getSpacingMode(); SPINE_CHECK(get_spine_constraint_data(),)
return (SpacingMode) m; get_spine_constraint_data()->setPositionMode((spine::PositionMode)v);
}
void SpinePathConstraintData::set_spacing_mode(SpacingMode v) {
auto m = (int) v;
get_spine_constraint_data()->setSpacingMode((spine::SpacingMode) m);
} }
SpinePathConstraintData::RotateMode SpinePathConstraintData::get_rotate_mode() { SpineConstant::SpacingMode SpinePathConstraintData::get_spacing_mode() {
auto m = (int) get_spine_constraint_data()->getRotateMode(); SPINE_CHECK(get_spine_constraint_data(),SpineConstant::SpacingMode_Fixed)
return (RotateMode) m; return (SpineConstant::SpacingMode) get_spine_constraint_data()->getSpacingMode();
} }
void SpinePathConstraintData::set_rotate_mode(RotateMode v) {
auto m = (int) v; void SpinePathConstraintData::set_spacing_mode(SpineConstant::SpacingMode v) {
get_spine_constraint_data()->setRotateMode((spine::RotateMode) m); SPINE_CHECK(get_spine_constraint_data(),)
get_spine_constraint_data()->setSpacingMode((spine::SpacingMode) v);
}
SpineConstant::RotateMode SpinePathConstraintData::get_rotate_mode() {
SPINE_CHECK(get_spine_constraint_data(),SpineConstant::RotateMode_Tangent)
return (SpineConstant::RotateMode)get_spine_constraint_data()->getRotateMode();
}
void SpinePathConstraintData::set_rotate_mode(SpineConstant::RotateMode v) {
SPINE_CHECK(get_spine_constraint_data(),)
get_spine_constraint_data()->setRotateMode((spine::RotateMode) v);
} }
float SpinePathConstraintData::get_offset_rotation() { float SpinePathConstraintData::get_offset_rotation() {
SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getOffsetRotation(); return get_spine_constraint_data()->getOffsetRotation();
} }
void SpinePathConstraintData::set_offset_rotation(float v) { void SpinePathConstraintData::set_offset_rotation(float v) {
SPINE_CHECK(get_spine_constraint_data(),)
get_spine_constraint_data()->setOffsetRotation(v); get_spine_constraint_data()->setOffsetRotation(v);
} }
float SpinePathConstraintData::get_position() { float SpinePathConstraintData::get_position() {
SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getPosition(); return get_spine_constraint_data()->getPosition();
} }
void SpinePathConstraintData::set_position(float v) { void SpinePathConstraintData::set_position(float v) {
SPINE_CHECK(get_spine_constraint_data(),)
get_spine_constraint_data()->setPosition(v); get_spine_constraint_data()->setPosition(v);
} }
float SpinePathConstraintData::get_spacing() { float SpinePathConstraintData::get_spacing() {
SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getSpacing(); return get_spine_constraint_data()->getSpacing();
} }
void SpinePathConstraintData::set_spacing(float v) { void SpinePathConstraintData::set_spacing(float v) {
SPINE_CHECK(get_spine_constraint_data(),)
get_spine_constraint_data()->setSpacing(v); get_spine_constraint_data()->setSpacing(v);
} }
float SpinePathConstraintData::get_mix_rotate() { float SpinePathConstraintData::get_mix_rotate() {
SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getMixRotate(); return get_spine_constraint_data()->getMixRotate();
} }
void SpinePathConstraintData::set_mix_rotate(float v) { void SpinePathConstraintData::set_mix_rotate(float v) {
SPINE_CHECK(get_spine_constraint_data(),)
get_spine_constraint_data()->setMixRotate(v); get_spine_constraint_data()->setMixRotate(v);
} }
float SpinePathConstraintData::get_mix_x() { float SpinePathConstraintData::get_mix_x() {
SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getMixX(); return get_spine_constraint_data()->getMixX();
} }
void SpinePathConstraintData::set_mix_x(float v) { void SpinePathConstraintData::set_mix_x(float v) {
SPINE_CHECK(get_spine_constraint_data(),)
get_spine_constraint_data()->setMixX(v); get_spine_constraint_data()->setMixX(v);
} }
float SpinePathConstraintData::get_mix_y() { float SpinePathConstraintData::get_mix_y() {
SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getMixY(); return get_spine_constraint_data()->getMixY();
} }
void SpinePathConstraintData::set_mix_y(float v) { void SpinePathConstraintData::set_mix_y(float v) {
SPINE_CHECK(get_spine_constraint_data(),)
get_spine_constraint_data()->setMixY(v); get_spine_constraint_data()->setMixY(v);
} }

View File

@ -31,6 +31,7 @@
#define GODOT_SPINEPATHCONSTRAINTDATA_H #define GODOT_SPINEPATHCONSTRAINTDATA_H
#include "SpineConstraintData.h" #include "SpineConstraintData.h"
#include "SpineConstant.h"
#include "SpineBoneData.h" #include "SpineBoneData.h"
#include "SpineSlotData.h" #include "SpineSlotData.h"
#include <spine/PathConstraintData.h> #include <spine/PathConstraintData.h>
@ -44,60 +45,46 @@ protected:
static void _bind_methods(); static void _bind_methods();
public: public:
SpinePathConstraintData();
~SpinePathConstraintData();
enum PositionMode {
POSITIONMODE_FIXED = 0,
POSITIONMODE_PERCENT
};
enum SpacingMode {
SPACINGMODE_LENGTH = 0,
SPACINGMODE_FIXED,
SPACINGMODE_PERCENT
};
enum RotateMode {
ROTATEMODE_TANGENT = 0,
ROTATEMODE_CHAIN,
ROTATEMODE_CHAINSCALE
};
Array get_bones(); Array get_bones();
Ref<SpineSlotData> get_target(); Ref<SpineSlotData> get_target();
void set_target(Ref<SpineSlotData> v); void set_target(Ref<SpineSlotData> v);
PositionMode get_position_mode(); SpineConstant::PositionMode get_position_mode();
void set_position_mode(PositionMode v);
SpacingMode get_spacing_mode(); void set_position_mode(SpineConstant::PositionMode v);
void set_spacing_mode(SpacingMode v);
RotateMode get_rotate_mode(); SpineConstant::SpacingMode get_spacing_mode();
void set_rotate_mode(RotateMode v);
void set_spacing_mode(SpineConstant::SpacingMode v);
SpineConstant::RotateMode get_rotate_mode();
void set_rotate_mode(SpineConstant::RotateMode v);
float get_offset_rotation(); float get_offset_rotation();
void set_offset_rotation(float v); void set_offset_rotation(float v);
float get_position(); float get_position();
void set_position(float v); void set_position(float v);
float get_spacing(); float get_spacing();
void set_spacing(float v); void set_spacing(float v);
float get_mix_rotate(); float get_mix_rotate();
void set_mix_rotate(float v); void set_mix_rotate(float v);
float get_mix_x(); float get_mix_x();
void set_mix_x(float v); void set_mix_x(float v);
float get_mix_y(); float get_mix_y();
void set_mix_y(float v); void set_mix_y(float v);
}; };
VARIANT_ENUM_CAST(SpinePathConstraintData::PositionMode);
VARIANT_ENUM_CAST(SpinePathConstraintData::SpacingMode);
VARIANT_ENUM_CAST(SpinePathConstraintData::RotateMode);
#endif//GODOT_SPINEPATHCONSTRAINTDATA_H #endif//GODOT_SPINEPATHCONSTRAINTDATA_H

View File

@ -28,6 +28,7 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineSkeleton.h" #include "SpineSkeleton.h"
#include "SpineCommon.h"
void SpineSkeleton::_bind_methods() { void SpineSkeleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("update_world_transform"), &SpineSkeleton::update_world_transform); ClassDB::bind_method(D_METHOD("update_world_transform"), &SpineSkeleton::update_world_transform);
@ -49,14 +50,14 @@ void SpineSkeleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_data"), &SpineSkeleton::get_skeleton_data_res); ClassDB::bind_method(D_METHOD("get_data"), &SpineSkeleton::get_skeleton_data_res);
ClassDB::bind_method(D_METHOD("get_bones"), &SpineSkeleton::get_bones); ClassDB::bind_method(D_METHOD("get_bones"), &SpineSkeleton::get_bones);
ClassDB::bind_method(D_METHOD("get_slots"), &SpineSkeleton::get_slots); ClassDB::bind_method(D_METHOD("get_slots"), &SpineSkeleton::get_slots);
ClassDB::bind_method(D_METHOD("get_draw_orders"), &SpineSkeleton::get_draw_orders); ClassDB::bind_method(D_METHOD("get_draw_order"), &SpineSkeleton::get_draw_order);
ClassDB::bind_method(D_METHOD("get_ik_constraints"), &SpineSkeleton::get_ik_constraints); ClassDB::bind_method(D_METHOD("get_ik_constraints"), &SpineSkeleton::get_ik_constraints);
ClassDB::bind_method(D_METHOD("get_path_constraints"), &SpineSkeleton::get_path_constraints); ClassDB::bind_method(D_METHOD("get_path_constraints"), &SpineSkeleton::get_path_constraints);
ClassDB::bind_method(D_METHOD("get_transform_constraints"), &SpineSkeleton::get_transform_constraints); ClassDB::bind_method(D_METHOD("get_transform_constraints"), &SpineSkeleton::get_transform_constraints);
ClassDB::bind_method(D_METHOD("get_skin"), &SpineSkeleton::get_skin); ClassDB::bind_method(D_METHOD("get_skin"), &SpineSkeleton::get_skin);
ClassDB::bind_method(D_METHOD("get_color"), &SpineSkeleton::get_color); ClassDB::bind_method(D_METHOD("get_color"), &SpineSkeleton::get_color);
ClassDB::bind_method(D_METHOD("set_color", "v"), &SpineSkeleton::set_color); ClassDB::bind_method(D_METHOD("set_color", "v"), &SpineSkeleton::set_color);
ClassDB::bind_method(D_METHOD("set_position", "pos"), &SpineSkeleton::set_position); ClassDB::bind_method(D_METHOD("set_position", "position"), &SpineSkeleton::set_position);
ClassDB::bind_method(D_METHOD("get_x"), &SpineSkeleton::get_x); ClassDB::bind_method(D_METHOD("get_x"), &SpineSkeleton::get_x);
ClassDB::bind_method(D_METHOD("set_x", "v"), &SpineSkeleton::set_x); ClassDB::bind_method(D_METHOD("set_x", "v"), &SpineSkeleton::set_x);
ClassDB::bind_method(D_METHOD("get_y"), &SpineSkeleton::get_y); ClassDB::bind_method(D_METHOD("get_y"), &SpineSkeleton::get_y);
@ -86,30 +87,34 @@ Ref<SpineSkeletonDataResource> SpineSkeleton::get_skeleton_data_res() const {
return skeleton_data_res; return skeleton_data_res;
} }
void SpineSkeleton::set_spine_sprite(SpineSprite* sprite) { void SpineSkeleton::set_spine_sprite(SpineSprite* _sprite) {
this->sprite = sprite; this->sprite = _sprite;
} }
#define S_T(x) (spine::String((x).utf8()))
void SpineSkeleton::update_world_transform() { void SpineSkeleton::update_world_transform() {
SPINE_CHECK(skeleton,)
skeleton->updateWorldTransform(); skeleton->updateWorldTransform();
} }
void SpineSkeleton::set_to_setup_pose() { void SpineSkeleton::set_to_setup_pose() {
SPINE_CHECK(skeleton,)
skeleton->setToSetupPose(); skeleton->setToSetupPose();
} }
void SpineSkeleton::set_bones_to_setup_pose() { void SpineSkeleton::set_bones_to_setup_pose() {
SPINE_CHECK(skeleton,)
skeleton->setBonesToSetupPose(); skeleton->setBonesToSetupPose();
} }
void SpineSkeleton::set_slots_to_setup_pose() { void SpineSkeleton::set_slots_to_setup_pose() {
SPINE_CHECK(skeleton,)
skeleton->setSlotsToSetupPose(); skeleton->setSlotsToSetupPose();
} }
Ref<SpineBone> SpineSkeleton::find_bone(const String &name) { Ref<SpineBone> SpineSkeleton::find_bone(const String &name) {
if (name.empty()) return nullptr; SPINE_CHECK(skeleton, nullptr)
auto bone = skeleton->findBone(S_T(name)); if (EMPTY(name)) return nullptr;
auto bone = skeleton->findBone(SPINE_STRING(name));
if (!bone) return nullptr; if (!bone) return nullptr;
Ref<SpineBone> bone_ref(memnew(SpineBone)); Ref<SpineBone> bone_ref(memnew(SpineBone));
bone_ref->set_spine_object(bone); bone_ref->set_spine_object(bone);
@ -118,8 +123,9 @@ Ref<SpineBone> SpineSkeleton::find_bone(const String &name) {
} }
Ref<SpineSlot> SpineSkeleton::find_slot(const String &name) { Ref<SpineSlot> SpineSkeleton::find_slot(const String &name) {
if (name.empty()) return nullptr; SPINE_CHECK(skeleton, nullptr)
auto slot = skeleton->findSlot(S_T(name)); if (EMPTY(name)) return nullptr;
auto slot = skeleton->findSlot(SPINE_STRING(name));
if (!slot) return nullptr; if (!slot) return nullptr;
Ref<SpineSlot> slot_ref(memnew(SpineSlot)); Ref<SpineSlot> slot_ref(memnew(SpineSlot));
slot_ref->set_spine_object(slot); slot_ref->set_spine_object(slot);
@ -127,217 +133,231 @@ Ref<SpineSlot> SpineSkeleton::find_slot(const String &name) {
} }
void SpineSkeleton::set_skin_by_name(const String &skin_name) { void SpineSkeleton::set_skin_by_name(const String &skin_name) {
skeleton->setSkin(S_T(skin_name)); SPINE_CHECK(skeleton,)
skeleton->setSkin(SPINE_STRING(skin_name));
} }
void SpineSkeleton::set_skin(Ref<SpineSkin> new_skin) { void SpineSkeleton::set_skin(Ref<SpineSkin> new_skin) {
if (new_skin.is_valid()) SPINE_CHECK(skeleton,)
skeleton->setSkin(new_skin->get_spine_object()); skeleton->setSkin(new_skin.is_valid() ? new_skin->get_spine_object() : nullptr);
else
skeleton->setSkin(nullptr);
} }
Ref<SpineAttachment> SpineSkeleton::get_attachment_by_slot_name(const String &slot_name, const String &attachment_name) { Ref<SpineAttachment> SpineSkeleton::get_attachment_by_slot_name(const String &slot_name, const String &attachment_name) {
auto a = skeleton->getAttachment(S_T(slot_name), S_T(attachment_name)); SPINE_CHECK(skeleton, nullptr)
if (a == nullptr) return nullptr; auto attachment = skeleton->getAttachment(SPINE_STRING(slot_name), SPINE_STRING(attachment_name));
Ref<SpineAttachment> gd_a(memnew(SpineAttachment)); if (!attachment) return nullptr;
gd_a->set_spine_object(a); Ref<SpineAttachment> attachment_ref(memnew(SpineAttachment));
return gd_a; attachment_ref->set_spine_object(attachment);
return attachment_ref;
} }
Ref<SpineAttachment> SpineSkeleton::get_attachment_by_slot_index(int slot_index, const String &attachment_name) { Ref<SpineAttachment> SpineSkeleton::get_attachment_by_slot_index(int slot_index, const String &attachment_name) {
auto a = skeleton->getAttachment(slot_index, S_T(attachment_name)); SPINE_CHECK(skeleton, nullptr)
if (a == nullptr) return nullptr; auto attachment = skeleton->getAttachment(slot_index, SPINE_STRING(attachment_name));
Ref<SpineAttachment> gd_a(memnew(SpineAttachment)); if (!attachment) return nullptr;
gd_a->set_spine_object(a); Ref<SpineAttachment> attachment_ref(memnew(SpineAttachment));
return gd_a; attachment_ref->set_spine_object(attachment);
return attachment_ref;
} }
void SpineSkeleton::set_attachment(const String &slot_name, const String &attachment_name) { void SpineSkeleton::set_attachment(const String &slot_name, const String &attachment_name) {
ERR_FAIL_COND(slot_name.empty()); SPINE_CHECK(skeleton,)
ERR_FAIL_COND(get_attachment_by_slot_name(slot_name, attachment_name) == nullptr); skeleton->setAttachment(SPINE_STRING(slot_name), SPINE_STRING(attachment_name));
skeleton->setAttachment(S_T(slot_name), S_T(attachment_name));
} }
Ref<SpineIkConstraint> SpineSkeleton::find_ik_constraint(const String &constraint_name) { Ref<SpineIkConstraint> SpineSkeleton::find_ik_constraint(const String &constraint_name) {
if (constraint_name.empty()) return nullptr; SPINE_CHECK(skeleton, nullptr)
auto c = skeleton->findIkConstraint(S_T(constraint_name)); if (EMPTY(constraint_name)) return nullptr;
if (c == nullptr) return nullptr; auto constraint = skeleton->findIkConstraint(SPINE_STRING(constraint_name));
Ref<SpineIkConstraint> gd_c(memnew(SpineIkConstraint)); if (!constraint) return nullptr;
gd_c->set_spine_object(c); Ref<SpineIkConstraint> constraint_ref(memnew(SpineIkConstraint));
return gd_c; constraint_ref->set_spine_object(constraint);
return constraint_ref;
} }
Ref<SpineTransformConstraint> SpineSkeleton::find_transform_constraint(const String &constraint_name) { Ref<SpineTransformConstraint> SpineSkeleton::find_transform_constraint(const String &constraint_name) {
if (constraint_name.empty()) return nullptr; SPINE_CHECK(skeleton, nullptr)
auto c = skeleton->findTransformConstraint(S_T(constraint_name)); if (EMPTY(constraint_name)) return nullptr;
if (c == nullptr) return nullptr; auto constraint = skeleton->findTransformConstraint(SPINE_STRING(constraint_name));
Ref<SpineTransformConstraint> gd_c(memnew(SpineTransformConstraint)); if (!constraint) return nullptr;
gd_c->set_spine_object(c); Ref<SpineTransformConstraint> constraint_ref(memnew(SpineTransformConstraint));
return gd_c; constraint_ref->set_spine_object(constraint);
return constraint_ref;
} }
Ref<SpinePathConstraint> SpineSkeleton::find_path_constraint(const String &constraint_name) { Ref<SpinePathConstraint> SpineSkeleton::find_path_constraint(const String &constraint_name) {
if (constraint_name.empty()) return nullptr; SPINE_CHECK(skeleton, nullptr)
auto c = skeleton->findPathConstraint(S_T(constraint_name)); if (EMPTY(constraint_name)) return nullptr;
if (c == nullptr) return nullptr; auto constraint = skeleton->findPathConstraint(SPINE_STRING(constraint_name));
Ref<SpinePathConstraint> gd_c(memnew(SpinePathConstraint)); if (!constraint) return nullptr;
gd_c->set_spine_object(c); Ref<SpinePathConstraint> constraint_ref(memnew(SpinePathConstraint));
return gd_c; constraint_ref->set_spine_object(constraint);
return constraint_ref;
} }
Dictionary SpineSkeleton::get_bounds() { Rect2 SpineSkeleton::get_bounds() {
SPINE_CHECK(skeleton, Rect2(0, 0, 0, 0))
float x, y, w, h; float x, y, w, h;
spine::Vector<float> vertex_buffer; skeleton->getBounds(x, y, w, h, bounds_vertex_buffer);
skeleton->getBounds(x, y, w, h, vertex_buffer); return Rect2(x, y, w, h);
Dictionary res;
res["x"] = x;
res["y"] = y;
res["w"] = w;
res["h"] = h;
Array gd_a;
gd_a.resize(vertex_buffer.size());
for (size_t i = 0; i < gd_a.size(); ++i) {
gd_a[i] = vertex_buffer[i];
}
res["vertex_buffer"] = gd_a;
return res;
} }
Ref<SpineBone> SpineSkeleton::get_root_bone() { Ref<SpineBone> SpineSkeleton::get_root_bone() {
auto b = skeleton->getRootBone(); SPINE_CHECK(skeleton, nullptr)
if (b == nullptr) return nullptr; auto bone = skeleton->getRootBone();
Ref<SpineBone> gd_b(memnew(SpineBone)); if (!bone) return nullptr;
gd_b->set_spine_object(b); Ref<SpineBone> bone_ref(memnew(SpineBone));
gd_b->set_spine_sprite(sprite); bone_ref->set_spine_object(bone);
return gd_b; bone_ref->set_spine_sprite(sprite);
return bone_ref;
} }
Array SpineSkeleton::get_bones() { Array SpineSkeleton::get_bones() {
auto &as = skeleton->getBones(); Array result;
Array gd_as; SPINE_CHECK(skeleton, result)
gd_as.resize(as.size()); auto &bones = skeleton->getBones();
for (size_t i = 0; i < gd_as.size(); ++i) { result.resize((int)bones.size());
auto b = as[i]; for (int i = 0; i < result.size(); ++i) {
if (b == nullptr) gd_as[i] = Ref<SpineBone>(nullptr); auto bone = bones[i];
Ref<SpineBone> gd_a(memnew(SpineBone)); Ref<SpineBone> bone_ref(memnew(SpineBone));
gd_a->set_spine_object(b); bone_ref->set_spine_object(bone);
gd_a->set_spine_sprite(sprite); bone_ref->set_spine_sprite(sprite);
gd_as[i] = gd_a; result[i] = bone_ref;
} }
return gd_as; return result;
} }
Array SpineSkeleton::get_slots() { Array SpineSkeleton::get_slots() {
auto &as = skeleton->getSlots(); Array result;
Array gd_as; SPINE_CHECK(skeleton, result)
gd_as.resize(as.size()); auto &slots = skeleton->getSlots();
for (size_t i = 0; i < gd_as.size(); ++i) { result.resize((int)slots.size());
auto b = as[i]; for (int i = 0; i < result.size(); ++i) {
if (b == nullptr) gd_as[i] = Ref<SpineSlot>(nullptr); auto slot = slots[i];
Ref<SpineSlot> gd_a(memnew(SpineSlot)); Ref<SpineSlot> slot_ref(memnew(SpineSlot));
gd_a->set_spine_object(b); slot_ref->set_spine_object(slot);
gd_as[i] = gd_a; result[i] = slot_ref;
} }
return gd_as; return result;
} }
Array SpineSkeleton::get_draw_orders() {
auto &as = skeleton->getDrawOrder(); Array SpineSkeleton::get_draw_order() {
Array gd_as; Array result;
gd_as.resize(as.size()); SPINE_CHECK(skeleton, result)
for (size_t i = 0; i < gd_as.size(); ++i) { auto &slots = skeleton->getDrawOrder();
auto b = as[i]; result.resize((int)slots.size());
if (b == nullptr) gd_as[i] = Ref<SpineSlot>(nullptr); for (int i = 0; i < result.size(); ++i) {
Ref<SpineSlot> gd_a(memnew(SpineSlot)); auto slot = slots[i];
gd_a->set_spine_object(b); Ref<SpineSlot> slot_ref(memnew(SpineSlot));
gd_as[i] = gd_a; slot_ref->set_spine_object(slot);
result[i] = slot_ref;
} }
return gd_as; return result;
} }
Array SpineSkeleton::get_ik_constraints() { Array SpineSkeleton::get_ik_constraints() {
auto &as = skeleton->getIkConstraints(); Array result;
Array gd_as; SPINE_CHECK(skeleton, result)
gd_as.resize(as.size()); auto &constraints = skeleton->getIkConstraints();
for (size_t i = 0; i < gd_as.size(); ++i) { result.resize((int)constraints.size());
auto b = as[i]; for (int i = 0; i < result.size(); ++i) {
if (b == nullptr) gd_as[i] = Ref<SpineIkConstraint>(nullptr); auto constraint = constraints[i];
Ref<SpineIkConstraint> gd_a(memnew(SpineIkConstraint)); Ref<SpineIkConstraint> constraint_ref(memnew(SpineIkConstraint));
gd_a->set_spine_object(b); constraint_ref->set_spine_object(constraint);
gd_as[i] = gd_a; result[i] = constraint_ref;
} }
return gd_as; return result;
} }
Array SpineSkeleton::get_path_constraints() { Array SpineSkeleton::get_path_constraints() {
auto &as = skeleton->getPathConstraints(); Array result;
Array gd_as; SPINE_CHECK(skeleton, result)
gd_as.resize(as.size()); auto &constraints = skeleton->getPathConstraints();
for (size_t i = 0; i < gd_as.size(); ++i) { result.resize((int)constraints.size());
auto b = as[i]; for (int i = 0; i < result.size(); ++i) {
if (b == nullptr) gd_as[i] = Ref<SpinePathConstraint>(nullptr); auto constraint = constraints[i];
Ref<SpinePathConstraint> gd_a(memnew(SpinePathConstraint)); Ref<SpinePathConstraint> constraint_ref(memnew(SpinePathConstraint));
gd_a->set_spine_object(b); constraint_ref->set_spine_object(constraint);
gd_as[i] = gd_a; result[i] = constraint_ref;
} }
return gd_as; return result;
} }
Array SpineSkeleton::get_transform_constraints() { Array SpineSkeleton::get_transform_constraints() {
auto &as = skeleton->getTransformConstraints(); Array result;
Array gd_as; SPINE_CHECK(skeleton, result)
gd_as.resize(as.size()); auto &constraints = skeleton->getTransformConstraints();
for (size_t i = 0; i < gd_as.size(); ++i) { result.resize((int)constraints.size());
auto b = as[i]; for (int i = 0; i < result.size(); ++i) {
if (b == nullptr) gd_as[i] = Ref<SpineTransformConstraint>(nullptr); auto constraint = constraints[i];
Ref<SpineTransformConstraint> gd_a(memnew(SpineTransformConstraint)); Ref<SpineTransformConstraint> constraint_ref(memnew(SpineTransformConstraint));
gd_a->set_spine_object(b); constraint_ref->set_spine_object(constraint);
gd_as[i] = gd_a; result[i] = constraint_ref;
} }
return gd_as; return result;
} }
Ref<SpineSkin> SpineSkeleton::get_skin() { Ref<SpineSkin> SpineSkeleton::get_skin() {
auto s = skeleton->getSkin(); SPINE_CHECK(skeleton, nullptr)
if (s == nullptr) return nullptr; auto skin = skeleton->getSkin();
Ref<SpineSkin> gd_s(memnew(SpineSkin)); if (!skin) return nullptr;
gd_s->set_spine_object(s); Ref<SpineSkin> skin_ref(memnew(SpineSkin));
return gd_s; skin_ref->set_spine_object(skin);
return skin_ref;
} }
Color SpineSkeleton::get_color() { Color SpineSkeleton::get_color() {
auto &c = skeleton->getColor(); SPINE_CHECK(skeleton, Color(0, 0, 0, 0))
return Color(c.r, c.g, c.b, c.a); auto &color = skeleton->getColor();
} return Color(color.r, color.g, color.b, color.a);
void SpineSkeleton::set_color(Color v) {
auto &c = skeleton->getColor();
c.set(v.r, v.g, v.b, v.a);
} }
void SpineSkeleton::set_position(Vector2 pos) { void SpineSkeleton::set_color(Color v) {
skeleton->setPosition(pos.x, pos.y); SPINE_CHECK(skeleton,)
auto &color = skeleton->getColor();
color.set(v.r, v.g, v.b, v.a);
}
void SpineSkeleton::set_position(Vector2 position) {
SPINE_CHECK(skeleton,)
skeleton->setPosition(position.x, position.y);
} }
float SpineSkeleton::get_x() { float SpineSkeleton::get_x() {
SPINE_CHECK(skeleton, 0)
return skeleton->getX(); return skeleton->getX();
} }
void SpineSkeleton::set_x(float v) { void SpineSkeleton::set_x(float v) {
SPINE_CHECK(skeleton,)
skeleton->setX(v); skeleton->setX(v);
} }
float SpineSkeleton::get_y() { float SpineSkeleton::get_y() {
SPINE_CHECK(skeleton, 0)
return skeleton->getY(); return skeleton->getY();
} }
void SpineSkeleton::set_y(float v) { void SpineSkeleton::set_y(float v) {
SPINE_CHECK(skeleton,)
skeleton->setY(v); skeleton->setY(v);
} }
float SpineSkeleton::get_scale_x() { float SpineSkeleton::get_scale_x() {
SPINE_CHECK(skeleton, 1)
return skeleton->getScaleX(); return skeleton->getScaleX();
} }
void SpineSkeleton::set_scale_x(float v) { void SpineSkeleton::set_scale_x(float v) {
SPINE_CHECK(skeleton,)
skeleton->setScaleX(v); skeleton->setScaleX(v);
} }
float SpineSkeleton::get_scale_y() { float SpineSkeleton::get_scale_y() {
SPINE_CHECK(skeleton, 1)
return skeleton->getScaleY(); return skeleton->getScaleY();
} }
void SpineSkeleton::set_scale_y(float v) { void SpineSkeleton::set_scale_y(float v) {
SPINE_CHECK(skeleton,)
skeleton->setScaleY(v); skeleton->setScaleY(v);
} }

View File

@ -30,8 +30,7 @@
#ifndef GODOT_SPINESKELETON_H #ifndef GODOT_SPINESKELETON_H
#define GODOT_SPINESKELETON_H #define GODOT_SPINESKELETON_H
#include <spine/spine.h> #include "SpineCommon.h"
#include "SpineSkeletonDataResource.h" #include "SpineSkeletonDataResource.h"
#include "SpineBone.h" #include "SpineBone.h"
#include "SpineSlot.h" #include "SpineSlot.h"
@ -41,32 +40,37 @@
class SpineSprite; class SpineSprite;
class SpineSkeleton : public Reference { class SpineSkeleton : public REFCOUNTED {
GDCLASS(SpineSkeleton, Reference); GDCLASS(SpineSkeleton, REFCOUNTED);
friend class SpineBone;
friend class SpineSlot;
friend class SpineTimeline;
friend class SpineSprite;
friend class SpineAnimation;
friend class SpineAnimationState;
friend class SpineCollisionShapeProxy;
protected: protected:
static void _bind_methods(); static void _bind_methods();
void set_skeleton_data_res(Ref<SpineSkeletonDataResource> data_res);
Ref<SpineSkeletonDataResource> get_skeleton_data_res() const;
void set_spine_object(spine::Skeleton *s) { skeleton = s; }
spine::Skeleton *get_spine_object() { return skeleton; }
void set_spine_sprite(SpineSprite *sprite);
private: private:
spine::Skeleton *skeleton; spine::Skeleton *skeleton;
SpineSprite *sprite; SpineSprite *sprite;
Ref<SpineSkeletonDataResource> skeleton_data_res; Ref<SpineSkeletonDataResource> skeleton_data_res;
spine::Vector<float> bounds_vertex_buffer;
public: public:
SpineSkeleton(); SpineSkeleton();
~SpineSkeleton(); ~SpineSkeleton() override;
void set_skeleton_data_res(Ref<SpineSkeletonDataResource> data_res);
Ref<SpineSkeletonDataResource> get_skeleton_data_res() const;
inline void set_spine_object(spine::Skeleton *s) {
skeleton = s;
}
inline spine::Skeleton *get_spine_object() {
return skeleton;
}
void set_spine_sprite(SpineSprite *sprite);
void update_world_transform(); void update_world_transform();
@ -81,45 +85,59 @@ public:
Ref<SpineSlot> find_slot(const String &name); Ref<SpineSlot> find_slot(const String &name);
void set_skin_by_name(const String &skin_name); void set_skin_by_name(const String &skin_name);
void set_skin(Ref<SpineSkin> new_skin); void set_skin(Ref<SpineSkin> new_skin);
Ref<SpineAttachment> get_attachment_by_slot_name(const String &slot_name, const String &attachment_name); Ref<SpineAttachment> get_attachment_by_slot_name(const String &slot_name, const String &attachment_name);
Ref<SpineAttachment> get_attachment_by_slot_index(int slot_index, const String &attachment_name); Ref<SpineAttachment> get_attachment_by_slot_index(int slot_index, const String &attachment_name);
void set_attachment(const String &slot_name, const String &attachment_name); void set_attachment(const String &slot_name, const String &attachment_name);
Ref<SpineIkConstraint> find_ik_constraint(const String &constraint_name); Ref<SpineIkConstraint> find_ik_constraint(const String &constraint_name);
Ref<SpineTransformConstraint> find_transform_constraint(const String &constraint_name); Ref<SpineTransformConstraint> find_transform_constraint(const String &constraint_name);
Ref<SpinePathConstraint> find_path_constraint(const String &constraint_name); Ref<SpinePathConstraint> find_path_constraint(const String &constraint_name);
Dictionary get_bounds(); Rect2 get_bounds();
Ref<SpineBone> get_root_bone(); Ref<SpineBone> get_root_bone();
Array get_bones(); Array get_bones();
Array get_slots(); Array get_slots();
Array get_draw_orders();
Array get_draw_order();
Array get_ik_constraints(); Array get_ik_constraints();
Array get_path_constraints(); Array get_path_constraints();
Array get_transform_constraints(); Array get_transform_constraints();
Ref<SpineSkin> get_skin(); Ref<SpineSkin> get_skin();
Color get_color(); Color get_color();
void set_color(Color v); void set_color(Color v);
void set_position(Vector2 pos); void set_position(Vector2 position);
float get_x(); float get_x();
void set_x(float v); void set_x(float v);
float get_y(); float get_y();
void set_y(float v); void set_y(float v);
float get_scale_x(); float get_scale_x();
void set_scale_x(float v); void set_scale_x(float v);
float get_scale_y(); float get_scale_y();
void set_scale_y(float v); void set_scale_y(float v);
}; };

View File

@ -28,7 +28,7 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineSkeletonDataResource.h" #include "SpineSkeletonDataResource.h"
#include "SpineCommon.h"
#include "core/io/marshalls.h" #include "core/io/marshalls.h"
void SpineAnimationMix::_bind_methods() { void SpineAnimationMix::_bind_methods() {
@ -41,33 +41,34 @@ void SpineAnimationMix::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "from"), "set_from", "get_from"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "from"), "set_from", "get_from");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "to"), "set_to", "get_to"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "to"), "set_to", "get_to");
#if VERSION_MAJOR > 3
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "mix"), "set_mix", "get_mix");
#else
ADD_PROPERTY(PropertyInfo(Variant::REAL, "mix"), "set_mix", "get_mix"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "mix"), "set_mix", "get_mix");
#endif
} }
SpineAnimationMix::SpineAnimationMix(): from(""), to(""), mix(0) { SpineAnimationMix::SpineAnimationMix(): from(""), to(""), mix(0) {
} }
SpineAnimationMix::~SpineAnimationMix() { void SpineAnimationMix::set_from(const StringName &_from) {
} this->from = _from;
void SpineAnimationMix::set_from(const StringName &from) {
this->from = from;
} }
String SpineAnimationMix::get_from() { String SpineAnimationMix::get_from() {
return from; return from;
} }
void SpineAnimationMix::set_to(const StringName &to) { void SpineAnimationMix::set_to(const StringName &_to) {
this->to = to; this->to = _to;
} }
String SpineAnimationMix::get_to() { String SpineAnimationMix::get_to() {
return to; return to;
} }
void SpineAnimationMix::set_mix(float mix) { void SpineAnimationMix::set_mix(float _mix) {
this->mix = mix; this->mix = _mix;
} }
float SpineAnimationMix::get_mix() { float SpineAnimationMix::get_mix() {
@ -119,11 +120,15 @@ void SpineSkeletonDataResource::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "atlas_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineAtlasResource"), "set_atlas_res", "get_atlas_res"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "atlas_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineAtlasResource"), "set_atlas_res", "get_atlas_res");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skeleton_file_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineSkeletonFileResource"), "set_skeleton_file_res", "get_skeleton_file_res"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skeleton_file_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineSkeletonFileResource"), "set_skeleton_file_res", "get_skeleton_file_res");
#if VERSION_MAJOR > 3
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "default_mix"), "set_default_mix", "get_default_mix");
#else
ADD_PROPERTY(PropertyInfo(Variant::REAL, "default_mix"), "set_default_mix", "get_default_mix"); ADD_PROPERTY(PropertyInfo(Variant::REAL, "default_mix"), "set_default_mix", "get_default_mix");
#endif
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animation_mixes"), "set_animation_mixes", "get_animation_mixes"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "animation_mixes"), "set_animation_mixes", "get_animation_mixes");
} }
SpineSkeletonDataResource::SpineSkeletonDataResource() : skeleton_data(nullptr), animation_state_data(nullptr), default_mix(0) { SpineSkeletonDataResource::SpineSkeletonDataResource() : default_mix(0), skeleton_data(nullptr), animation_state_data(nullptr) {
} }
SpineSkeletonDataResource::~SpineSkeletonDataResource() { SpineSkeletonDataResource::~SpineSkeletonDataResource() {
@ -142,32 +147,32 @@ void SpineSkeletonDataResource::update_skeleton_data() {
} }
if (atlas_res.is_valid() && skeleton_file_res.is_valid()) { if (atlas_res.is_valid() && skeleton_file_res.is_valid()) {
load_res(atlas_res->get_spine_atlas(), skeleton_file_res->get_json(), skeleton_file_res->get_binary()); load_resources(atlas_res->get_spine_atlas(), skeleton_file_res->get_json(), skeleton_file_res->get_binary());
} }
emit_signal("skeleton_data_changed"); emit_signal("skeleton_data_changed");
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
property_list_changed_notify(); NOTIFY_PROPERTY_LIST_CHANGED();
#endif #endif
} }
void SpineSkeletonDataResource::load_res(spine::Atlas *atlas, const String &json, const Vector<uint8_t> &binary) { void SpineSkeletonDataResource::load_resources(spine::Atlas *atlas, const String &json, const Vector<uint8_t> &binary) {
if ((json.empty() && binary.empty()) || atlas == nullptr) return; if ((EMPTY(json) && EMPTY(binary)) || atlas == nullptr) return;
spine::SkeletonData *data; spine::SkeletonData *data;
if (!json.empty()) { if (!EMPTY(json)) {
spine::SkeletonJson skeletonJson(atlas); spine::SkeletonJson skeletonJson(atlas);
data = skeletonJson.readSkeletonData(json.utf8()); data = skeletonJson.readSkeletonData(json.utf8());
if (!data) { if (!data) {
print_error(String("Error while loading skeleton data: ") + get_path()); ERR_PRINT(String("Error while loading skeleton data: ") + get_path());
print_error(String("Error message: ") + skeletonJson.getError().buffer()); ERR_PRINT(String("Error message: ") + skeletonJson.getError().buffer());
return; return;
} }
} else { } else {
spine::SkeletonBinary skeletonBinary(atlas); spine::SkeletonBinary skeletonBinary(atlas);
data = skeletonBinary.readSkeletonData(binary.ptr(), binary.size()); data = skeletonBinary.readSkeletonData(binary.ptr(), binary.size());
if (!data) { if (!data) {
print_error(String("Error while loading skeleton data: ") + get_path()); ERR_PRINT(String("Error while loading skeleton data: ") + get_path());
print_error(String("Error message: ") + skeletonBinary.getError().buffer()); ERR_PRINT(String("Error message: ") + skeletonBinary.getError().buffer());
return; return;
} }
} }
@ -218,8 +223,8 @@ void SpineSkeletonDataResource::get_skin_names(Vector<String> &skin_names) const
} }
} }
void SpineSkeletonDataResource::set_default_mix(float default_mix) { void SpineSkeletonDataResource::set_default_mix(float _default_mix) {
this->default_mix = default_mix; this->default_mix = _default_mix;
update_mixes(); update_mixes();
} }
@ -227,16 +232,16 @@ float SpineSkeletonDataResource::get_default_mix() {
return default_mix; return default_mix;
} }
void SpineSkeletonDataResource::set_animation_mixes(Array animation_mixes) { void SpineSkeletonDataResource::set_animation_mixes(Array _animation_mixes) {
for (int i = 0; i < animation_mixes.size(); i++) { for (int i = 0; i < _animation_mixes.size(); i++) {
auto objectId = Object::cast_to<EncodedObjectAsID>(animation_mixes[0]); auto objectId = Object::cast_to<EncodedObjectAsID>(_animation_mixes[0]);
if (objectId) { if (objectId) {
ERR_PRINT("Live-editing of animation mixes is not supported."); ERR_PRINT("Live-editing of animation mixes is not supported.");
return; return;
} }
} }
this->animation_mixes = animation_mixes; this->animation_mixes = _animation_mixes;
update_mixes(); update_mixes();
} }
@ -264,18 +269,10 @@ void SpineSkeletonDataResource::update_mixes() {
} }
} }
#define CHECK(x) \
if (!is_skeleton_data_loaded()) { \
ERR_PRINT("skeleton data has not loaded yet!"); \
return x; \
}
#define S_T(x) (spine::String((x).utf8()))
Ref<SpineAnimation> SpineSkeletonDataResource::find_animation(const String &animation_name) const { Ref<SpineAnimation> SpineSkeletonDataResource::find_animation(const String &animation_name) const {
CHECK(nullptr) SPINE_CHECK(skeleton_data, nullptr)
if (animation_name.empty()) return nullptr; if (EMPTY(animation_name)) return nullptr;
auto animation = skeleton_data->findAnimation(S_T(animation_name)); auto animation = skeleton_data->findAnimation(SPINE_STRING(animation_name));
if (!animation) return nullptr; if (!animation) return nullptr;
Ref<SpineAnimation> animation_ref(memnew(SpineAnimation)); Ref<SpineAnimation> animation_ref(memnew(SpineAnimation));
animation_ref->set_spine_object(animation); animation_ref->set_spine_object(animation);
@ -283,67 +280,68 @@ Ref<SpineAnimation> SpineSkeletonDataResource::find_animation(const String &anim
} }
Ref<SpineBoneData> SpineSkeletonDataResource::find_bone(const String &bone_name) const { Ref<SpineBoneData> SpineSkeletonDataResource::find_bone(const String &bone_name) const {
CHECK(nullptr) SPINE_CHECK(skeleton_data, nullptr)
if (bone_name.empty()) return nullptr; if (EMPTY(bone_name)) return nullptr;
auto bone = skeleton_data->findBone(S_T(bone_name)); auto bone = skeleton_data->findBone(SPINE_STRING(bone_name));
if (bone == nullptr) return nullptr; if (!bone) return nullptr;
Ref<SpineBoneData> bone_ref(memnew(SpineBoneData)); Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
bone_ref->set_spine_object(bone); bone_ref->set_spine_object(bone);
return bone_ref; return bone_ref;
} }
Ref<SpineSlotData> SpineSkeletonDataResource::find_slot(const String &slot_name) const { Ref<SpineSlotData> SpineSkeletonDataResource::find_slot(const String &slot_name) const {
CHECK(nullptr) SPINE_CHECK(skeleton_data, nullptr)
if (slot_name.empty()) return nullptr; if (EMPTY(slot_name)) return nullptr;
auto slot = skeleton_data->findSlot(S_T(slot_name)); auto slot = skeleton_data->findSlot(SPINE_STRING(slot_name));
if (slot == nullptr) return nullptr; if (!slot) return nullptr;
Ref<SpineSlotData> slot_ref(memnew(SpineSlotData)); Ref<SpineSlotData> slot_ref(memnew(SpineSlotData));
slot_ref->set_spine_object(slot); slot_ref->set_spine_object(slot);
return slot_ref; return slot_ref;
} }
Ref<SpineSkin> SpineSkeletonDataResource::find_skin(const String &skin_name) const { Ref<SpineSkin> SpineSkeletonDataResource::find_skin(const String &skin_name) const {
CHECK(nullptr) SPINE_CHECK(skeleton_data, nullptr)
if (skin_name.empty()) return nullptr; if (EMPTY(skin_name)) return nullptr;
auto skin = skeleton_data->findSkin(S_T(skin_name)); auto skin = skeleton_data->findSkin(SPINE_STRING(skin_name));
if (skin == nullptr) return nullptr; if (!skin) return nullptr;
Ref<SpineSkin> skin_ref(memnew(SpineSkin)); Ref<SpineSkin> skin_ref(memnew(SpineSkin));
skin_ref->set_spine_object(skin); skin_ref->set_spine_object(skin);
return skin_ref; return skin_ref;
} }
Ref<SpineEventData> SpineSkeletonDataResource::find_event(const String &event_data_name) const { Ref<SpineEventData> SpineSkeletonDataResource::find_event(const String &event_data_name) const {
CHECK(nullptr) SPINE_CHECK(skeleton_data, nullptr)
if (event_data_name.empty()) return nullptr; if (EMPTY(event_data_name)) return nullptr;
auto event = skeleton_data->findEvent(S_T(event_data_name)); auto event = skeleton_data->findEvent(SPINE_STRING(event_data_name));
if (event == nullptr) return nullptr; if (!event) return nullptr;
Ref<SpineEventData> event_ref(memnew(SpineEventData)); Ref<SpineEventData> event_ref(memnew(SpineEventData));
event_ref->set_spine_object(event); event_ref->set_spine_object(event);
return event_ref; return event_ref;
} }
Ref<SpineIkConstraintData> SpineSkeletonDataResource::find_ik_constraint(const String &constraint_name) const { Ref<SpineIkConstraintData> SpineSkeletonDataResource::find_ik_constraint(const String &constraint_name) const {
CHECK(nullptr) SPINE_CHECK(skeleton_data, nullptr)
if (constraint_name.empty()) return nullptr; if (EMPTY(constraint_name)) return nullptr;
auto constraint = skeleton_data->findIkConstraint(S_T(constraint_name)); auto constraint = skeleton_data->findIkConstraint(SPINE_STRING(constraint_name));
if (constraint == nullptr) return nullptr; if (!constraint) return nullptr;
Ref<SpineIkConstraintData> constraint_ref(memnew(SpineIkConstraintData)); Ref<SpineIkConstraintData> constraint_ref(memnew(SpineIkConstraintData));
constraint_ref->set_spine_object(constraint); constraint_ref->set_spine_object(constraint);
return constraint_ref; return constraint_ref;
} }
Ref<SpineTransformConstraintData> SpineSkeletonDataResource::find_transform_constraint(const String &constraint_name) const { Ref<SpineTransformConstraintData> SpineSkeletonDataResource::find_transform_constraint(const String &constraint_name) const {
CHECK(nullptr) SPINE_CHECK(skeleton_data, nullptr)
if (constraint_name.empty()) return nullptr; if (EMPTY(constraint_name)) return nullptr;
auto constraint = skeleton_data->findTransformConstraint(S_T(constraint_name)); auto constraint = skeleton_data->findTransformConstraint(SPINE_STRING(constraint_name));
if (constraint == nullptr) return nullptr; if (!constraint) return nullptr;
Ref<SpineTransformConstraintData> constraint_ref(memnew(SpineTransformConstraintData)); Ref<SpineTransformConstraintData> constraint_ref(memnew(SpineTransformConstraintData));
constraint_ref->set_spine_object(constraint); constraint_ref->set_spine_object(constraint);
return constraint_ref; return constraint_ref;
} }
Ref<SpinePathConstraintData> SpineSkeletonDataResource::find_path_constraint(const String &constraint_name) const { Ref<SpinePathConstraintData> SpineSkeletonDataResource::find_path_constraint(const String &constraint_name) const {
CHECK(nullptr) SPINE_CHECK(skeleton_data, nullptr)
if (constraint_name.empty()) return nullptr; if (EMPTY(constraint_name)) return nullptr;
auto constraint = skeleton_data->findPathConstraint(S_T(constraint_name)); auto constraint = skeleton_data->findPathConstraint(SPINE_STRING(constraint_name));
if (constraint == nullptr) return nullptr; if (constraint == nullptr) return nullptr;
Ref<SpinePathConstraintData> constraint_ref(memnew(SpinePathConstraintData)); Ref<SpinePathConstraintData> constraint_ref(memnew(SpinePathConstraintData));
constraint_ref->set_spine_object(constraint); constraint_ref->set_spine_object(constraint);
@ -351,173 +349,170 @@ Ref<SpinePathConstraintData> SpineSkeletonDataResource::find_path_constraint(con
} }
String SpineSkeletonDataResource::get_skeleton_name() const{ String SpineSkeletonDataResource::get_skeleton_name() const{
CHECK("") SPINE_CHECK(skeleton_data, "")
return skeleton_data->getName().buffer(); return skeleton_data->getName().buffer();
} }
Array SpineSkeletonDataResource::get_bones() const { Array SpineSkeletonDataResource::get_bones() const {
Array bone_refs; Array result;
CHECK(bone_refs) SPINE_CHECK(skeleton_data, result)
auto bones = skeleton_data->getBones(); auto bones = skeleton_data->getBones();
bone_refs.resize((int)bones.size()); result.resize((int)bones.size());
for (int i = 0; i < bones.size(); ++i) { for (int i = 0; i < bones.size(); ++i) {
Ref<SpineBoneData> bone_ref(memnew(SpineBoneData)); Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
bone_ref->set_spine_object(bones[i]); bone_ref->set_spine_object(bones[i]);
bone_refs[i] = bone_ref; result[i] = bone_ref;
} }
return bone_refs; return result;
} }
Array SpineSkeletonDataResource::get_slots() const { Array SpineSkeletonDataResource::get_slots() const {
Array slot_refs; Array result;
CHECK(slot_refs) SPINE_CHECK(skeleton_data, result)
auto slots = skeleton_data->getSlots(); auto slots = skeleton_data->getSlots();
slot_refs.resize((int)slots.size()); result.resize((int)slots.size());
for (int i = 0; i < slots.size(); ++i) { for (int i = 0; i < slots.size(); ++i) {
Ref<SpineSlotData> slot_ref(memnew(SpineSlotData)); Ref<SpineSlotData> slot_ref(memnew(SpineSlotData));
slot_ref->set_spine_object(slots[i]); slot_ref->set_spine_object(slots[i]);
slot_refs[i] = slot_ref; result[i] = slot_ref;
} }
return slot_refs; return result;
} }
Array SpineSkeletonDataResource::get_skins() const { Array SpineSkeletonDataResource::get_skins() const {
Array skin_refs; Array result;
CHECK(skin_refs) SPINE_CHECK(skeleton_data, result)
auto skins = skeleton_data->getSkins(); auto skins = skeleton_data->getSkins();
skin_refs.resize((int)skins.size()); result.resize((int)skins.size());
for (int i = 0; i < skins.size(); ++i) { for (int i = 0; i < skins.size(); ++i) {
Ref<SpineSkin> skin_ref(memnew(SpineSkin)); Ref<SpineSkin> skin_ref(memnew(SpineSkin));
skin_ref->set_spine_object(skins[i]); skin_ref->set_spine_object(skins[i]);
skin_refs[i] = skin_ref; result[i] = skin_ref;
} }
return skin_refs; return result;
} }
Ref<SpineSkin> SpineSkeletonDataResource::get_default_skin() const { Ref<SpineSkin> SpineSkeletonDataResource::get_default_skin() const {
CHECK(nullptr) SPINE_CHECK(skeleton_data, nullptr)
auto skin = skeleton_data->getDefaultSkin(); auto skin = skeleton_data->getDefaultSkin();
if (skin == nullptr) return nullptr; if (skin) return nullptr;
Ref<SpineSkin> skin_ref(memnew(SpineSkin)); Ref<SpineSkin> skin_ref(memnew(SpineSkin));
skin_ref->set_spine_object(skin); skin_ref->set_spine_object(skin);
return skin_ref; return skin_ref;
} }
void SpineSkeletonDataResource::set_default_skin(Ref<SpineSkin> skin) { void SpineSkeletonDataResource::set_default_skin(Ref<SpineSkin> skin) {
CHECK() SPINE_CHECK(skeleton_data,)
if (skin.is_valid()) skeleton_data->setDefaultSkin(skin.is_valid() ? skin->get_spine_object() : nullptr);
skeleton_data->setDefaultSkin(skin->get_spine_object());
else
skeleton_data->setDefaultSkin(nullptr);
} }
Array SpineSkeletonDataResource::get_events() const { Array SpineSkeletonDataResource::get_events() const {
Array event_refs; Array result;
CHECK(event_refs) SPINE_CHECK(skeleton_data, result)
auto events = skeleton_data->getEvents(); auto events = skeleton_data->getEvents();
event_refs.resize((int)events.size()); result.resize((int)events.size());
for (int i = 0; i < events.size(); ++i) { for (int i = 0; i < events.size(); ++i) {
Ref<SpineEventData> event_ref(memnew(SpineEventData)); Ref<SpineEventData> event_ref(memnew(SpineEventData));
event_ref->set_spine_object(events[i]); event_ref->set_spine_object(events[i]);
event_refs[i] = event_ref; result[i] = event_ref;
} }
return event_refs; return result;
} }
Array SpineSkeletonDataResource::get_animations() const { Array SpineSkeletonDataResource::get_animations() const {
Array animation_refs; Array result;
CHECK(animation_refs) SPINE_CHECK(skeleton_data, result)
auto animations = skeleton_data->getAnimations(); auto animations = skeleton_data->getAnimations();
animation_refs.resize((int)animations.size()); result.resize((int)animations.size());
for (int i = 0; i < animations.size(); ++i) { for (int i = 0; i < animations.size(); ++i) {
Ref<SpineAnimation> animation_ref(memnew(SpineAnimation)); Ref<SpineAnimation> animation_ref(memnew(SpineAnimation));
animation_ref->set_spine_object(animations[i]); animation_ref->set_spine_object(animations[i]);
animation_refs[i] = animation_ref; result[i] = animation_ref;
} }
return animation_refs; return result;
} }
Array SpineSkeletonDataResource::get_ik_constraints() const { Array SpineSkeletonDataResource::get_ik_constraints() const {
Array constraint_refs; Array result;
CHECK(constraint_refs) SPINE_CHECK(skeleton_data, result)
auto constraints = skeleton_data->getIkConstraints(); auto constraints = skeleton_data->getIkConstraints();
constraint_refs.resize((int)constraints.size()); result.resize((int)constraints.size());
for (int i = 0; i < constraints.size(); ++i) { for (int i = 0; i < constraints.size(); ++i) {
Ref<SpineIkConstraintData> constraint_ref(memnew(SpineIkConstraintData)); Ref<SpineIkConstraintData> constraint_ref(memnew(SpineIkConstraintData));
constraint_ref->set_spine_object(constraints[i]); constraint_ref->set_spine_object(constraints[i]);
constraint_refs[i] = constraint_ref; result[i] = constraint_ref;
} }
return constraint_refs; return result;
} }
Array SpineSkeletonDataResource::get_transform_constraints() const { Array SpineSkeletonDataResource::get_transform_constraints() const {
Array constraint_refs; Array result;
CHECK(constraint_refs) SPINE_CHECK(skeleton_data, result)
auto constraints = skeleton_data->getTransformConstraints(); auto constraints = skeleton_data->getTransformConstraints();
constraint_refs.resize((int)constraints.size()); result.resize((int)constraints.size());
for (int i = 0; i < constraints.size(); ++i) { for (int i = 0; i < constraints.size(); ++i) {
Ref<SpineTransformConstraintData> constraint_ref(memnew(SpineTransformConstraintData)); Ref<SpineTransformConstraintData> constraint_ref(memnew(SpineTransformConstraintData));
constraint_ref->set_spine_object(constraints[i]); constraint_ref->set_spine_object(constraints[i]);
constraint_refs[i] = constraint_ref; result[i] = constraint_ref;
} }
return constraint_refs; return result;
} }
Array SpineSkeletonDataResource::get_path_constraints() const { Array SpineSkeletonDataResource::get_path_constraints() const {
Array constraint_refs; Array result;
CHECK(constraint_refs) SPINE_CHECK(skeleton_data, result)
auto constraints = skeleton_data->getPathConstraints(); auto constraints = skeleton_data->getPathConstraints();
constraint_refs.resize((int)constraints.size()); result.resize((int)constraints.size());
for (int i = 0; i < constraints.size(); ++i) { for (int i = 0; i < constraints.size(); ++i) {
Ref<SpinePathConstraintData> constraint_ref(memnew(SpinePathConstraintData)); Ref<SpinePathConstraintData> constraint_ref(memnew(SpinePathConstraintData));
constraint_ref->set_spine_object(constraints[i]); constraint_ref->set_spine_object(constraints[i]);
constraint_refs[i] = constraint_ref; result[i] = constraint_ref;
} }
return constraint_refs; return result;
} }
float SpineSkeletonDataResource::get_x() const{ float SpineSkeletonDataResource::get_x() const{
CHECK(0) SPINE_CHECK(skeleton_data, 0)
return skeleton_data->getX(); return skeleton_data->getX();
} }
float SpineSkeletonDataResource::get_y() const { float SpineSkeletonDataResource::get_y() const {
CHECK(0) SPINE_CHECK(skeleton_data, 0)
return skeleton_data->getY(); return skeleton_data->getY();
} }
float SpineSkeletonDataResource::get_width() const{ float SpineSkeletonDataResource::get_width() const{
CHECK(0) SPINE_CHECK(skeleton_data, 0)
return skeleton_data->getWidth(); return skeleton_data->getWidth();
} }
float SpineSkeletonDataResource::get_height() const { float SpineSkeletonDataResource::get_height() const {
CHECK(0) SPINE_CHECK(skeleton_data, 0)
return skeleton_data->getHeight(); return skeleton_data->getHeight();
} }
String SpineSkeletonDataResource::get_version() const { String SpineSkeletonDataResource::get_version() const {
CHECK("") SPINE_CHECK(skeleton_data, "")
return skeleton_data->getVersion().buffer(); return skeleton_data->getVersion().buffer();
} }
String SpineSkeletonDataResource::get_hash() const { String SpineSkeletonDataResource::get_hash() const {
CHECK("") SPINE_CHECK(skeleton_data, "")
return skeleton_data->getHash().buffer(); return skeleton_data->getHash().buffer();
} }
String SpineSkeletonDataResource::get_images_path() const { String SpineSkeletonDataResource::get_images_path() const {
CHECK("") SPINE_CHECK(skeleton_data, "")
return skeleton_data->getImagesPath().buffer(); return skeleton_data->getImagesPath().buffer();
} }
String SpineSkeletonDataResource::get_audio_path() const { String SpineSkeletonDataResource::get_audio_path() const {
CHECK("") SPINE_CHECK(skeleton_data, "")
return skeleton_data->getAudioPath().buffer(); return skeleton_data->getAudioPath().buffer();
} }
float SpineSkeletonDataResource::get_fps() const { float SpineSkeletonDataResource::get_fps() const {
CHECK(0) SPINE_CHECK(skeleton_data, 0)
return skeleton_data->getFps(); return skeleton_data->getFps();
} }
//

View File

@ -23,7 +23,6 @@ protected:
float mix; float mix;
public: public:
SpineAnimationMix(); SpineAnimationMix();
~SpineAnimationMix();
void set_from(const StringName &from); void set_from(const StringName &from);
@ -55,7 +54,7 @@ private:
void update_skeleton_data(); void update_skeleton_data();
void load_res(spine::Atlas *atlas, const String &json, const Vector<uint8_t> &binary); void load_resources(spine::Atlas *atlas, const String &json, const Vector<uint8_t> &binary);
public: public:
SpineSkeletonDataResource(); SpineSkeletonDataResource();
@ -69,9 +68,9 @@ public:
void set_skeleton_file_res(const Ref<SpineSkeletonFileResource> &skeleton_file); void set_skeleton_file_res(const Ref<SpineSkeletonFileResource> &skeleton_file);
Ref<SpineSkeletonFileResource> get_skeleton_file_res(); Ref<SpineSkeletonFileResource> get_skeleton_file_res();
inline spine::SkeletonData *get_skeleton_data() const { return skeleton_data; } spine::SkeletonData *get_skeleton_data() const { return skeleton_data; }
inline spine::AnimationStateData *get_animation_state_data() const { return animation_state_data; } spine::AnimationStateData *get_animation_state_data() const { return animation_state_data; }
void get_animation_names(Vector<String> &animation_names) const; void get_animation_names(Vector<String> &animation_names) const;

View File

@ -28,67 +28,80 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineSkeletonFileResource.h" #include "SpineSkeletonFileResource.h"
#if VERSION_MAJOR > 3
#include "core/io/file_access.h"
#else
#include "core/os/file_access.h"
#endif
void SpineSkeletonFileResource::_bind_methods() { void SpineSkeletonFileResource::_bind_methods() {
} }
Error SpineSkeletonFileResource::load_from_file(const String &p_path) { Error SpineSkeletonFileResource::load_from_file(const String &path) {
Error err; Error error;
if (path.ends_with("spjson"))
if (p_path.ends_with("spjson")) json = FileAccess::get_file_as_string(path, &error);
json = FileAccess::get_file_as_string(p_path, &err);
else else
binary = FileAccess::get_file_as_array(p_path, &err); binary = FileAccess::get_file_as_array(path, &error);
return err; return error;
} }
Error SpineSkeletonFileResource::save_to_file(const String &p_path) { Error SpineSkeletonFileResource::save_to_file(const String &path) {
Error err; Error error;
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); #if VERSION_MAJOR > 3
if (err != OK) { Ref<FileAccess> file = FileAccess::open(path, FileAccess::WRITE, &error);
if (error != OK) return error;
#else
FileAccess *file = FileAccess::open(path, FileAccess::WRITE, &error);
if (error != OK) {
if (file) file->close(); if (file) file->close();
return err; return error;
} }
#endif
if (!is_binary()) if (!is_binary())
file->store_string(json); file->store_string(json);
else else
file->store_buffer(binary.ptr(), binary.size()); file->store_buffer(binary.ptr(), binary.size());
#if VERSION_MAJOR > 3
file->flush();
#else
file->close(); file->close();
#endif
return OK; return OK;
} }
RES SpineSkeletonFileResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) { #if VERSION_MAJOR > 3
Ref<SpineSkeletonFileResource> skeleton = memnew(SpineSkeletonFileResource); RES SpineSkeletonFileResourceFormatLoader::load(const String &path, const String &original_path, Error *error, bool use_sub_threads, float *progress, CacheMode cache_mode) {
skeleton->load_from_file(p_path); #else
RES SpineSkeletonFileResourceFormatLoader::load(const String &path, const String &original_path, Error *error) {
if (r_error) { #endif
*r_error = OK; Ref<SpineSkeletonFileResource> skeleton_file = memnew(SpineSkeletonFileResource);
} skeleton_file->load_from_file(path);
return skeleton; if (error) *error = OK;
return skeleton_file;
} }
void SpineSkeletonFileResourceFormatLoader::get_recognized_extensions(List<String> *r_extensions) const { void SpineSkeletonFileResourceFormatLoader::get_recognized_extensions(List<String> *extensions) const {
r_extensions->push_back("spjson"); extensions->push_back("spjson");
r_extensions->push_back("spskel"); extensions->push_back("spskel");
} }
String SpineSkeletonFileResourceFormatLoader::get_resource_type(const String &p_path) const { String SpineSkeletonFileResourceFormatLoader::get_resource_type(const String &path) const {
return "SpineSkeletonFileResource"; return "SpineSkeletonFileResource";
} }
bool SpineSkeletonFileResourceFormatLoader::handles_type(const String &p_type) const { bool SpineSkeletonFileResourceFormatLoader::handles_type(const String &type) const {
return p_type == "SpineSkeletonFileResource" || ClassDB::is_parent_class(p_type, "SpineSkeletonFileResource"); return type == "SpineSkeletonFileResource" || ClassDB::is_parent_class(type, "SpineSkeletonFileResource");
} }
Error SpineSkeletonFileResourceFormatSaver::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
Ref<SpineSkeletonFileResource> res = p_resource.get_ref_ptr(); Error SpineSkeletonFileResourceFormatSaver::save(const String &path, const RES &resource, uint32_t flags) {
Error error = res->save_to_file(p_path); Ref<SpineSkeletonFileResource> res = resource;
Error error = res->save_to_file(path);
return error; return error;
} }
void SpineSkeletonFileResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { void SpineSkeletonFileResourceFormatSaver::get_recognized_extensions(const RES &resource, List<String> *p_extensions) const {
if (Object::cast_to<SpineSkeletonFileResource>(*p_resource)) { if (Object::cast_to<SpineSkeletonFileResource>(*resource)) {
p_extensions->push_back("spjson"); p_extensions->push_back("spjson");
p_extensions->push_back("spskel"); p_extensions->push_back("spskel");
} }

View File

@ -30,7 +30,7 @@
#ifndef GODOT_SPINESKELETONFILERESOURCE_H #ifndef GODOT_SPINESKELETONFILERESOURCE_H
#define GODOT_SPINESKELETONFILERESOURCE_H #define GODOT_SPINESKELETONFILERESOURCE_H
#include "core/variant_parser.h" #include "SpineCommon.h"
#include "core/io/resource_loader.h" #include "core/io/resource_loader.h"
#include "core/io/resource_saver.h" #include "core/io/resource_saver.h"
@ -44,30 +44,42 @@ protected:
Vector<uint8_t> binary; Vector<uint8_t> binary;
public: public:
inline const bool is_binary() { return !binary.empty(); } bool is_binary() { return binary.size() > 0; }
inline const Vector<uint8_t> &get_binary() { return binary; }
inline const String &get_json() { return json; }
Error load_from_file(const String &p_path); const Vector<uint8_t> &get_binary() { return binary; }
Error save_to_file(const String &p_path);
const String &get_json() { return json; }
Error load_from_file(const String &path);
Error save_to_file(const String &path);
}; };
class SpineSkeletonFileResourceFormatLoader : public ResourceFormatLoader { class SpineSkeletonFileResourceFormatLoader : public ResourceFormatLoader {
GDCLASS(SpineSkeletonFileResourceFormatLoader, ResourceFormatLoader); GDCLASS(SpineSkeletonFileResourceFormatLoader, ResourceFormatLoader);
public: public:
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL); #if VERSION_MAJOR > 3
virtual void get_recognized_extensions(List<String> *r_extensions) const; RES load(const String &path, const String &original_path, Error *error, bool use_sub_threads, float *progress, CacheMode cache_mode);
virtual bool handles_type(const String &p_type) const; #else
virtual String get_resource_type(const String &p_path) const; RES load(const String &path, const String &original_path, Error *error) override;
#endif
void get_recognized_extensions(List<String> *extensions) const override;
bool handles_type(const String &type) const override;
String get_resource_type(const String &path) const override;
}; };
class SpineSkeletonFileResourceFormatSaver : public ResourceFormatSaver { class SpineSkeletonFileResourceFormatSaver : public ResourceFormatSaver {
GDCLASS(SpineSkeletonFileResourceFormatSaver, ResourceFormatSaver); GDCLASS(SpineSkeletonFileResourceFormatSaver, ResourceFormatSaver);
public: public:
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override; Error save(const String &path, const RES &resource, uint32_t flags) override;
void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const override;
void get_recognized_extensions(const RES &resource, List<String> *p_extensions) const override;
bool recognize(const RES &p_resource) const override; bool recognize(const RES &p_resource) const override;
}; };

View File

@ -28,9 +28,9 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineSkin.h" #include "SpineSkin.h"
#include "SpineBoneData.h" #include "SpineBoneData.h"
#include "SpineConstraintData.h" #include "SpineConstraintData.h"
#include "SpineCommon.h"
void SpineSkin::_bind_methods() { void SpineSkin::_bind_methods() {
ClassDB::bind_method(D_METHOD("init", "name"), &SpineSkin::init); ClassDB::bind_method(D_METHOD("init", "name"), &SpineSkin::init);
@ -39,123 +39,164 @@ void SpineSkin::_bind_methods() {
ClassDB::bind_method(D_METHOD("remove_attachment", "slot_index", "name"), &SpineSkin::remove_attachment); ClassDB::bind_method(D_METHOD("remove_attachment", "slot_index", "name"), &SpineSkin::remove_attachment);
ClassDB::bind_method(D_METHOD("find_names_for_slot", "slot_index"), &SpineSkin::find_names_for_slot); ClassDB::bind_method(D_METHOD("find_names_for_slot", "slot_index"), &SpineSkin::find_names_for_slot);
ClassDB::bind_method(D_METHOD("find_attachments_for_slot", "slot_index"), &SpineSkin::find_attachments_for_slot); ClassDB::bind_method(D_METHOD("find_attachments_for_slot", "slot_index"), &SpineSkin::find_attachments_for_slot);
ClassDB::bind_method(D_METHOD("get_skin_name"), &SpineSkin::get_skin_name); ClassDB::bind_method(D_METHOD("get_name"), &SpineSkin::get_name);
ClassDB::bind_method(D_METHOD("add_skin", "other"), &SpineSkin::add_skin); ClassDB::bind_method(D_METHOD("add_skin", "other"), &SpineSkin::add_skin);
ClassDB::bind_method(D_METHOD("copy_skin", "other"), &SpineSkin::copy_skin); ClassDB::bind_method(D_METHOD("copy_skin", "other"), &SpineSkin::copy_skin);
ClassDB::bind_method(D_METHOD("get_attachments"), &SpineSkin::get_attachments); ClassDB::bind_method(D_METHOD("get_attachments"), &SpineSkin::get_attachments);
ClassDB::bind_method(D_METHOD("get_all_bone_data"), &SpineSkin::get_bones); ClassDB::bind_method(D_METHOD("get_bones"), &SpineSkin::get_bones);
ClassDB::bind_method(D_METHOD("get_all_constraint_data"), &SpineSkin::get_constraint); ClassDB::bind_method(D_METHOD("get_constraints"), &SpineSkin::get_constraints);
} }
SpineSkin::SpineSkin() : skin(NULL) {} SpineSkin::SpineSkin() : skin(nullptr), owns_skin(false) {
SpineSkin::~SpineSkin() {} }
SpineSkin::~SpineSkin() {
if (owns_skin) delete skin;
}
#define S_T(x) (spine::String(x.utf8()))
Ref<SpineSkin> SpineSkin::init(const String &name) { Ref<SpineSkin> SpineSkin::init(const String &name) {
skin = new spine::Skin(S_T(name)); if (skin) {
ERR_PRINT("Can not initialize an already initialized skin.");
return this;
}
owns_skin = true;
skin = new spine::Skin(SPINE_STRING(name));
return this; return this;
} }
void SpineSkin::set_attachment(uint64_t slot_index, const String &name, Ref<SpineAttachment> attachment) { void SpineSkin::set_attachment(uint64_t slot_index, const String &name, Ref<SpineAttachment> attachment) {
if (!attachment.is_valid()) { SPINE_CHECK(skin,)
ERR_PRINT("attachment is invalid!"); skin->setAttachment(slot_index, SPINE_STRING(name), attachment.is_valid() ? attachment->get_spine_object() : nullptr);
return;
}
skin->setAttachment(slot_index, S_T(name), attachment->get_spine_object());
} }
Ref<SpineAttachment> SpineSkin::get_attachment(uint64_t slot_index, const String &name) { Ref<SpineAttachment> SpineSkin::get_attachment(uint64_t slot_index, const String &name) {
auto a = skin->getAttachment(slot_index, S_T(name)); SPINE_CHECK(skin, nullptr)
if (a == NULL) return NULL; auto attachment = skin->getAttachment(slot_index, SPINE_STRING(name));
Ref<SpineAttachment> gd_attachment(memnew(SpineAttachment)); if (attachment) return nullptr;
gd_attachment->set_spine_object(a); Ref<SpineAttachment> attachment_ref(memnew(SpineAttachment));
return gd_attachment; attachment_ref->set_spine_object(attachment);
return attachment_ref;
} }
void SpineSkin::remove_attachment(uint64_t slot_index, const String &name) { void SpineSkin::remove_attachment(uint64_t slot_index, const String &name) {
skin->removeAttachment(slot_index, S_T(name)); SPINE_CHECK(skin,)
skin->removeAttachment(slot_index, SPINE_STRING(name));
} }
Array SpineSkin::find_names_for_slot(uint64_t slot_index) { Array SpineSkin::find_names_for_slot(uint64_t slot_index) {
Array result;
SPINE_CHECK(skin, result)
spine::Vector<spine::String> names; spine::Vector<spine::String> names;
skin->findNamesForSlot(slot_index, names); skin->findNamesForSlot(slot_index, names);
Array gd_names; result.resize((int)names.size());
gd_names.resize(names.size()); for (int i = 0; i < names.size(); ++i) {
for (size_t i = 0; i < names.size(); ++i) { result[i] = names[i].buffer();
gd_names[i] = names[i].buffer();
} }
return gd_names; return result;
} }
Array SpineSkin::find_attachments_for_slot(uint64_t slot_index) { Array SpineSkin::find_attachments_for_slot(uint64_t slot_index) {
spine::Vector<spine::Attachment *> as; Array result;
skin->findAttachmentsForSlot(slot_index, as); SPINE_CHECK(skin, result)
Array gd_as; spine::Vector<spine::Attachment *> attachments;
gd_as.resize(as.size()); skin->findAttachmentsForSlot(slot_index, attachments);
for (size_t i = 0; i < as.size(); ++i) { result.resize((int)attachments.size());
if (as[i] == NULL) gd_as[i] = Ref<SpineAttachment>(NULL); for (int i = 0; i < attachments.size(); ++i) {
else { if (!attachments[i]) {
Ref<SpineAttachment> gd_a(memnew(SpineAttachment)); result[i] = Ref<SpineAttachment>(nullptr);
gd_a->set_spine_object(as[i]); } else {
gd_as[i] = gd_a; Ref<SpineAttachment> attachment_ref(memnew(SpineAttachment));
attachment_ref->set_spine_object(attachments[i]);
result[i] = attachment_ref;
} }
} }
return gd_as; return result;
} }
String SpineSkin::get_skin_name() { String SpineSkin::get_name() {
SPINE_CHECK(skin, "")
return skin->getName().buffer(); return skin->getName().buffer();
} }
void SpineSkin::add_skin(Ref<SpineSkin> other) { void SpineSkin::add_skin(Ref<SpineSkin> other) {
if (other.is_valid() && other->get_spine_object()) { SPINE_CHECK(skin,)
skin->addSkin(other->get_spine_object()); if (!other.is_valid() || !other->get_spine_object()) {
} else { ERR_PRINT("other is not a valid SpineSkin.");
ERR_PRINT("other is NULL!"); return;
} }
skin->addSkin(other->get_spine_object());
} }
void SpineSkin::copy_skin(Ref<SpineSkin> other) { void SpineSkin::copy_skin(Ref<SpineSkin> other) {
if (other.is_valid() && other->get_spine_object()) { SPINE_CHECK(skin,)
skin->copySkin(other->get_spine_object()); if (!other.is_valid() || !other->get_spine_object()) {
} else { ERR_PRINT("other is not a valid SpineSkin.");
ERR_PRINT("other is NULL!"); return;
} }
skin->copySkin(other->get_spine_object());
} }
Ref<SpineSkinAttachmentMapEntries> SpineSkin::get_attachments() { Array SpineSkin::get_attachments() {
auto *es = new spine::Skin::AttachmentMap::Entries(skin->getAttachments()); Array result;
Ref<SpineSkinAttachmentMapEntries> gd_es(memnew(SpineSkinAttachmentMapEntries)); SPINE_CHECK(skin, result)
gd_es->set_spine_object(es); auto entries = skin->getAttachments();
return gd_es; while(entries.hasNext()) {
spine::Skin::AttachmentMap::Entry &entry = entries.next();
Ref<SpineSkinEntry> entry_ref = memnew(SpineSkinEntry);
Ref<SpineAttachment> attachment_ref = nullptr;
if (entry._attachment) {
attachment_ref = Ref<SpineAttachment>(memnew(SpineAttachment));
attachment_ref->set_spine_object(entry._attachment);
}
entry_ref->init(entry._slotIndex, entry._name.buffer(), attachment_ref);
result.push_back(entry_ref);
}
return result;
} }
Array SpineSkin::get_bones() { Array SpineSkin::get_bones() {
auto bs = skin->getBones(); Array result;
Array gd_bs; SPINE_CHECK(skin, result)
gd_bs.resize(bs.size()); auto bones = skin->getBones();
for (size_t i = 0; i < bs.size(); ++i) { result.resize((int)bones.size());
if (bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL); for (int i = 0; i < bones.size(); ++i) {
else { Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
Ref<SpineBoneData> gd_b(memnew(SpineBoneData)); bone_ref->set_spine_object(bones[i]);
gd_b->set_spine_object(bs[i]); result[i] = bone_ref;
gd_bs[i] = gd_b;
}
} }
return gd_bs; return result;
} }
Array SpineSkin::get_constraint() { Array SpineSkin::get_constraints() {
auto cs = skin->getConstraints(); Array result;
Array gd_cs; SPINE_CHECK(skin, result)
gd_cs.resize(cs.size()); auto constraints = skin->getConstraints();
for (size_t i = 0; i < cs.size(); ++i) { result.resize((int)constraints.size());
if (cs[i] == NULL) gd_cs[i] = Ref<SpineConstraintData>(NULL); for (int i = 0; i < constraints.size(); ++i) {
else { Ref<SpineConstraintData> constraint_ref(memnew(SpineConstraintData));
Ref<SpineConstraintData> gd_c(memnew(SpineConstraintData)); constraint_ref->set_spine_object(constraints[i]);
gd_c->set_spine_object(cs[i]); result[i] = constraint_ref;
gd_cs[i] = gd_c;
}
} }
return gd_cs; return result;
}
void SpineSkinEntry::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_slot_index"), &SpineSkinEntry::get_slot_index);
ClassDB::bind_method(D_METHOD("get_name"), &SpineSkinEntry::get_name);
ClassDB::bind_method(D_METHOD("get_attachment"), &SpineSkinEntry::get_attachment);
}
SpineSkinEntry::SpineSkinEntry() : slot_index(0) {
}
int SpineSkinEntry::get_slot_index() {
return slot_index;
}
const String &SpineSkinEntry::get_name() {
return name;
}
Ref<SpineAttachment> SpineSkinEntry::get_attachment() {
return attachment;
} }

View File

@ -30,32 +30,25 @@
#ifndef GODOT_SPINESKIN_H #ifndef GODOT_SPINESKIN_H
#define GODOT_SPINESKIN_H #define GODOT_SPINESKIN_H
#include "core/variant_parser.h" #include "SpineCommon.h"
#include <spine/spine.h>
#include "SpineAttachment.h" #include "SpineAttachment.h"
#include "SpineSkinAttachmentMapEntries.h"
class SpineSkin : public Reference { class SpineSkin : public REFCOUNTED {
GDCLASS(SpineSkin, Reference); GDCLASS(SpineSkin, REFCOUNTED);
protected: protected:
static void _bind_methods(); static void _bind_methods();
private: private:
spine::Skin *skin; spine::Skin *skin;
bool owns_skin;
public: public:
SpineSkin(); SpineSkin();
~SpineSkin(); ~SpineSkin() override;
inline void set_spine_object(spine::Skin *s) { void set_spine_object(spine::Skin *s) { skin = s; }
skin = s; spine::Skin *get_spine_object() { return skin; }
}
spine::Skin *get_spine_object() {
return skin;
}
Ref<SpineSkin> init(const String &name); Ref<SpineSkin> init(const String &name);
@ -69,17 +62,45 @@ public:
Array find_attachments_for_slot(uint64_t slot_index); Array find_attachments_for_slot(uint64_t slot_index);
String get_skin_name(); String get_name();
void add_skin(Ref<SpineSkin> other); void add_skin(Ref<SpineSkin> other);
void copy_skin(Ref<SpineSkin> other); void copy_skin(Ref<SpineSkin> other);
Ref<SpineSkinAttachmentMapEntries> get_attachments(); Array get_attachments();
Array get_bones(); Array get_bones();
Array get_constraint(); Array get_constraints();
};
class SpineSkinEntry : public REFCOUNTED {
GDCLASS(SpineSkinEntry, REFCOUNTED);
friend class SpineSkin;
protected:
static void _bind_methods();
void init(int _slot_index, const String &_name, Ref<SpineAttachment> _attachment) {
this->slot_index = _slot_index;
this->name = _name;
this->attachment = _attachment;
}
private:
int slot_index;
String name;
Ref<SpineAttachment> attachment;
public:
SpineSkinEntry();
int get_slot_index();
const String &get_name();
Ref<SpineAttachment> get_attachment();
}; };
#endif//GODOT_SPINESKIN_H #endif//GODOT_SPINESKIN_H

View File

@ -1,93 +0,0 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#include "SpineSkinAttachmentMapEntries.h"
void SpineSkinAttachmentMapEntry::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_slot_index"), &SpineSkinAttachmentMapEntry::get_slot_index);
ClassDB::bind_method(D_METHOD("set_slot_index", "v"), &SpineSkinAttachmentMapEntry::set_slot_index);
ClassDB::bind_method(D_METHOD("get_entry_name"), &SpineSkinAttachmentMapEntry::get_entry_name);
ClassDB::bind_method(D_METHOD("set_entry_name", "v"), &SpineSkinAttachmentMapEntry::set_entry_name);
ClassDB::bind_method(D_METHOD("get_attachment"), &SpineSkinAttachmentMapEntry::get_attachment);
ClassDB::bind_method(D_METHOD("set_attachment", "v"), &SpineSkinAttachmentMapEntry::set_attachment);
}
SpineSkinAttachmentMapEntry::SpineSkinAttachmentMapEntry() : entry(NULL) {}
SpineSkinAttachmentMapEntry::~SpineSkinAttachmentMapEntry() {}
uint64_t SpineSkinAttachmentMapEntry::get_slot_index() {
return entry->_slotIndex;
}
void SpineSkinAttachmentMapEntry::set_slot_index(uint64_t v) {
entry->_slotIndex = v;
}
String SpineSkinAttachmentMapEntry::get_entry_name() {
return entry->_name.buffer();
}
void SpineSkinAttachmentMapEntry::set_entry_name(const String &v) {
entry->_name = spine::String(v.utf8());
}
Ref<SpineAttachment> SpineSkinAttachmentMapEntry::get_attachment() {
if (entry->_attachment == NULL) return NULL;
Ref<SpineAttachment> gd_attachment(memnew(SpineAttachment));
gd_attachment->set_spine_object(entry->_attachment);
return gd_attachment;
}
void SpineSkinAttachmentMapEntry::set_attachment(Ref<SpineAttachment> v) {
if (v.is_valid()) {
entry->_attachment = v->get_spine_object();
} else {
entry->_attachment = NULL;
}
}
void SpineSkinAttachmentMapEntries::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_next"), &SpineSkinAttachmentMapEntries::has_next);
ClassDB::bind_method(D_METHOD("next"), &SpineSkinAttachmentMapEntries::next);
}
SpineSkinAttachmentMapEntries::SpineSkinAttachmentMapEntries() : entries(NULL) {}
SpineSkinAttachmentMapEntries::~SpineSkinAttachmentMapEntries() {
if (entries) {
delete entries;
return;
}
}
bool SpineSkinAttachmentMapEntries::has_next() {
return entries->hasNext();
}
Ref<SpineSkinAttachmentMapEntry> SpineSkinAttachmentMapEntries::next() {
auto &e = entries->next();
Ref<SpineSkinAttachmentMapEntry> gd_entry(memnew(SpineSkinAttachmentMapEntry));
gd_entry->set_spine_object(&e);
return gd_entry;
}

View File

@ -1,93 +0,0 @@
/******************************************************************************
* Spine Runtimes License Agreement
* Last updated January 1, 2020. Replaces all prior versions.
*
* Copyright (c) 2013-2020, Esoteric Software LLC
*
* Integration of the Spine Runtimes into software or otherwise creating
* derivative works of the Spine Runtimes is permitted under the terms and
* conditions of Section 2 of the Spine Editor License Agreement:
* http://esotericsoftware.com/spine-editor-license
*
* Otherwise, it is permitted to integrate the Spine Runtimes into software
* or otherwise create derivative works of the Spine Runtimes (collectively,
* "Products"), provided that each user of the Products must obtain their own
* Spine Editor license and redistribution of the Products in any form must
* include this license and copyright notice.
*
* THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES,
* BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#ifndef GODOT_SPINESKINATTACHMENTMAPENTRIES_H
#define GODOT_SPINESKINATTACHMENTMAPENTRIES_H
#include "core/variant_parser.h"
#include <spine/spine.h>
#include "SpineAttachment.h"
class SpineSkinAttachmentMapEntry : public Reference {
GDCLASS(SpineSkinAttachmentMapEntry, Reference);
protected:
static void _bind_methods();
private:
spine::Skin::AttachmentMap::Entry *entry;
public:
SpineSkinAttachmentMapEntry();
~SpineSkinAttachmentMapEntry();
inline void set_spine_object(spine::Skin::AttachmentMap::Entry *e) {
entry = e;
}
inline spine::Skin::AttachmentMap::Entry *get_spine_object() {
return entry;
}
uint64_t get_slot_index();
void set_slot_index(uint64_t v);
String get_entry_name();
void set_entry_name(const String &v);
Ref<SpineAttachment> get_attachment();
void set_attachment(Ref<SpineAttachment> v);
};
class SpineSkinAttachmentMapEntries : public Reference {
GDCLASS(SpineSkinAttachmentMapEntries, Reference);
protected:
static void _bind_methods();
private:
spine::Skin::AttachmentMap::Entries *entries;
public:
SpineSkinAttachmentMapEntries();
~SpineSkinAttachmentMapEntries();
inline void set_spine_object(spine::Skin::AttachmentMap::Entries *e) {
entries = e;
}
inline spine::Skin::AttachmentMap::Entries *get_spine_object() {
return entries;
}
bool has_next();
Ref<SpineSkinAttachmentMapEntry> next();
};
#endif//GODOT_SPINESKINATTACHMENTMAPENTRIES_H

View File

@ -28,13 +28,12 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineSlot.h" #include "SpineSlot.h"
#include "SpineBone.h" #include "SpineBone.h"
#include "SpineSkeleton.h" #include "SpineSkeleton.h"
#include "SpineCommon.h"
void SpineSlot::_bind_methods() { void SpineSlot::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_to_setup_pos"), &SpineSlot::set_to_setup_pos); ClassDB::bind_method(D_METHOD("set_to_setup_pose"), &SpineSlot::set_to_setup_pose);
ClassDB::bind_method(D_METHOD("get_data"), &SpineSlot::get_data); ClassDB::bind_method(D_METHOD("get_data"), &SpineSlot::get_data);
ClassDB::bind_method(D_METHOD("get_bone"), &SpineSlot::get_bone); ClassDB::bind_method(D_METHOD("get_bone"), &SpineSlot::get_bone);
ClassDB::bind_method(D_METHOD("get_skeleton"), &SpineSlot::get_skeleton); ClassDB::bind_method(D_METHOD("get_skeleton"), &SpineSlot::get_skeleton);
@ -49,93 +48,121 @@ void SpineSlot::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_attachment_state", "v"), &SpineSlot::set_attachment_state); ClassDB::bind_method(D_METHOD("set_attachment_state", "v"), &SpineSlot::set_attachment_state);
ClassDB::bind_method(D_METHOD("get_deform"), &SpineSlot::get_deform); ClassDB::bind_method(D_METHOD("get_deform"), &SpineSlot::get_deform);
ClassDB::bind_method(D_METHOD("set_deform", "v"), &SpineSlot::set_deform); ClassDB::bind_method(D_METHOD("set_deform", "v"), &SpineSlot::set_deform);
ClassDB::bind_method(D_METHOD("get_sequence_index"), &SpineSlot::get_sequence_index);
ClassDB::bind_method(D_METHOD("set_sequence_index", "v"), &SpineSlot::set_sequence_index);
} }
SpineSlot::SpineSlot() : slot(NULL) {} SpineSlot::SpineSlot() : slot(nullptr) {
SpineSlot::~SpineSlot() {} }
void SpineSlot::set_to_setup_pos() { void SpineSlot::set_to_setup_pose() {
SPINE_CHECK(slot,)
slot->setToSetupPose(); slot->setToSetupPose();
} }
Ref<SpineSlotData> SpineSlot::get_data() { Ref<SpineSlotData> SpineSlot::get_data() {
auto &sd = slot->getData(); SPINE_CHECK(slot, nullptr)
Ref<SpineSlotData> gd_sd(memnew(SpineSlotData)); auto &slot_data = slot->getData();
gd_sd->set_spine_object(&sd); Ref<SpineSlotData> slot_data_ref(memnew(SpineSlotData));
return gd_sd; slot_data_ref->set_spine_object(&slot_data);
return slot_data_ref;
} }
Ref<SpineBone> SpineSlot::get_bone() { Ref<SpineBone> SpineSlot::get_bone() {
auto &b = slot->getBone(); SPINE_CHECK(slot, nullptr)
Ref<SpineBone> gd_b(memnew(SpineBone)); auto &bone = slot->getBone();
gd_b->set_spine_object(&b); Ref<SpineBone> bone_ref(memnew(SpineBone));
return gd_b; bone_ref->set_spine_object(&bone);
return bone_ref;
} }
Ref<SpineSkeleton> SpineSlot::get_skeleton() { Ref<SpineSkeleton> SpineSlot::get_skeleton() {
auto &s = slot->getSkeleton(); SPINE_CHECK(slot, nullptr)
Ref<SpineSkeleton> gd_s(memnew(SpineSkeleton)); auto &skeleton = slot->getSkeleton();
gd_s->set_spine_object(&s); Ref<SpineSkeleton> skeleton_ref(memnew(SpineSkeleton));
return gd_s; skeleton_ref->set_spine_object(&skeleton);
return skeleton_ref;
} }
Color SpineSlot::get_color() { Color SpineSlot::get_color() {
auto &c = slot->getColor(); SPINE_CHECK(slot, Color(0, 0, 0, 0))
return Color(c.r, c.g, c.b, c.a); auto &color = slot->getColor();
return Color(color.r, color.g, color.b, color.a);
} }
void SpineSlot::set_color(Color v) { void SpineSlot::set_color(Color v) {
auto &c = slot->getColor(); SPINE_CHECK(slot,)
c.set(v.r, v.g, v.b, v.a); auto &color = slot->getColor();
color.set(v.r, v.g, v.b, v.a);
} }
Color SpineSlot::get_dark_color() { Color SpineSlot::get_dark_color() {
auto &c = slot->getDarkColor(); SPINE_CHECK(slot, Color(0, 0, 0, 0))
return Color(c.r, c.g, c.b, c.a); auto &color = slot->getDarkColor();
return Color(color.r, color.g, color.b, color.a);
} }
void SpineSlot::set_dark_color(Color v) { void SpineSlot::set_dark_color(Color v) {
auto &c = slot->getDarkColor(); SPINE_CHECK(slot,)
c.set(v.r, v.g, v.b, v.a); auto &color = slot->getDarkColor();
color.set(v.r, v.g, v.b, v.a);
} }
bool SpineSlot::has_dark_color() { bool SpineSlot::has_dark_color() {
SPINE_CHECK(slot, false)
return slot->hasDarkColor(); return slot->hasDarkColor();
} }
Ref<SpineAttachment> SpineSlot::get_attachment() { Ref<SpineAttachment> SpineSlot::get_attachment() {
auto a = slot->getAttachment(); SPINE_CHECK(slot, nullptr)
if (a == NULL) return NULL; auto attachment = slot->getAttachment();
Ref<SpineAttachment> gd_a(memnew(SpineAttachment)); if (!attachment) return nullptr;
gd_a->set_spine_object(a); Ref<SpineAttachment> attachment_ref(memnew(SpineAttachment));
return gd_a; attachment_ref->set_spine_object(attachment);
return attachment_ref;
} }
void SpineSlot::set_attachment(Ref<SpineAttachment> v) { void SpineSlot::set_attachment(Ref<SpineAttachment> v) {
if (v.is_valid()) { SPINE_CHECK(slot,)
slot->setAttachment(v->get_spine_object()); slot->setAttachment(v.is_valid() ? v->get_spine_object() : nullptr);
} else {
slot->setAttachment(NULL);
}
} }
int SpineSlot::get_attachment_state() { int SpineSlot::get_attachment_state() {
SPINE_CHECK(slot, 0)
return slot->getAttachmentState(); return slot->getAttachmentState();
} }
void SpineSlot::set_attachment_state(int v) { void SpineSlot::set_attachment_state(int v) {
SPINE_CHECK(slot,)
slot->setAttachmentState(v); slot->setAttachmentState(v);
} }
Array SpineSlot::get_deform() { Array SpineSlot::get_deform() {
auto &ds = slot->getDeform(); Array result;
Array gd_ds; SPINE_CHECK(slot, result)
gd_ds.resize(ds.size()); auto &deform = slot->getDeform();
for (size_t i = 0; i < ds.size(); ++i) { result.resize((int)deform.size());
gd_ds[i] = ds[i]; for (int i = 0; i < deform.size(); ++i) {
result[i] = deform[i];
} }
return gd_ds; return result;
} }
void SpineSlot::set_deform(Array gd_ds) {
auto &ds = slot->getDeform(); void SpineSlot::set_deform(Array v) {
ds.setSize(gd_ds.size(), 0); SPINE_CHECK(slot,)
for (size_t i = 0; i < gd_ds.size(); ++i) { auto &deform = slot->getDeform();
ds[i] = gd_ds[i]; deform.setSize(v.size(), 0);
for (int i = 0; i < v.size(); ++i) {
deform[i] = v[i];
} }
} }
int SpineSlot::get_sequence_index() {
SPINE_CHECK(slot, 0)
return slot->getAttachmentState();
}
void SpineSlot::set_sequence_index(int v) {
SPINE_CHECK(slot,)
slot->setAttachmentState(v);
}

View File

@ -30,19 +30,16 @@
#ifndef GODOT_SPINESLOT_H #ifndef GODOT_SPINESLOT_H
#define GODOT_SPINESLOT_H #define GODOT_SPINESLOT_H
#include "core/variant_parser.h" #include "SpineCommon.h"
#include <spine/spine.h>
#include "SpineSlotData.h" #include "SpineSlotData.h"
#include "SpineAttachment.h" #include "SpineAttachment.h"
#include "SpineBone.h"
// Breaks cyclic dependency.
class SpineSkeleton; class SpineSkeleton;
class SpineBone; class SpineSlot : public REFCOUNTED {
GDCLASS(SpineSlot, REFCOUNTED);
class SpineSlot : public Reference {
GDCLASS(SpineSlot, Reference);
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -52,16 +49,11 @@ private:
public: public:
SpineSlot(); SpineSlot();
~SpineSlot();
inline void set_spine_object(spine::Slot *s) { void set_spine_object(spine::Slot *s) { slot = s; }
slot = s; spine::Slot *get_spine_object() { return slot; }
}
inline spine::Slot *get_spine_object() {
return slot;
}
void set_to_setup_pos(); void set_to_setup_pose();
Ref<SpineSlotData> get_data(); Ref<SpineSlotData> get_data();
@ -70,21 +62,30 @@ public:
Ref<SpineSkeleton> get_skeleton(); Ref<SpineSkeleton> get_skeleton();
Color get_color(); Color get_color();
void set_color(Color v); void set_color(Color v);
Color get_dark_color(); Color get_dark_color();
void set_dark_color(Color v); void set_dark_color(Color v);
bool has_dark_color(); bool has_dark_color();
Ref<SpineAttachment> get_attachment(); Ref<SpineAttachment> get_attachment();
void set_attachment(Ref<SpineAttachment> v); void set_attachment(Ref<SpineAttachment> v);
int get_attachment_state(); int get_attachment_state();
void set_attachment_state(int v); void set_attachment_state(int v);
Array get_deform(); Array get_deform();
void set_deform(Array v); void set_deform(Array v);
int get_sequence_index();
void set_sequence_index(int v);
}; };
#endif//GODOT_SPINESLOT_H #endif//GODOT_SPINESLOT_H

View File

@ -28,13 +28,16 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineSlotData.h" #include "SpineSlotData.h"
#include "SpineCommon.h"
void SpineSlotData::_bind_methods() { void SpineSlotData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_index"), &SpineSlotData::get_index); ClassDB::bind_method(D_METHOD("get_index"), &SpineSlotData::get_index);
ClassDB::bind_method(D_METHOD("get_slot_name"), &SpineSlotData::get_slot_name); ClassDB::bind_method(D_METHOD("get_name"), &SpineSlotData::get_name);
ClassDB::bind_method(D_METHOD("get_bone_data"), &SpineSlotData::get_bone_data); ClassDB::bind_method(D_METHOD("get_bone_data"), &SpineSlotData::get_bone_data);
ClassDB::bind_method(D_METHOD("get_color"), &SpineSlotData::get_color); ClassDB::bind_method(D_METHOD("get_color"), &SpineSlotData::get_color);
ClassDB::bind_method(D_METHOD("set_color", "v"), &SpineSlotData::set_color);
ClassDB::bind_method(D_METHOD("get_dark_color"), &SpineSlotData::get_dark_color); ClassDB::bind_method(D_METHOD("get_dark_color"), &SpineSlotData::get_dark_color);
ClassDB::bind_method(D_METHOD("set_dark_color", "v"), &SpineSlotData::set_dark_color);
ClassDB::bind_method(D_METHOD("has_dark_color"), &SpineSlotData::has_dark_color); ClassDB::bind_method(D_METHOD("has_dark_color"), &SpineSlotData::has_dark_color);
ClassDB::bind_method(D_METHOD("set_has_dark_color", "v"), &SpineSlotData::set_has_dark_color); ClassDB::bind_method(D_METHOD("set_has_dark_color", "v"), &SpineSlotData::set_has_dark_color);
ClassDB::bind_method(D_METHOD("get_attachment_name"), &SpineSlotData::get_attachment_name); ClassDB::bind_method(D_METHOD("get_attachment_name"), &SpineSlotData::get_attachment_name);
@ -42,73 +45,77 @@ void SpineSlotData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_blend_mode"), &SpineSlotData::get_blend_mode); ClassDB::bind_method(D_METHOD("get_blend_mode"), &SpineSlotData::get_blend_mode);
ClassDB::bind_method(D_METHOD("set_blend_mode", "v"), &SpineSlotData::set_blend_mode); ClassDB::bind_method(D_METHOD("set_blend_mode", "v"), &SpineSlotData::set_blend_mode);
ClassDB::bind_method(D_METHOD("set_color", "v"), &SpineSlotData::set_color);
ClassDB::bind_method(D_METHOD("set_dark_color", "v"), &SpineSlotData::set_dark_color);
BIND_ENUM_CONSTANT(BLENDMODE_NORMAL);
BIND_ENUM_CONSTANT(BLENDMODE_ADDITIVE);
BIND_ENUM_CONSTANT(BLENDMODE_MULTIPLY);
BIND_ENUM_CONSTANT(BLENDMODE_SCREEN);
} }
SpineSlotData::SpineSlotData() : slot_data(NULL) {} SpineSlotData::SpineSlotData() : slot_data(nullptr) {
SpineSlotData::~SpineSlotData() {} }
#define S_T(x) (spine::String(x.utf8()))
int SpineSlotData::get_index() { int SpineSlotData::get_index() {
SPINE_CHECK(slot_data, 0)
return slot_data->getIndex(); return slot_data->getIndex();
} }
String SpineSlotData::get_slot_name() { String SpineSlotData::get_name() {
SPINE_CHECK(slot_data, String(""))
return slot_data->getName().buffer(); return slot_data->getName().buffer();
} }
Ref<SpineBoneData> SpineSlotData::get_bone_data() { Ref<SpineBoneData> SpineSlotData::get_bone_data() {
auto &bd = slot_data->getBoneData(); SPINE_CHECK(slot_data, nullptr)
Ref<SpineBoneData> gd_bone_data(memnew(SpineBoneData)); auto &bone_data = slot_data->getBoneData();
gd_bone_data->set_spine_object(&bd); Ref<SpineBoneData> bone_data_ref(memnew(SpineBoneData));
return gd_bone_data; bone_data_ref->set_spine_object(&bone_data);
return bone_data_ref;
} }
Color SpineSlotData::get_color() { Color SpineSlotData::get_color() {
auto &c = slot_data->getColor(); SPINE_CHECK(slot_data, Color(0, 0, 0, 0))
return Color(c.r, c.g, c.b, c.a); auto &color = slot_data->getColor();
return Color(color.r, color.g, color.b, color.a);
} }
void SpineSlotData::set_color(Color v) { void SpineSlotData::set_color(Color v) {
auto &c = slot_data->getColor(); SPINE_CHECK(slot_data,)
c.set(v.r, v.g, v.b, v.a); auto &color = slot_data->getColor();
color.set(v.r, v.g, v.b, v.a);
} }
Color SpineSlotData::get_dark_color() { Color SpineSlotData::get_dark_color() {
auto &c = slot_data->getDarkColor(); SPINE_CHECK(slot_data, Color(0, 0, 0, 0))
return Color(c.r, c.g, c.b, c.a); auto &color = slot_data->getDarkColor();
return Color(color.r, color.g, color.b, color.a);
} }
void SpineSlotData::set_dark_color(Color v) { void SpineSlotData::set_dark_color(Color v) {
auto &c = slot_data->getDarkColor(); SPINE_CHECK(slot_data,)
c.set(v.r, v.g, v.b, v.a); auto &color = slot_data->getDarkColor();
color.set(v.r, v.g, v.b, v.a);
} }
bool SpineSlotData::has_dark_color() { bool SpineSlotData::has_dark_color() {
SPINE_CHECK(slot_data, false)
return slot_data->hasDarkColor(); return slot_data->hasDarkColor();
} }
void SpineSlotData::set_has_dark_color(bool v) { void SpineSlotData::set_has_dark_color(bool v) {
SPINE_CHECK(slot_data,)
slot_data->setHasDarkColor(v); slot_data->setHasDarkColor(v);
} }
String SpineSlotData::get_attachment_name() { String SpineSlotData::get_attachment_name() {
SPINE_CHECK(slot_data, "")
return slot_data->getAttachmentName().buffer(); return slot_data->getAttachmentName().buffer();
} }
void SpineSlotData::set_attachment_name(const String &v) { void SpineSlotData::set_attachment_name(const String &v) {
slot_data->setAttachmentName(S_T(v)); SPINE_CHECK(slot_data,)
slot_data->setAttachmentName(SPINE_STRING(v));
} }
SpineSlotData::BlendMode SpineSlotData::get_blend_mode() { SpineConstant::BlendMode SpineSlotData::get_blend_mode() {
auto bm = (int) slot_data->getBlendMode(); SPINE_CHECK(slot_data, SpineConstant::BlendMode_Normal)
return (BlendMode) bm; return (SpineConstant::BlendMode)slot_data->getBlendMode();
} }
void SpineSlotData::set_blend_mode(BlendMode v) { void SpineSlotData::set_blend_mode(SpineConstant::BlendMode v) {
auto bm = (int) v; SPINE_CHECK(slot_data,)
slot_data->setBlendMode((spine::BlendMode) bm); slot_data->setBlendMode((spine::BlendMode) v);
} }
#undef S_T

View File

@ -29,14 +29,13 @@
#ifndef GODOT_SPINESLOTDATA_H #ifndef GODOT_SPINESLOTDATA_H
#define GODOT_SPINESLOTDATA_H #define GODOT_SPINESLOTDATA_H
#include "core/variant_parser.h"
#include <spine/spine.h>
#include "SpineCommon.h"
#include "SpineBoneData.h" #include "SpineBoneData.h"
#include <spine/SlotData.h>
class SpineSlotData : public Reference { class SpineSlotData : public REFCOUNTED {
GDCLASS(SpineSlotData, Reference); GDCLASS(SpineSlotData, REFCOUNTED);
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -46,43 +45,35 @@ private:
public: public:
SpineSlotData(); SpineSlotData();
~SpineSlotData();
inline void set_spine_object(spine::SlotData *s) { void set_spine_object(spine::SlotData *s) { slot_data = s; }
slot_data = s; spine::SlotData *get_spine_object() { return slot_data; }
}
inline spine::SlotData *get_spine_object() {
return slot_data;
}
enum BlendMode {
BLENDMODE_NORMAL = 0,
BLENDMODE_ADDITIVE,
BLENDMODE_MULTIPLY,
BLENDMODE_SCREEN
};
int get_index(); int get_index();
String get_slot_name(); String get_name();
Ref<SpineBoneData> get_bone_data(); Ref<SpineBoneData> get_bone_data();
Color get_color(); Color get_color();
void set_color(Color c); void set_color(Color c);
Color get_dark_color(); Color get_dark_color();
void set_dark_color(Color c); void set_dark_color(Color c);
bool has_dark_color(); bool has_dark_color();
void set_has_dark_color(bool v); void set_has_dark_color(bool v);
String get_attachment_name(); String get_attachment_name();
void set_attachment_name(const String &v); void set_attachment_name(const String &v);
BlendMode get_blend_mode(); SpineConstant::BlendMode get_blend_mode();
void set_blend_mode(BlendMode v);
void set_blend_mode(SpineConstant::BlendMode v);
}; };
VARIANT_ENUM_CAST(SpineSlotData::BlendMode);
#endif//GODOT_SPINESLOTDATA_H #endif//GODOT_SPINESLOTDATA_H

View File

@ -46,9 +46,6 @@ void SpineSprite::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_bind_slot_nodes"), &SpineSprite::get_bind_slot_nodes); ClassDB::bind_method(D_METHOD("get_bind_slot_nodes"), &SpineSprite::get_bind_slot_nodes);
ClassDB::bind_method(D_METHOD("set_bind_slot_nodes", "v"), &SpineSprite::set_bind_slot_nodes); ClassDB::bind_method(D_METHOD("set_bind_slot_nodes", "v"), &SpineSprite::set_bind_slot_nodes);
ClassDB::bind_method(D_METHOD("get_overlap"), &SpineSprite::get_overlap);
ClassDB::bind_method(D_METHOD("set_overlap", "v"), &SpineSprite::set_overlap);
ClassDB::bind_method(D_METHOD("bone_get_global_transform", "bone_name"), &SpineSprite::bone_get_global_transform); ClassDB::bind_method(D_METHOD("bone_get_global_transform", "bone_name"), &SpineSprite::bone_get_global_transform);
ClassDB::bind_method(D_METHOD("bone_set_global_transform", "bone_name", "global_transform"), &SpineSprite::bone_set_global_transform); ClassDB::bind_method(D_METHOD("bone_set_global_transform", "bone_name", "global_transform"), &SpineSprite::bone_set_global_transform);
@ -65,14 +62,13 @@ void SpineSprite::_bind_methods() {
ADD_SIGNAL(MethodInfo("animation_event", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); ADD_SIGNAL(MethodInfo("animation_event", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent")));
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skeleton_data_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineSkeletonDataResource"), "set_skeleton_data_res", "get_skeleton_data_res"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skeleton_data_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineSkeletonDataResource"), "set_skeleton_data_res", "get_skeleton_data_res");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "overlap"), "set_overlap", "get_overlap");
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "bind_slot_nodes"), "set_bind_slot_nodes", "get_bind_slot_nodes"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "bind_slot_nodes"), "set_bind_slot_nodes", "get_bind_slot_nodes");
ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Process,Physics,Manual"), "set_process_mode", "get_process_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Process,Physics,Manual"), "set_process_mode", "get_process_mode");
BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Process); BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Process)
BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Physics); BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Physics)
BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Manual); BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Manual)
} }
SpineSprite::SpineSprite() : overlap(false), process_mode(ProcessMode_Process), skeleton_clipper(nullptr) { SpineSprite::SpineSprite() : overlap(false), process_mode(ProcessMode_Process), skeleton_clipper(nullptr) {
@ -121,8 +117,13 @@ void SpineSprite::_on_skeleton_data_changed() {
animation_state.unref(); animation_state.unref();
if (skeleton_data_res.is_valid()) { if (skeleton_data_res.is_valid()) {
#if VERSION_MAJOR > 3
if (!skeleton_data_res->is_connected("skeleton_data_changed", callable_mp(this, &SpineSprite::_on_skeleton_data_changed)))
skeleton_data_res->connect("skeleton_data_changed", callable_mp(this, &SpineSprite::_on_skeleton_data_changed));
#else
if (!skeleton_data_res->is_connected("skeleton_data_changed", this, "_on_skeleton_data_changed")) if (!skeleton_data_res->is_connected("skeleton_data_changed", this, "_on_skeleton_data_changed"))
skeleton_data_res->connect("skeleton_data_changed", this, "_on_skeleton_data_changed"); skeleton_data_res->connect("skeleton_data_changed", this, "_on_skeleton_data_changed");
#endif
} }
if (skeleton_data_res.is_valid() && skeleton_data_res->is_skeleton_data_loaded()) { if (skeleton_data_res.is_valid() && skeleton_data_res->is_skeleton_data_loaded()) {
@ -146,7 +147,7 @@ void SpineSprite::_on_skeleton_data_changed() {
} }
} }
property_list_changed_notify(); NOTIFY_PROPERTY_LIST_CHANGED();
} }
Ref<SpineSkeleton> SpineSprite::get_skeleton() { Ref<SpineSkeleton> SpineSprite::get_skeleton() {
@ -162,20 +163,25 @@ void SpineSprite::_notification(int p_what) {
case NOTIFICATION_READY: { case NOTIFICATION_READY: {
set_process_internal(process_mode == ProcessMode_Process); set_process_internal(process_mode == ProcessMode_Process);
set_physics_process_internal(process_mode == ProcessMode_Physics); set_physics_process_internal(process_mode == ProcessMode_Physics);
} break; break;
}
case NOTIFICATION_INTERNAL_PROCESS: { case NOTIFICATION_INTERNAL_PROCESS: {
if (process_mode == ProcessMode_Process) if (process_mode == ProcessMode_Process)
_update_all(get_process_delta_time()); _update_all(get_process_delta_time());
} break; break;
}
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (process_mode == ProcessMode_Physics) if (process_mode == ProcessMode_Physics)
_update_all(get_physics_process_delta_time()); _update_all(get_physics_process_delta_time());
} break; break;
}
default:
break;
} }
} }
void SpineSprite::_update_all(float delta) { void SpineSprite::_update_all(float delta) {
if (!(skeleton.is_valid() && animation_state.is_valid()) || mesh_instances.empty()) if (!(skeleton.is_valid() && animation_state.is_valid()) || EMPTY(mesh_instances))
return; return;
animation_state->update(delta); animation_state->update(delta);
@ -191,7 +197,7 @@ void SpineSprite::_update_all(float delta) {
void SpineSprite::update_bind_slot_nodes() { void SpineSprite::update_bind_slot_nodes() {
if (animation_state.is_valid() && skeleton.is_valid()) { if (animation_state.is_valid() && skeleton.is_valid()) {
for (size_t i = 0, n = bind_slot_nodes.size(); i < n; ++i) { for (int i = 0, n = bind_slot_nodes.size(); i < n; ++i) {
auto a = bind_slot_nodes[i]; auto a = bind_slot_nodes[i];
if (a.get_type() == Variant::DICTIONARY) { if (a.get_type() == Variant::DICTIONARY) {
auto d = (Dictionary) a; auto d = (Dictionary) a;
@ -199,14 +205,14 @@ void SpineSprite::update_bind_slot_nodes() {
NodePath node_path = d["node_path"]; NodePath node_path = d["node_path"];
Node *node = get_node_or_null(node_path); Node *node = get_node_or_null(node_path);
if (node && node->is_class("Node2D")) { if (node && node->is_class("Node2D")) {
Node2D *node2d = (Node2D *) node; auto *node2d = (Node2D *) node;
String slot_name = d["slot_name"]; String slot_name = d["slot_name"];
auto slot = skeleton->find_slot(slot_name); auto slot = skeleton->find_slot(slot_name);
if (slot.is_valid()) { if (slot.is_valid()) {
auto bone = slot->get_bone(); auto bone = slot->get_bone();
if (bone.is_valid()) { if (bone.is_valid()) {
update_bind_slot_node_transform(bone, node2d); bone->apply_world_transform_2d(node2d);
update_bind_slot_node_draw_order(slot_name, node2d); update_bind_slot_node_draw_order(slot_name, node2d);
} }
} }
@ -218,14 +224,14 @@ void SpineSprite::update_bind_slot_nodes() {
NodePath node_path = as[1]; NodePath node_path = as[1];
Node *node = get_node_or_null(node_path); Node *node = get_node_or_null(node_path);
if (node && node->is_class("Node2D")) { if (node && node->is_class("Node2D")) {
Node2D *node2d = (Node2D *) node; auto *node2d = (Node2D *) node;
String slot_name = as[0]; String slot_name = as[0];
auto slot = skeleton->find_slot(slot_name); auto slot = skeleton->find_slot(slot_name);
if (slot.is_valid()) { if (slot.is_valid()) {
auto bone = slot->get_bone(); auto bone = slot->get_bone();
if (bone.is_valid()) { if (bone.is_valid()) {
update_bind_slot_node_transform(bone, node2d); bone->apply_world_transform_2d(node2d);
update_bind_slot_node_draw_order(slot_name, node2d); update_bind_slot_node_draw_order(slot_name, node2d);
} }
} }
@ -236,11 +242,22 @@ void SpineSprite::update_bind_slot_nodes() {
} }
} }
void SpineSprite::update_bind_slot_node_transform(Ref<SpineBone> bone, Node2D *node2d) {
bone->apply_world_transform_2d(node2d);
}
void SpineSprite::update_bind_slot_node_draw_order(const String &slot_name, Node2D *node2d) { void SpineSprite::update_bind_slot_node_draw_order(const String &slot_name, Node2D *node2d) {
#if VERSION_MAJOR > 3
auto nodes = find_nodes(slot_name);
if (!nodes.is_empty()) {
auto mesh_ins = Object::cast_to<MeshInstance2D>(nodes[0]);
if (mesh_ins) {
auto pos = mesh_ins->get_index();
// get child
auto node = find_child_node_by_node(node2d);
if (node && node->get_index() != pos + 1) {
move_child(node, pos + 1);
}
}
}
#else
auto mesh_ins = find_node(slot_name); auto mesh_ins = find_node(slot_name);
if (mesh_ins) { if (mesh_ins) {
auto pos = mesh_ins->get_index(); auto pos = mesh_ins->get_index();
@ -251,6 +268,7 @@ void SpineSprite::update_bind_slot_node_draw_order(const String &slot_name, Node
move_child(node, pos + 1); move_child(node, pos + 1);
} }
} }
#endif
} }
Node *SpineSprite::find_child_node_by_node(Node *node) { Node *SpineSprite::find_child_node_by_node(Node *node) {
if (node == nullptr) return nullptr; if (node == nullptr) return nullptr;
@ -283,9 +301,9 @@ void SpineSprite::remove_meshes() {
#define TEMP_COPY(t, get_res) \ #define TEMP_COPY(t, get_res) \
do { \ do { \
auto &temp_uvs = get_res; \ auto &temp_uvs = get_res; \
t.setSize(temp_uvs.size(), 0); \ (t).setSize(temp_uvs.size(), 0); \
for (size_t j = 0; j < t.size(); ++j) { \ for (size_t j = 0; j < (t).size(); ++j) { \
t[j] = temp_uvs[j]; \ (t)[j] = temp_uvs[j]; \
} \ } \
} while (false); } while (false);
@ -294,7 +312,7 @@ void SpineSprite::update_meshes(Ref<SpineSkeleton> s) {
static unsigned short quad_indices[] = {0, 1, 2, 2, 3, 0}; static unsigned short quad_indices[] = {0, 1, 2, 2, 3, 0};
auto sk = s->get_spine_object(); auto sk = s->get_spine_object();
for (size_t i = 0, n = sk->getSlots().size(); i < n; ++i) { for (int i = 0, n = sk->getSlots().size(); i < n; ++i) {
spine::Vector<float> vertices; spine::Vector<float> vertices;
spine::Vector<float> uvs; spine::Vector<float> uvs;
spine::Vector<unsigned short> indices; spine::Vector<unsigned short> indices;
@ -319,7 +337,7 @@ void SpineSprite::update_meshes(Ref<SpineSkeleton> s) {
size_t v_num = 0; size_t v_num = 0;
if (attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) { if (attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) {
spine::RegionAttachment *region_attachment = (spine::RegionAttachment *) attachment; auto *region_attachment = (spine::RegionAttachment *) attachment;
auto p_spine_renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) region_attachment->getRendererObject())->page->getRendererObject(); auto p_spine_renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) region_attachment->getRendererObject())->page->getRendererObject();
tex = p_spine_renderer_object->texture; tex = p_spine_renderer_object->texture;
@ -343,7 +361,7 @@ void SpineSprite::update_meshes(Ref<SpineSkeleton> s) {
tint.b *= attachment_color.b; tint.b *= attachment_color.b;
tint.a *= attachment_color.a; tint.a *= attachment_color.a;
} else if (attachment->getRTTI().isExactly(spine::MeshAttachment::rtti)) { } else if (attachment->getRTTI().isExactly(spine::MeshAttachment::rtti)) {
spine::MeshAttachment *mesh = (spine::MeshAttachment *) attachment; auto *mesh = (spine::MeshAttachment *) attachment;
auto p_spine_renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); auto p_spine_renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) mesh->getRendererObject())->page->getRendererObject();
tex = p_spine_renderer_object->texture; tex = p_spine_renderer_object->texture;
@ -371,7 +389,11 @@ void SpineSprite::update_meshes(Ref<SpineSkeleton> s) {
} }
auto mesh_ins = mesh_instances[i]; auto mesh_ins = mesh_instances[i];
#if VERSION_MAJOR > 3
RenderingServer::get_singleton()->canvas_item_clear(mesh_ins->get_canvas_item());
#else
VisualServer::get_singleton()->canvas_item_clear(mesh_ins->get_canvas_item()); VisualServer::get_singleton()->canvas_item_clear(mesh_ins->get_canvas_item());
#endif
if (skeleton_clipper->isClipping()) { if (skeleton_clipper->isClipping()) {
skeleton_clipper->clipTriangles(vertices, indices, uvs, VERTEX_STRIDE); skeleton_clipper->clipTriangles(vertices, indices, uvs, VERTEX_STRIDE);
@ -403,6 +425,18 @@ void SpineSprite::update_meshes(Ref<SpineSkeleton> s) {
p_indices.set(j, clipped_indices[j]); p_indices.set(j, clipped_indices[j]);
} }
#if VERSION_MAJOR > 3
RenderingServer::get_singleton()->canvas_item_add_triangle_array(mesh_ins->get_canvas_item(),
p_indices,
p_points,
p_colors,
p_uvs,
Vector<int>(),
Vector<float>(),
tex.is_null() ? RID() : tex->get_rid(),
-1
);
#else
VisualServer::get_singleton()->canvas_item_add_triangle_array(mesh_ins->get_canvas_item(), VisualServer::get_singleton()->canvas_item_add_triangle_array(mesh_ins->get_canvas_item(),
p_indices, p_indices,
p_points, p_points,
@ -413,6 +447,7 @@ void SpineSprite::update_meshes(Ref<SpineSkeleton> s) {
tex.is_null() ? RID() : tex->get_rid(), tex.is_null() ? RID() : tex->get_rid(),
-1, -1,
normal_tex.is_null() ? RID() : normal_tex->get_rid()); normal_tex.is_null() ? RID() : normal_tex->get_rid());
#endif
} }
} else { } else {
if (indices.size() > 0) { if (indices.size() > 0) {
@ -432,6 +467,17 @@ void SpineSprite::update_meshes(Ref<SpineSkeleton> s) {
p_indices.set(j, indices[j]); p_indices.set(j, indices[j]);
} }
#if VERSION_MAJOR > 3
RenderingServer::get_singleton()->canvas_item_add_triangle_array(mesh_ins->get_canvas_item(),
p_indices,
p_points,
p_colors,
p_uvs,
Vector<int>(),
Vector<float>(),
tex.is_null() ? RID() : tex->get_rid(),
-1);
#else
VisualServer::get_singleton()->canvas_item_add_triangle_array(mesh_ins->get_canvas_item(), VisualServer::get_singleton()->canvas_item_add_triangle_array(mesh_ins->get_canvas_item(),
p_indices, p_indices,
p_points, p_points,
@ -442,6 +488,7 @@ void SpineSprite::update_meshes(Ref<SpineSkeleton> s) {
tex.is_null() ? RID() : tex->get_rid(), tex.is_null() ? RID() : tex->get_rid(),
-1, -1,
normal_tex.is_null() ? RID() : normal_tex->get_rid()); normal_tex.is_null() ? RID() : normal_tex->get_rid());
#endif
} }
} }
skeleton_clipper->clipEnd(*slot); skeleton_clipper->clipEnd(*slot);
@ -496,14 +543,6 @@ void SpineSprite::set_bind_slot_nodes(Array v) {
bind_slot_nodes = v; bind_slot_nodes = v;
} }
bool SpineSprite::get_overlap() {
return overlap;
}
void SpineSprite::set_overlap(bool v) {
overlap = v;
}
Transform2D SpineSprite::bone_get_global_transform(const String &bone_name) { Transform2D SpineSprite::bone_get_global_transform(const String &bone_name) {
if (!animation_state.is_valid() && !skeleton.is_valid()) { if (!animation_state.is_valid() && !skeleton.is_valid()) {
return get_global_transform(); return get_global_transform();

View File

@ -30,12 +30,11 @@
#ifndef GODOT_SPINESPRITE_H #ifndef GODOT_SPINESPRITE_H
#define GODOT_SPINESPRITE_H #define GODOT_SPINESPRITE_H
#include "scene/2d/node_2d.h"
#include "scene/resources/texture.h"
#include "SpineSkeleton.h" #include "SpineSkeleton.h"
#include "SpineAnimationState.h" #include "SpineAnimationState.h"
#include "scene/2d/node_2d.h"
#include "scene/2d/mesh_instance_2d.h" #include "scene/2d/mesh_instance_2d.h"
#include "scene/resources/texture.h"
class SpineSprite : public Node2D, public spine::AnimationStateListenerObject { class SpineSprite : public Node2D, public spine::AnimationStateListenerObject {
GDCLASS(SpineSprite, Node2D); GDCLASS(SpineSprite, Node2D);
@ -90,7 +89,6 @@ public:
void update_meshes(Ref<SpineSkeleton> s); void update_meshes(Ref<SpineSkeleton> s);
void update_bind_slot_nodes(); void update_bind_slot_nodes();
void update_bind_slot_node_transform(Ref<SpineBone> bone, Node2D *node2d);
void update_bind_slot_node_draw_order(const String &slot_name, Node2D *node2d); void update_bind_slot_node_draw_order(const String &slot_name, Node2D *node2d);
Node *find_child_node_by_node(Node *node); Node *find_child_node_by_node(Node *node);
@ -101,15 +99,15 @@ public:
void _update_all(float delta); void _update_all(float delta);
Array get_bind_slot_nodes(); Array get_bind_slot_nodes();
void set_bind_slot_nodes(Array v); void set_bind_slot_nodes(Array v);
Transform2D bone_get_global_transform(const String &bone_name); Transform2D bone_get_global_transform(const String &bone_name);
void bone_set_global_transform(const String &bone_name, Transform2D transform); void bone_set_global_transform(const String &bone_name, Transform2D transform);
bool get_overlap();
void set_overlap(bool v);
ProcessMode get_process_mode(); ProcessMode get_process_mode();
void set_process_mode(ProcessMode v); void set_process_mode(ProcessMode v);
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED

View File

@ -30,7 +30,9 @@
#include "SpineTimeline.h" #include "SpineTimeline.h"
#include "SpineSkeleton.h" #include "SpineSkeleton.h"
#include "SpineEvent.h" #include "SpineEvent.h"
#if VERSION_MAJOR == 3
#include "core/method_bind_ext.gen.inc" #include "core/method_bind_ext.gen.inc"
#endif
void SpineTimeline::_bind_methods() { void SpineTimeline::_bind_methods() {
ClassDB::bind_method(D_METHOD("apply", "skeleton", "last_time", "time", "events", "alpha", "blend", "direction"), &SpineTimeline::apply); ClassDB::bind_method(D_METHOD("apply", "skeleton", "last_time", "time", "events", "alpha", "blend", "direction"), &SpineTimeline::apply);
@ -42,58 +44,58 @@ void SpineTimeline::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_type"), &SpineTimeline::get_type); ClassDB::bind_method(D_METHOD("get_type"), &SpineTimeline::get_type);
} }
SpineTimeline::SpineTimeline() : timeline(NULL) { SpineTimeline::SpineTimeline() : timeline(nullptr) {
} }
SpineTimeline::~SpineTimeline() { void SpineTimeline::apply(Ref<SpineSkeleton> skeleton, float last_time, float time, Array events, float alpha,
}
void SpineTimeline::apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, Array events, float alpha,
SpineConstant::MixBlend blend, SpineConstant::MixDirection direction) { SpineConstant::MixBlend blend, SpineConstant::MixDirection direction) {
spine::Vector<spine::Event *> spineEvents; SPINE_CHECK(timeline,)
spineEvents.setSize(events.size(), nullptr); spine::Vector<spine::Event *> spine_events;
for (size_t i = 0; i < events.size(); ++i) { spine_events.setSize((int)events.size(), nullptr);
events[i] = ((Ref<SpineEvent>) spineEvents[i])->get_spine_object(); for (int i = 0; i < events.size(); ++i) {
events[i] = ((Ref<SpineEvent>) spine_events[i])->get_spine_object();
} }
timeline->apply(*(skeleton->get_spine_object()), lastTime, time, &spineEvents, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction); timeline->apply(*(skeleton->get_spine_object()), last_time, time, &spine_events, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction);
} }
int64_t SpineTimeline::get_frame_entries() { int SpineTimeline::get_frame_entries() {
return timeline->getFrameEntries(); SPINE_CHECK(timeline, 0)
return (int)timeline->getFrameEntries();
} }
int64_t SpineTimeline::get_frame_count() { int SpineTimeline::get_frame_count() {
return timeline->getFrameCount(); SPINE_CHECK(timeline, 0)
return (int)timeline->getFrameCount();
} }
Array SpineTimeline::get_frames() { Array SpineTimeline::get_frames() {
auto &frames = timeline->getFrames();
Array result; Array result;
result.resize(frames.size()); SPINE_CHECK(timeline, result)
auto &frames = timeline->getFrames();
for (size_t i = 0; i < result.size(); ++i) { result.resize((int)frames.size());
for (int i = 0; i < result.size(); ++i) {
result[i] = frames[i]; result[i] = frames[i];
} }
return result; return result;
} }
float SpineTimeline::get_duration() { float SpineTimeline::get_duration() {
SPINE_CHECK(timeline, 0)
return timeline->getDuration(); return timeline->getDuration();
} }
Array SpineTimeline::get_property_ids() { Array SpineTimeline::get_property_ids() {
auto &ids = timeline->getPropertyIds();
Array result; Array result;
result.resize(ids.size()); SPINE_CHECK(timeline, result)
auto &ids = timeline->getPropertyIds();
for (size_t i = 0; i < result.size(); ++i) { result.resize((int)ids.size());
for (int i = 0; i < result.size(); ++i) {
result[i] = (int64_t) ids[i]; result[i] = (int64_t) ids[i];
} }
return result; return result;
} }
String SpineTimeline::get_type() { String SpineTimeline::get_type() {
SPINE_CHECK(timeline, "")
return timeline->getRTTI().getClassName(); return timeline->getRTTI().getClassName();
} }

View File

@ -30,15 +30,15 @@
#ifndef GODOT_SPINETIMELINE_H #ifndef GODOT_SPINETIMELINE_H
#define GODOT_SPINETIMELINE_H #define GODOT_SPINETIMELINE_H
#include "spine/Timeline.h" #include "SpineCommon.h"
#include "SpineConstant.h" #include "SpineConstant.h"
#include "core/reference.h" #include <spine/Timeline.h>
class SpineSkeleton; class SpineSkeleton;
class SpineEvent; class SpineEvent;
class SpineTimeline : public Reference { class SpineTimeline : public REFCOUNTED {
GDCLASS(SpineTimeline, Reference); GDCLASS(SpineTimeline, REFCOUNTED);
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -48,16 +48,15 @@ private:
public: public:
SpineTimeline(); SpineTimeline();
~SpineTimeline();
inline void set_spine_object(spine::Timeline *timeline) { this->timeline = timeline; } void set_spine_object(spine::Timeline *_timeline) { this->timeline = _timeline; }
inline spine::Timeline *get_spine_object() { return timeline; } spine::Timeline *get_spine_object() { return timeline; }
void apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, Array events, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction); void apply(Ref<SpineSkeleton> skeleton, float last_time, float time, Array events, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction);
int64_t get_frame_entries(); int get_frame_entries();
int64_t get_frame_count(); int get_frame_count();
Array get_frames(); Array get_frames();

View File

@ -28,238 +28,305 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineTrackEntry.h" #include "SpineTrackEntry.h"
#include "SpineCommon.h"
void SpineTrackEntry::_bind_methods() { void SpineTrackEntry::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_track_index"), &SpineTrackEntry::get_track_index); ClassDB::bind_method(D_METHOD("get_track_index"), &SpineTrackEntry::get_track_index);
ClassDB::bind_method(D_METHOD("get_animation"), &SpineTrackEntry::get_animation); ClassDB::bind_method(D_METHOD("get_animation"), &SpineTrackEntry::get_animation);
ClassDB::bind_method(D_METHOD("get_previous"), &SpineTrackEntry::get_previous);
ClassDB::bind_method(D_METHOD("get_loop"), &SpineTrackEntry::get_loop); ClassDB::bind_method(D_METHOD("get_loop"), &SpineTrackEntry::get_loop);
ClassDB::bind_method(D_METHOD("set_loop", "v"), &SpineTrackEntry::set_loop); ClassDB::bind_method(D_METHOD("set_loop", "v"), &SpineTrackEntry::set_loop);
ClassDB::bind_method(D_METHOD("get_hold_previous"), &SpineTrackEntry::get_hold_previous); ClassDB::bind_method(D_METHOD("get_hold_previous"), &SpineTrackEntry::get_hold_previous);
ClassDB::bind_method(D_METHOD("set_hold_previous", "v"), &SpineTrackEntry::set_hold_previous); ClassDB::bind_method(D_METHOD("set_hold_previous", "v"), &SpineTrackEntry::set_hold_previous);
ClassDB::bind_method(D_METHOD("get_reverse"), &SpineTrackEntry::get_reverse); ClassDB::bind_method(D_METHOD("get_reverse"), &SpineTrackEntry::get_reverse);
ClassDB::bind_method(D_METHOD("set_reverse", "v"), &SpineTrackEntry::set_reverse); ClassDB::bind_method(D_METHOD("set_reverse", "v"), &SpineTrackEntry::set_reverse);
ClassDB::bind_method(D_METHOD("get_shortest_rotation"), &SpineTrackEntry::get_shortest_rotation);
ClassDB::bind_method(D_METHOD("set_shortest_rotation", "v"), &SpineTrackEntry::set_shortest_rotation);
ClassDB::bind_method(D_METHOD("get_delay"), &SpineTrackEntry::get_delay); ClassDB::bind_method(D_METHOD("get_delay"), &SpineTrackEntry::get_delay);
ClassDB::bind_method(D_METHOD("set_delay", "v"), &SpineTrackEntry::set_delay); ClassDB::bind_method(D_METHOD("set_delay", "v"), &SpineTrackEntry::set_delay);
ClassDB::bind_method(D_METHOD("get_track_time"), &SpineTrackEntry::get_track_time); ClassDB::bind_method(D_METHOD("get_track_time"), &SpineTrackEntry::get_track_time);
ClassDB::bind_method(D_METHOD("set_track_time", "v"), &SpineTrackEntry::set_track_time); ClassDB::bind_method(D_METHOD("set_track_time", "v"), &SpineTrackEntry::set_track_time);
ClassDB::bind_method(D_METHOD("get_track_end"), &SpineTrackEntry::get_track_end); ClassDB::bind_method(D_METHOD("get_track_end"), &SpineTrackEntry::get_track_end);
ClassDB::bind_method(D_METHOD("set_track_end", "v"), &SpineTrackEntry::set_track_end); ClassDB::bind_method(D_METHOD("set_track_end", "v"), &SpineTrackEntry::set_track_end);
ClassDB::bind_method(D_METHOD("get_animation_start"), &SpineTrackEntry::get_animation_start); ClassDB::bind_method(D_METHOD("get_animation_start"), &SpineTrackEntry::get_animation_start);
ClassDB::bind_method(D_METHOD("set_animation_start", "v"), &SpineTrackEntry::set_animation_start); ClassDB::bind_method(D_METHOD("set_animation_start", "v"), &SpineTrackEntry::set_animation_start);
ClassDB::bind_method(D_METHOD("get_animation_end"), &SpineTrackEntry::get_animation_end);
ClassDB::bind_method(D_METHOD("set_animation_end", "v"), &SpineTrackEntry::set_animation_end);
ClassDB::bind_method(D_METHOD("get_animation_last"), &SpineTrackEntry::get_animation_last); ClassDB::bind_method(D_METHOD("get_animation_last"), &SpineTrackEntry::get_animation_last);
ClassDB::bind_method(D_METHOD("set_animation_last", "v"), &SpineTrackEntry::set_animation_last); ClassDB::bind_method(D_METHOD("set_animation_last", "v"), &SpineTrackEntry::set_animation_last);
ClassDB::bind_method(D_METHOD("get_animation_time"), &SpineTrackEntry::get_animation_time); ClassDB::bind_method(D_METHOD("get_animation_time"), &SpineTrackEntry::get_animation_time);
ClassDB::bind_method(D_METHOD("get_time_scale"), &SpineTrackEntry::get_time_scale); ClassDB::bind_method(D_METHOD("get_time_scale"), &SpineTrackEntry::get_time_scale);
ClassDB::bind_method(D_METHOD("set_time_scale", "v"), &SpineTrackEntry::set_time_scale); ClassDB::bind_method(D_METHOD("set_time_scale", "v"), &SpineTrackEntry::set_time_scale);
ClassDB::bind_method(D_METHOD("get_alpha"), &SpineTrackEntry::get_alpha); ClassDB::bind_method(D_METHOD("get_alpha"), &SpineTrackEntry::get_alpha);
ClassDB::bind_method(D_METHOD("set_alpha", "v"), &SpineTrackEntry::set_alpha); ClassDB::bind_method(D_METHOD("set_alpha", "v"), &SpineTrackEntry::set_alpha);
ClassDB::bind_method(D_METHOD("get_event_threshold"), &SpineTrackEntry::get_event_threshold); ClassDB::bind_method(D_METHOD("get_event_threshold"), &SpineTrackEntry::get_event_threshold);
ClassDB::bind_method(D_METHOD("set_event_threshold", "v"), &SpineTrackEntry::set_event_threshold); ClassDB::bind_method(D_METHOD("set_event_threshold", "v"), &SpineTrackEntry::set_event_threshold);
ClassDB::bind_method(D_METHOD("get_attachment_threshold"), &SpineTrackEntry::get_attachment_threshold); ClassDB::bind_method(D_METHOD("get_attachment_threshold"), &SpineTrackEntry::get_attachment_threshold);
ClassDB::bind_method(D_METHOD("set_attachment_threshold", "v"), &SpineTrackEntry::set_attachment_threshold); ClassDB::bind_method(D_METHOD("set_attachment_threshold", "v"), &SpineTrackEntry::set_attachment_threshold);
ClassDB::bind_method(D_METHOD("get_draw_order_threshold"), &SpineTrackEntry::get_draw_order_threshold); ClassDB::bind_method(D_METHOD("get_draw_order_threshold"), &SpineTrackEntry::get_draw_order_threshold);
ClassDB::bind_method(D_METHOD("set_draw_order_threshold", "v"), &SpineTrackEntry::set_draw_order_threshold); ClassDB::bind_method(D_METHOD("set_draw_order_threshold", "v"), &SpineTrackEntry::set_draw_order_threshold);
ClassDB::bind_method(D_METHOD("get_next"), &SpineTrackEntry::get_next); ClassDB::bind_method(D_METHOD("get_next"), &SpineTrackEntry::get_next);
ClassDB::bind_method(D_METHOD("is_complete"), &SpineTrackEntry::is_complete); ClassDB::bind_method(D_METHOD("is_complete"), &SpineTrackEntry::is_complete);
ClassDB::bind_method(D_METHOD("get_mix_time"), &SpineTrackEntry::get_mix_time); ClassDB::bind_method(D_METHOD("get_mix_time"), &SpineTrackEntry::get_mix_time);
ClassDB::bind_method(D_METHOD("set_mix_time", "v"), &SpineTrackEntry::set_mix_time); ClassDB::bind_method(D_METHOD("set_mix_time", "v"), &SpineTrackEntry::set_mix_time);
ClassDB::bind_method(D_METHOD("get_mix_duration"), &SpineTrackEntry::get_mix_duration); ClassDB::bind_method(D_METHOD("get_mix_duration"), &SpineTrackEntry::get_mix_duration);
ClassDB::bind_method(D_METHOD("set_mix_duration", "v"), &SpineTrackEntry::set_mix_duration); ClassDB::bind_method(D_METHOD("set_mix_duration", "v"), &SpineTrackEntry::set_mix_duration);
ClassDB::bind_method(D_METHOD("get_mix_blend"), &SpineTrackEntry::get_mix_blend); ClassDB::bind_method(D_METHOD("get_mix_blend"), &SpineTrackEntry::get_mix_blend);
ClassDB::bind_method(D_METHOD("set_mix_blend", "v"), &SpineTrackEntry::set_mix_blend); ClassDB::bind_method(D_METHOD("set_mix_blend", "v"), &SpineTrackEntry::set_mix_blend);
ClassDB::bind_method(D_METHOD("get_mixing_from"), &SpineTrackEntry::get_mixing_from); ClassDB::bind_method(D_METHOD("get_mixing_from"), &SpineTrackEntry::get_mixing_from);
ClassDB::bind_method(D_METHOD("get_mixing_to"), &SpineTrackEntry::get_mixing_to); ClassDB::bind_method(D_METHOD("get_mixing_to"), &SpineTrackEntry::get_mixing_to);
ClassDB::bind_method(D_METHOD("reset_rotation_directions"), &SpineTrackEntry::reset_rotation_directions); ClassDB::bind_method(D_METHOD("reset_rotation_directions"), &SpineTrackEntry::reset_rotation_directions);
ClassDB::bind_method(D_METHOD("get_track_complete"), &SpineTrackEntry::get_track_complete);
BIND_ENUM_CONSTANT(MIXBLEND_SETUP);
BIND_ENUM_CONSTANT(MIXBLEND_FIRST);
BIND_ENUM_CONSTANT(MIXBLEND_REPLACE);
BIND_ENUM_CONSTANT(MIXBLEND_ADD);
} }
SpineTrackEntry::SpineTrackEntry() : track_entry(NULL) {} SpineTrackEntry::SpineTrackEntry() : track_entry(nullptr) {
SpineTrackEntry::~SpineTrackEntry() {} }
int SpineTrackEntry::get_track_index() { int SpineTrackEntry::get_track_index() {
SPINE_CHECK(track_entry, 0)
return track_entry->getTrackIndex(); return track_entry->getTrackIndex();
} }
Ref<SpineAnimation> SpineTrackEntry::get_animation() { Ref<SpineAnimation> SpineTrackEntry::get_animation() {
Ref<SpineAnimation> gd_anim(memnew(SpineAnimation)); SPINE_CHECK(track_entry, nullptr)
auto anim = track_entry->getAnimation(); auto animation = track_entry->getAnimation();
if (anim == NULL) return NULL; if (!animation) return nullptr;
gd_anim->set_spine_object(anim); Ref<SpineAnimation> animation_ref(memnew(SpineAnimation));
return gd_anim; animation_ref->set_spine_object(animation);
return animation_ref;
}
Ref<SpineTrackEntry> SpineTrackEntry::get_previous() {
SPINE_CHECK(track_entry, nullptr)
auto previous = track_entry->getPrevious();
if (!previous) return nullptr;
Ref<SpineTrackEntry> previous_ref(memnew(SpineTrackEntry));
previous_ref->set_spine_object(previous);
return previous_ref;
} }
bool SpineTrackEntry::get_loop() { bool SpineTrackEntry::get_loop() {
SPINE_CHECK(track_entry, false)
return track_entry->getLoop(); return track_entry->getLoop();
} }
void SpineTrackEntry::set_loop(bool v) { void SpineTrackEntry::set_loop(bool v) {
SPINE_CHECK(track_entry,)
track_entry->setLoop(v); track_entry->setLoop(v);
} }
bool SpineTrackEntry::get_hold_previous() { bool SpineTrackEntry::get_hold_previous() {
SPINE_CHECK(track_entry, false)
return track_entry->getHoldPrevious(); return track_entry->getHoldPrevious();
} }
void SpineTrackEntry::set_hold_previous(bool v) { void SpineTrackEntry::set_hold_previous(bool v) {
SPINE_CHECK(track_entry,)
track_entry->setHoldPrevious(v); track_entry->setHoldPrevious(v);
} }
float SpineTrackEntry::get_delay() {
return track_entry->getDelay();
}
void SpineTrackEntry::set_delay(float v) {
track_entry->setDelay(v);
}
float SpineTrackEntry::get_track_time() {
return track_entry->getTrackTime();
}
void SpineTrackEntry::set_track_time(float v) {
track_entry->setTrackTime(v);
}
float SpineTrackEntry::get_track_end() {
return track_entry->getTrackEnd();
}
void SpineTrackEntry::set_track_end(float v) {
track_entry->setTrackEnd(v);
}
float SpineTrackEntry::get_animation_start() {
return track_entry->getAnimationStart();
}
void SpineTrackEntry::set_animation_start(float v) {
track_entry->setAnimationStart(v);
}
float SpineTrackEntry::get_animation_last() {
return track_entry->getAnimationLast();
}
void SpineTrackEntry::set_animation_last(float v) {
track_entry->setAnimationLast(v);
}
float SpineTrackEntry::get_animation_time() {
return track_entry->getAnimationTime();
}
float SpineTrackEntry::get_time_scale() {
return track_entry->getTimeScale();
}
void SpineTrackEntry::set_time_scale(float v) {
track_entry->setTimeScale(v);
}
float SpineTrackEntry::get_alpha() {
return track_entry->getAlpha();
}
void SpineTrackEntry::set_alpha(float v) {
track_entry->setAlpha(v);
}
float SpineTrackEntry::get_event_threshold() {
return track_entry->getEventThreshold();
}
void SpineTrackEntry::set_event_threshold(float v) {
track_entry->setEventThreshold(v);
}
float SpineTrackEntry::get_attachment_threshold() {
return track_entry->getAttachmentThreshold();
}
void SpineTrackEntry::set_attachment_threshold(float v) {
track_entry->setAttachmentThreshold(v);
}
float SpineTrackEntry::get_draw_order_threshold() {
return track_entry->getDrawOrderThreshold();
}
void SpineTrackEntry::set_draw_order_threshold(float v) {
track_entry->setDrawOrderThreshold(v);
}
Ref<SpineTrackEntry> SpineTrackEntry::get_next() {
Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry));
auto entry = track_entry->getNext();
if (entry == NULL) return NULL;
gd_entry->set_spine_object(entry);
return gd_entry;
}
bool SpineTrackEntry::is_complete() {
return track_entry->isComplete();
}
float SpineTrackEntry::get_mix_time() {
return track_entry->getMixTime();
}
void SpineTrackEntry::set_mix_time(float v) {
track_entry->setMixTime(v);
}
float SpineTrackEntry::get_mix_duration() {
return track_entry->getMixDuration();
}
void SpineTrackEntry::set_mix_duration(float v) {
track_entry->setMixDuration(v);
}
SpineTrackEntry::MixBlend SpineTrackEntry::get_mix_blend() {
int mb = track_entry->getMixBlend();
return (MixBlend) mb;
}
void SpineTrackEntry::set_mix_blend(SpineTrackEntry::MixBlend v) {
int mb = (int) v;
track_entry->setMixBlend((spine::MixBlend) mb);
}
Ref<SpineTrackEntry> SpineTrackEntry::get_mixing_from() {
Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry));
auto entry = track_entry->getMixingFrom();
if (entry == NULL) return NULL;
gd_entry->set_spine_object(entry);
return gd_entry;
}
Ref<SpineTrackEntry> SpineTrackEntry::get_mixing_to() {
Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry));
auto entry = track_entry->getMixingTo();
if (entry == NULL) return NULL;
gd_entry->set_spine_object(entry);
return gd_entry;
}
void SpineTrackEntry::reset_rotation_directions() {
track_entry->resetRotationDirections();
}
bool SpineTrackEntry::get_reverse() { bool SpineTrackEntry::get_reverse() {
SPINE_CHECK(track_entry, false)
return track_entry->getReverse(); return track_entry->getReverse();
} }
void SpineTrackEntry::set_reverse(bool v) { void SpineTrackEntry::set_reverse(bool v) {
SPINE_CHECK(track_entry,)
track_entry->setReverse(v); track_entry->setReverse(v);
} }
bool SpineTrackEntry::get_shortest_rotation() {
SPINE_CHECK(track_entry, false)
return track_entry->getShortestRotation();
}
void SpineTrackEntry::set_shortest_rotation(bool v) {
SPINE_CHECK(track_entry,)
track_entry->setShortestRotation(v);
}
float SpineTrackEntry::get_delay() {
SPINE_CHECK(track_entry, 0)
return track_entry->getDelay();
}
void SpineTrackEntry::set_delay(float v) {
SPINE_CHECK(track_entry,)
track_entry->setDelay(v);
}
float SpineTrackEntry::get_track_time() {
SPINE_CHECK(track_entry, 0)
return track_entry->getTrackTime();
}
void SpineTrackEntry::set_track_time(float v) {
SPINE_CHECK(track_entry,)
track_entry->setTrackTime(v);
}
float SpineTrackEntry::get_track_end() {
SPINE_CHECK(track_entry, 0)
return track_entry->getTrackEnd();
}
void SpineTrackEntry::set_track_end(float v) {
SPINE_CHECK(track_entry,)
track_entry->setTrackEnd(v);
}
float SpineTrackEntry::get_animation_start() {
SPINE_CHECK(track_entry, 0)
return track_entry->getAnimationStart();
}
void SpineTrackEntry::set_animation_start(float v) {
SPINE_CHECK(track_entry,)
track_entry->setAnimationStart(v);
}
float SpineTrackEntry::get_animation_end() {
SPINE_CHECK(track_entry, 0)
return track_entry->getAnimationEnd();
}
void SpineTrackEntry::set_animation_end(float v) {
SPINE_CHECK(track_entry,)
track_entry->setAnimationEnd(v);
}
float SpineTrackEntry::get_animation_last() {
SPINE_CHECK(track_entry, 0)
return track_entry->getAnimationLast();
}
void SpineTrackEntry::set_animation_last(float v) {
SPINE_CHECK(track_entry,)
track_entry->setAnimationLast(v);
}
float SpineTrackEntry::get_animation_time() {
SPINE_CHECK(track_entry, 0)
return track_entry->getAnimationTime();
}
float SpineTrackEntry::get_time_scale() {
SPINE_CHECK(track_entry, 0)
return track_entry->getTimeScale();
}
void SpineTrackEntry::set_time_scale(float v) {
SPINE_CHECK(track_entry,)
track_entry->setTimeScale(v);
}
float SpineTrackEntry::get_alpha() {
SPINE_CHECK(track_entry, 0)
return track_entry->getAlpha();
}
void SpineTrackEntry::set_alpha(float v) {
SPINE_CHECK(track_entry,)
track_entry->setAlpha(v);
}
float SpineTrackEntry::get_event_threshold() {
SPINE_CHECK(track_entry, 0)
return track_entry->getEventThreshold();
}
void SpineTrackEntry::set_event_threshold(float v) {
SPINE_CHECK(track_entry,)
track_entry->setEventThreshold(v);
}
float SpineTrackEntry::get_attachment_threshold() {
SPINE_CHECK(track_entry, 0)
return track_entry->getAttachmentThreshold();
}
void SpineTrackEntry::set_attachment_threshold(float v) {
SPINE_CHECK(track_entry,)
track_entry->setAttachmentThreshold(v);
}
float SpineTrackEntry::get_draw_order_threshold() {
SPINE_CHECK(track_entry, 0)
return track_entry->getDrawOrderThreshold();
}
void SpineTrackEntry::set_draw_order_threshold(float v) {
SPINE_CHECK(track_entry,)
track_entry->setDrawOrderThreshold(v);
}
Ref<SpineTrackEntry> SpineTrackEntry::get_next() {
SPINE_CHECK(track_entry, nullptr)
auto next = track_entry->getNext();
if (!next) return nullptr;
Ref<SpineTrackEntry> next_ref(memnew(SpineTrackEntry));
next_ref->set_spine_object(next);
return next_ref;
}
bool SpineTrackEntry::is_complete() {
SPINE_CHECK(track_entry, false)
return track_entry->isComplete();
}
float SpineTrackEntry::get_mix_time() {
SPINE_CHECK(track_entry, 0)
return track_entry->getMixTime();
}
void SpineTrackEntry::set_mix_time(float v) {
SPINE_CHECK(track_entry,)
track_entry->setMixTime(v);
}
float SpineTrackEntry::get_mix_duration() {
SPINE_CHECK(track_entry, 0)
return track_entry->getMixDuration();
}
void SpineTrackEntry::set_mix_duration(float v) {
SPINE_CHECK(track_entry,)
track_entry->setMixDuration(v);
}
SpineConstant::MixBlend SpineTrackEntry::get_mix_blend() {
SPINE_CHECK(track_entry, SpineConstant::MixBlend_Setup)
return (SpineConstant::MixBlend)track_entry->getMixBlend();
}
void SpineTrackEntry::set_mix_blend(SpineConstant::MixBlend v) {
SPINE_CHECK(track_entry,)
track_entry->setMixBlend((spine::MixBlend) v);
}
Ref<SpineTrackEntry> SpineTrackEntry::get_mixing_from() {
SPINE_CHECK(track_entry, nullptr)
auto mixing_from = track_entry->getMixingFrom();
if (!mixing_from) return nullptr;
Ref<SpineTrackEntry> mixing_from_ref(memnew(SpineTrackEntry));
mixing_from_ref->set_spine_object(mixing_from);
return mixing_from_ref;
}
Ref<SpineTrackEntry> SpineTrackEntry::get_mixing_to() {
SPINE_CHECK(track_entry, nullptr)
auto mixing_to = track_entry->getMixingTo();
if (!mixing_to) return nullptr;
Ref<SpineTrackEntry> mixing_to_ref(memnew(SpineTrackEntry));
mixing_to_ref->set_spine_object(mixing_to);
return mixing_to_ref;
}
void SpineTrackEntry::reset_rotation_directions() {
SPINE_CHECK(track_entry,)
track_entry->resetRotationDirections();
}
float SpineTrackEntry::get_track_complete() {
SPINE_CHECK(track_entry, 0)
return track_entry->getTrackComplete();
}

View File

@ -30,14 +30,13 @@
#ifndef GODOT_SPINETRACKENTRY_H #ifndef GODOT_SPINETRACKENTRY_H
#define GODOT_SPINETRACKENTRY_H #define GODOT_SPINETRACKENTRY_H
#include "core/variant_parser.h" #include "SpineCommon.h"
#include <spine/spine.h>
#include "SpineAnimation.h" #include "SpineAnimation.h"
#include "SpineConstant.h"
#include <spine/AnimationState.h>
class SpineTrackEntry : public Reference { class SpineTrackEntry : public REFCOUNTED {
GDCLASS(SpineTrackEntry, Reference); GDCLASS(SpineTrackEntry, REFCOUNTED);
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -47,65 +46,76 @@ private:
public: public:
SpineTrackEntry(); SpineTrackEntry();
~SpineTrackEntry();
inline void set_spine_object(spine::TrackEntry *t) { void set_spine_object(spine::TrackEntry *_track_entry) { this->track_entry = _track_entry; }
track_entry = t; spine::TrackEntry *get_spine_object() { return track_entry; }
}
inline spine::TrackEntry *get_spine_object() {
return track_entry;
}
enum MixBlend {
MIXBLEND_SETUP = 0,
MIXBLEND_FIRST,
MIXBLEND_REPLACE,
MIXBLEND_ADD
};
int get_track_index(); int get_track_index();
Ref<SpineAnimation> get_animation(); Ref<SpineAnimation> get_animation();
Ref<SpineTrackEntry> get_previous();
bool get_loop(); bool get_loop();
void set_loop(bool v); void set_loop(bool v);
bool get_hold_previous(); bool get_hold_previous();
void set_hold_previous(bool v); void set_hold_previous(bool v);
bool get_reverse(); bool get_reverse();
void set_reverse(bool v); void set_reverse(bool v);
bool get_shortest_rotation();
void set_shortest_rotation(bool v);
float get_delay(); float get_delay();
void set_delay(float v); void set_delay(float v);
float get_track_time(); float get_track_time();
void set_track_time(float v); void set_track_time(float v);
float get_track_end(); float get_track_end();
void set_track_end(float v); void set_track_end(float v);
float get_animation_start(); float get_animation_start();
void set_animation_start(float v); void set_animation_start(float v);
float get_animation_end();
void set_animation_end(float v);
float get_animation_last(); float get_animation_last();
void set_animation_last(float v); void set_animation_last(float v);
float get_animation_time(); float get_animation_time();
float get_time_scale(); float get_time_scale();
void set_time_scale(float v); void set_time_scale(float v);
float get_alpha(); float get_alpha();
void set_alpha(float v); void set_alpha(float v);
float get_event_threshold(); float get_event_threshold();
void set_event_threshold(float v); void set_event_threshold(float v);
float get_attachment_threshold(); float get_attachment_threshold();
void set_attachment_threshold(float v); void set_attachment_threshold(float v);
float get_draw_order_threshold(); float get_draw_order_threshold();
void set_draw_order_threshold(float v); void set_draw_order_threshold(float v);
Ref<SpineTrackEntry> get_next(); Ref<SpineTrackEntry> get_next();
@ -113,19 +123,24 @@ public:
bool is_complete(); bool is_complete();
float get_mix_time(); float get_mix_time();
void set_mix_time(float v); void set_mix_time(float v);
float get_mix_duration(); float get_mix_duration();
void set_mix_duration(float v); void set_mix_duration(float v);
MixBlend get_mix_blend(); SpineConstant::MixBlend get_mix_blend();
void set_mix_blend(MixBlend v);
void set_mix_blend(SpineConstant::MixBlend v);
Ref<SpineTrackEntry> get_mixing_from(); Ref<SpineTrackEntry> get_mixing_from();
Ref<SpineTrackEntry> get_mixing_to(); Ref<SpineTrackEntry> get_mixing_to();
void reset_rotation_directions(); void reset_rotation_directions();
float get_track_complete();
}; };
VARIANT_ENUM_CAST(SpineTrackEntry::MixBlend);
#endif//GODOT_SPINETRACKENTRY_H #endif//GODOT_SPINETRACKENTRY_H

View File

@ -28,6 +28,7 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineTransformConstraint.h" #include "SpineTransformConstraint.h"
#include "SpineCommon.h"
void SpineTransformConstraint::_bind_methods() { void SpineTransformConstraint::_bind_methods() {
ClassDB::bind_method(D_METHOD("update"), &SpineTransformConstraint::update); ClassDB::bind_method(D_METHOD("update"), &SpineTransformConstraint::update);
@ -51,98 +52,121 @@ void SpineTransformConstraint::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_active", "v"), &SpineTransformConstraint::set_active); ClassDB::bind_method(D_METHOD("set_active", "v"), &SpineTransformConstraint::set_active);
} }
SpineTransformConstraint::SpineTransformConstraint() : transform_constraint(NULL) {} SpineTransformConstraint::SpineTransformConstraint() : transform_constraint(nullptr) {
SpineTransformConstraint::~SpineTransformConstraint() {} }
void SpineTransformConstraint::update() { void SpineTransformConstraint::update() {
SPINE_CHECK(transform_constraint,)
transform_constraint->update(); transform_constraint->update();
} }
int SpineTransformConstraint::get_order() { int SpineTransformConstraint::get_order() {
SPINE_CHECK(transform_constraint, 0)
return transform_constraint->getOrder(); return transform_constraint->getOrder();
} }
Ref<SpineTransformConstraintData> SpineTransformConstraint::get_data() { Ref<SpineTransformConstraintData> SpineTransformConstraint::get_data() {
auto &d = transform_constraint->getData(); SPINE_CHECK(transform_constraint, nullptr)
Ref<SpineTransformConstraintData> gd_d(memnew(SpineTransformConstraintData)); auto &data = transform_constraint->getData();
gd_d->set_spine_object(&d); Ref<SpineTransformConstraintData> data_ref(memnew(SpineTransformConstraintData));
return gd_d; data_ref->set_spine_object(&data);
return data_ref;
} }
Array SpineTransformConstraint::get_bones() { Array SpineTransformConstraint::get_bones() {
auto &bs = transform_constraint->getBones(); Array result;
Array gd_bs; SPINE_CHECK(transform_constraint, result)
gd_bs.resize(bs.size()); auto &bones = transform_constraint->getBones();
for (size_t i = 0; i < bs.size(); ++i) { result.resize((int)bones.size());
auto b = bs[i]; for (int i = 0; i < bones.size(); ++i) {
if (b == NULL) gd_bs[i] = Ref<SpineBone>(NULL); auto bone = bones[i];
Ref<SpineBone> gd_b(memnew(SpineBone)); Ref<SpineBone> bone_ref(memnew(SpineBone));
gd_b->set_spine_object(b); bone_ref->set_spine_object(bone);
gd_bs[i] = gd_b; result[i] = bone_ref;
} }
return gd_bs; return result;
} }
Ref<SpineBone> SpineTransformConstraint::get_target() { Ref<SpineBone> SpineTransformConstraint::get_target() {
auto b = transform_constraint->getTarget(); SPINE_CHECK(transform_constraint, nullptr)
if (b == NULL) return NULL; auto target = transform_constraint->getTarget();
Ref<SpineBone> gd_b(memnew(SpineBone)); if (!target) return nullptr;
gd_b->set_spine_object(b); Ref<SpineBone> target_ref(memnew(SpineBone));
return gd_b; target_ref->set_spine_object(target);
return target_ref;
} }
void SpineTransformConstraint::set_target(Ref<SpineBone> v) { void SpineTransformConstraint::set_target(Ref<SpineBone> v) {
if (v.is_valid()) { SPINE_CHECK(transform_constraint,)
transform_constraint->setTarget(v->get_spine_object()); transform_constraint->setTarget(v.is_valid() ? v->get_spine_object() : nullptr);
} else {
transform_constraint->setTarget(NULL);
}
} }
float SpineTransformConstraint::get_mix_rotate() { float SpineTransformConstraint::get_mix_rotate() {
SPINE_CHECK(transform_constraint, 0)
return transform_constraint->getMixRotate(); return transform_constraint->getMixRotate();
} }
void SpineTransformConstraint::set_mix_rotate(float v) { void SpineTransformConstraint::set_mix_rotate(float v) {
SPINE_CHECK(transform_constraint,)
transform_constraint->setMixRotate(v); transform_constraint->setMixRotate(v);
} }
float SpineTransformConstraint::get_mix_x() { float SpineTransformConstraint::get_mix_x() {
SPINE_CHECK(transform_constraint, 0)
return transform_constraint->getMixX(); return transform_constraint->getMixX();
} }
void SpineTransformConstraint::set_mix_x(float v) { void SpineTransformConstraint::set_mix_x(float v) {
SPINE_CHECK(transform_constraint,)
transform_constraint->setMixX(v); transform_constraint->setMixX(v);
} }
float SpineTransformConstraint::get_mix_y() { float SpineTransformConstraint::get_mix_y() {
SPINE_CHECK(transform_constraint, 0)
return transform_constraint->getMixY(); return transform_constraint->getMixY();
} }
void SpineTransformConstraint::set_mix_y(float v) { void SpineTransformConstraint::set_mix_y(float v) {
SPINE_CHECK(transform_constraint,)
transform_constraint->setMixY(v); transform_constraint->setMixY(v);
} }
float SpineTransformConstraint::get_mix_scale_x() { float SpineTransformConstraint::get_mix_scale_x() {
SPINE_CHECK(transform_constraint, 0)
return transform_constraint->getMixScaleX(); return transform_constraint->getMixScaleX();
} }
void SpineTransformConstraint::set_mix_scale_x(float v) { void SpineTransformConstraint::set_mix_scale_x(float v) {
SPINE_CHECK(transform_constraint,)
transform_constraint->setMixScaleX(v); transform_constraint->setMixScaleX(v);
} }
float SpineTransformConstraint::get_mix_scale_y() { float SpineTransformConstraint::get_mix_scale_y() {
SPINE_CHECK(transform_constraint, 0)
return transform_constraint->getMixScaleY(); return transform_constraint->getMixScaleY();
} }
void SpineTransformConstraint::set_mix_scale_y(float v) { void SpineTransformConstraint::set_mix_scale_y(float v) {
SPINE_CHECK(transform_constraint,)
transform_constraint->setMixScaleY(v); transform_constraint->setMixScaleY(v);
} }
float SpineTransformConstraint::get_mix_shear_y() { float SpineTransformConstraint::get_mix_shear_y() {
SPINE_CHECK(transform_constraint, 0)
return transform_constraint->getMixShearY(); return transform_constraint->getMixShearY();
} }
void SpineTransformConstraint::set_mix_shear_y(float v) { void SpineTransformConstraint::set_mix_shear_y(float v) {
SPINE_CHECK(transform_constraint,)
transform_constraint->setMixShearY(v); transform_constraint->setMixShearY(v);
} }
bool SpineTransformConstraint::is_active() { bool SpineTransformConstraint::is_active() {
SPINE_CHECK(transform_constraint, false)
return transform_constraint->isActive(); return transform_constraint->isActive();
} }
void SpineTransformConstraint::set_active(bool v) { void SpineTransformConstraint::set_active(bool v) {
SPINE_CHECK(transform_constraint,)
transform_constraint->setActive(v); transform_constraint->setActive(v);
} }

View File

@ -30,15 +30,13 @@
#ifndef GODOT_SPINETRANSFORMCONSTRAINT_H #ifndef GODOT_SPINETRANSFORMCONSTRAINT_H
#define GODOT_SPINETRANSFORMCONSTRAINT_H #define GODOT_SPINETRANSFORMCONSTRAINT_H
#include "core/variant_parser.h" #include "SpineCommon.h"
#include <spine/spine.h>
#include "SpineTransformConstraintData.h" #include "SpineTransformConstraintData.h"
#include "SpineBone.h" #include "SpineBone.h"
#include <spine/TransformConstraint.h>
class SpineTransformConstraint : public Reference { class SpineTransformConstraint : public REFCOUNTED {
GDCLASS(SpineTransformConstraint, Reference); GDCLASS(SpineTransformConstraint, REFCOUNTED);
protected: protected:
static void _bind_methods(); static void _bind_methods();
@ -48,14 +46,9 @@ private:
public: public:
SpineTransformConstraint(); SpineTransformConstraint();
~SpineTransformConstraint();
inline void set_spine_object(spine::TransformConstraint *tc) { void set_spine_object(spine::TransformConstraint *tc) { transform_constraint = tc; }
transform_constraint = tc; spine::TransformConstraint *get_spine_object() { return transform_constraint; }
}
inline spine::TransformConstraint *get_spine_object() {
return transform_constraint;
}
void update(); void update();
@ -66,27 +59,35 @@ public:
Array get_bones(); Array get_bones();
Ref<SpineBone> get_target(); Ref<SpineBone> get_target();
void set_target(Ref<SpineBone> v); void set_target(Ref<SpineBone> v);
float get_mix_rotate(); float get_mix_rotate();
void set_mix_rotate(float v); void set_mix_rotate(float v);
float get_mix_x(); float get_mix_x();
void set_mix_x(float v); void set_mix_x(float v);
float get_mix_y(); float get_mix_y();
void set_mix_y(float v); void set_mix_y(float v);
float get_mix_scale_x(); float get_mix_scale_x();
void set_mix_scale_x(float v); void set_mix_scale_x(float v);
float get_mix_scale_y(); float get_mix_scale_y();
void set_mix_scale_y(float v); void set_mix_scale_y(float v);
float get_mix_shear_y(); float get_mix_shear_y();
void set_mix_shear_y(float v); void set_mix_shear_y(float v);
bool is_active(); bool is_active();
void set_active(bool v); void set_active(bool v);
}; };

View File

@ -28,9 +28,10 @@
*****************************************************************************/ *****************************************************************************/
#include "SpineTransformConstraintData.h" #include "SpineTransformConstraintData.h"
#include "SpineCommon.h"
void SpineTransformConstraintData::_bind_methods() { void SpineTransformConstraintData::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_all_bone_data"), &SpineTransformConstraintData::get_bones); ClassDB::bind_method(D_METHOD("get_bones"), &SpineTransformConstraintData::get_bones);
ClassDB::bind_method(D_METHOD("get_target"), &SpineTransformConstraintData::get_target); ClassDB::bind_method(D_METHOD("get_target"), &SpineTransformConstraintData::get_target);
ClassDB::bind_method(D_METHOD("get_mix_rotate"), &SpineTransformConstraintData::get_mix_rotate); ClassDB::bind_method(D_METHOD("get_mix_rotate"), &SpineTransformConstraintData::get_mix_rotate);
ClassDB::bind_method(D_METHOD("get_mix_x"), &SpineTransformConstraintData::get_mix_x); ClassDB::bind_method(D_METHOD("get_mix_x"), &SpineTransformConstraintData::get_mix_x);
@ -48,71 +49,94 @@ void SpineTransformConstraintData::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_local"), &SpineTransformConstraintData::is_local); ClassDB::bind_method(D_METHOD("is_local"), &SpineTransformConstraintData::is_local);
} }
SpineTransformConstraintData::SpineTransformConstraintData() {}
SpineTransformConstraintData::~SpineTransformConstraintData() {}
Array SpineTransformConstraintData::get_bones() { Array SpineTransformConstraintData::get_bones() {
auto bs = get_spine_data()->getBones(); Array result;
Array gd_bs; SPINE_CHECK(get_spine_constraint_data(), result)
gd_bs.resize(bs.size()); auto bones = get_spine_constraint_data()->getBones();
for (size_t i = 0; i < bs.size(); ++i) { result.resize((int)bones.size());
if (bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL); for (int i = 0; i < bones.size(); ++i) {
else { Ref<SpineBoneData> bone_ref(memnew(SpineBoneData));
Ref<SpineBoneData> gd_b(memnew(SpineBoneData)); bone_ref->set_spine_object(bones[i]);
gd_b->set_spine_object(bs[i]); result[i] = bone_ref;
gd_bs[i] = gd_b;
}
} }
return gd_bs; return result;
} }
Ref<SpineBoneData> SpineTransformConstraintData::get_target() { Ref<SpineBoneData> SpineTransformConstraintData::get_target() {
auto b = get_spine_data()->getTarget(); SPINE_CHECK(get_spine_constraint_data(), nullptr)
if (b == NULL) return NULL; auto bone = get_spine_constraint_data()->getTarget();
Ref<SpineBoneData> gd_b(memnew(SpineBoneData)); if (!bone) return nullptr;
gd_b->set_spine_object(b); Ref<SpineBoneData> slot_ref(memnew(SpineBoneData));
return gd_b; slot_ref->set_spine_object(bone);
return slot_ref;
} }
float SpineTransformConstraintData::get_mix_rotate() { float SpineTransformConstraintData::get_mix_rotate() {
return get_spine_data()->getMixRotate(); SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getMixRotate();
} }
float SpineTransformConstraintData::get_mix_x() { float SpineTransformConstraintData::get_mix_x() {
return get_spine_data()->getMixX(); SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getMixX();
} }
float SpineTransformConstraintData::get_mix_y() { float SpineTransformConstraintData::get_mix_y() {
return get_spine_data()->getMixY(); SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getMixY();
} }
float SpineTransformConstraintData::get_mix_scale_x() { float SpineTransformConstraintData::get_mix_scale_x() {
return get_spine_data()->getMixScaleX(); SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getMixScaleX();
} }
float SpineTransformConstraintData::get_mix_scale_y() { float SpineTransformConstraintData::get_mix_scale_y() {
return get_spine_data()->getMixScaleY(); SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getMixScaleY();
} }
float SpineTransformConstraintData::get_mix_shear_y() { float SpineTransformConstraintData::get_mix_shear_y() {
return get_spine_data()->getMixShearY(); SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getMixShearY();
} }
float SpineTransformConstraintData::get_offset_rotation() { float SpineTransformConstraintData::get_offset_rotation() {
return get_spine_data()->getOffsetRotation(); SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getOffsetRotation();
} }
float SpineTransformConstraintData::get_offset_x() { float SpineTransformConstraintData::get_offset_x() {
return get_spine_data()->getOffsetX(); SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getOffsetX();
} }
float SpineTransformConstraintData::get_offset_y() { float SpineTransformConstraintData::get_offset_y() {
return get_spine_data()->getOffsetY(); SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getOffsetY();
} }
float SpineTransformConstraintData::get_offset_scale_x() { float SpineTransformConstraintData::get_offset_scale_x() {
return get_spine_data()->getOffsetScaleX(); SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getOffsetScaleX();
} }
float SpineTransformConstraintData::get_offset_scale_y() { float SpineTransformConstraintData::get_offset_scale_y() {
return get_spine_data()->getOffsetScaleY(); SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getOffsetScaleY();
} }
float SpineTransformConstraintData::get_offset_shear_y() { float SpineTransformConstraintData::get_offset_shear_y() {
return get_spine_data()->getOffsetShearY(); SPINE_CHECK(get_spine_constraint_data(), 0)
return get_spine_constraint_data()->getOffsetShearY();
} }
bool SpineTransformConstraintData::is_relative() { bool SpineTransformConstraintData::is_relative() {
return get_spine_data()->isRelative(); SPINE_CHECK(get_spine_constraint_data(), false)
return get_spine_constraint_data()->isRelative();
} }
bool SpineTransformConstraintData::is_local() { bool SpineTransformConstraintData::is_local() {
return get_spine_data()->isLocal(); SPINE_CHECK(get_spine_constraint_data(), false)
return get_spine_constraint_data()->isLocal();
} }

View File

@ -30,44 +30,49 @@
#ifndef GODOT_SPINETRANSFORMCONSTRAINTDATA_H #ifndef GODOT_SPINETRANSFORMCONSTRAINTDATA_H
#define GODOT_SPINETRANSFORMCONSTRAINTDATA_H #define GODOT_SPINETRANSFORMCONSTRAINTDATA_H
#include "core/variant_parser.h"
#include <spine/spine.h>
#include "SpineConstraintData.h" #include "SpineConstraintData.h"
#include "SpineBoneData.h" #include "SpineBoneData.h"
#include <spine/TransformConstraintData.h>
class SpineTransformConstraintData : public SpineConstraintData { class SpineTransformConstraintData : public SpineConstraintData {
GDCLASS(SpineTransformConstraintData, SpineConstraintData); GDCLASS(SpineTransformConstraintData, SpineConstraintData);
spine::TransformConstraintData *get_spine_constraint_data() { return (spine::TransformConstraintData *) SpineConstraintData::get_spine_object(); }
protected: protected:
static void _bind_methods(); static void _bind_methods();
public: public:
SpineTransformConstraintData();
~SpineTransformConstraintData();
virtual inline spine::TransformConstraintData *get_spine_data() {
return (spine::TransformConstraintData *) SpineConstraintData::get_spine_object();
}
Array get_bones(); Array get_bones();
Ref<SpineBoneData> get_target(); Ref<SpineBoneData> get_target();
float get_mix_rotate(); float get_mix_rotate();
float get_mix_x(); float get_mix_x();
float get_mix_y(); float get_mix_y();
float get_mix_scale_x(); float get_mix_scale_x();
float get_mix_scale_y(); float get_mix_scale_y();
float get_mix_shear_y(); float get_mix_shear_y();
float get_offset_rotation(); float get_offset_rotation();
float get_offset_x(); float get_offset_x();
float get_offset_y(); float get_offset_y();
float get_offset_scale_x(); float get_offset_scale_x();
float get_offset_scale_y(); float get_offset_scale_y();
float get_offset_shear_y(); float get_offset_shear_y();
bool is_relative(); bool is_relative();
bool is_local(); bool is_local();
}; };

View File

@ -27,8 +27,8 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
#include "SpineCommon.h"
#include "register_types.h" #include "register_types.h"
#include "core/class_db.h"
#include "SpineAtlasResource.h" #include "SpineAtlasResource.h"
#include "SpineSkeletonFileResource.h" #include "SpineSkeletonFileResource.h"
#include "SpineSkeletonDataResource.h" #include "SpineSkeletonDataResource.h"
@ -41,7 +41,6 @@
#include "SpineBoneData.h" #include "SpineBoneData.h"
#include "SpineSlotData.h" #include "SpineSlotData.h"
#include "SpineAttachment.h" #include "SpineAttachment.h"
#include "SpineSkinAttachmentMapEntries.h"
#include "SpineConstraintData.h" #include "SpineConstraintData.h"
#include "SpineSkin.h" #include "SpineSkin.h"
#include "SpineIkConstraintData.h" #include "SpineIkConstraintData.h"
@ -57,11 +56,8 @@ static Ref<SpineSkeletonFileResourceFormatLoader> skeleton_file_loader;
static Ref<SpineSkeletonFileResourceFormatSaver> skeleton_file_saver; static Ref<SpineSkeletonFileResourceFormatSaver> skeleton_file_saver;
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
#include "editor/editor_export.h"
#include "editor/editor_node.h" #include "editor/editor_node.h"
#include "SpineEditorPlugin.h" #include "SpineEditorPlugin.h"
#include "SpineSkeletonDataResource.h"
#include "SpineSprite.h"
static void editor_init_callback() { static void editor_init_callback() {
EditorNode::get_singleton()->add_editor_plugin(memnew(SpineEditorPlugin(EditorNode::get_singleton()))); EditorNode::get_singleton()->add_editor_plugin(memnew(SpineEditorPlugin(EditorNode::get_singleton())));
@ -88,8 +84,7 @@ void register_spine_godot_types() {
ClassDB::register_class<SpineBoneData>(); ClassDB::register_class<SpineBoneData>();
ClassDB::register_class<SpineSlotData>(); ClassDB::register_class<SpineSlotData>();
ClassDB::register_class<SpineAttachment>(); ClassDB::register_class<SpineAttachment>();
ClassDB::register_class<SpineSkinAttachmentMapEntry>(); ClassDB::register_class<SpineSkinEntry>();
ClassDB::register_class<SpineSkinAttachmentMapEntries>();
ClassDB::register_class<SpineConstraintData>(); ClassDB::register_class<SpineConstraintData>();
ClassDB::register_class<SpineSkin>(); ClassDB::register_class<SpineSkin>();
ClassDB::register_class<SpineIkConstraintData>(); ClassDB::register_class<SpineIkConstraintData>();
@ -104,6 +99,19 @@ void register_spine_godot_types() {
ClassDB::register_class<SpineConstant>(); ClassDB::register_class<SpineConstant>();
ClassDB::register_class<SpineCollisionShapeProxy>(); ClassDB::register_class<SpineCollisionShapeProxy>();
#if VERSION_MAJOR > 3
atlas_loader.instantiate();
ResourceLoader::add_resource_format_loader(atlas_loader);
atlas_saver.instantiate();
ResourceSaver::add_resource_format_saver(atlas_saver);
skeleton_file_loader.instantiate();
ResourceLoader::add_resource_format_loader(skeleton_file_loader);
skeleton_file_saver.instantiate();
ResourceSaver::add_resource_format_saver(skeleton_file_saver);
#else
atlas_loader.instance(); atlas_loader.instance();
ResourceLoader::add_resource_format_loader(atlas_loader); ResourceLoader::add_resource_format_loader(atlas_loader);
@ -115,6 +123,7 @@ void register_spine_godot_types() {
skeleton_file_saver.instance(); skeleton_file_saver.instance();
ResourceSaver::add_resource_format_saver(skeleton_file_saver); ResourceSaver::add_resource_format_saver(skeleton_file_saver);
#endif
} }
void unregister_spine_godot_types() { void unregister_spine_godot_types() {