[godot] Formatting

This commit is contained in:
Mario Zechner 2021-09-29 12:43:40 +02:00
parent 0b0800143a
commit 5ec5544132
79 changed files with 2235 additions and 2268 deletions

View File

@ -25,7 +25,9 @@ spotless {
'spine-sfml/**/*.cpp', 'spine-sfml/**/*.cpp',
'spine-sfml/**/*.h', 'spine-sfml/**/*.h',
'spine-ue4/**/*.cpp', 'spine-ue4/**/*.cpp',
'spine-ue4/**/*.h' 'spine-ue4/**/*.h',
'spine-godot/spine_godot/**.h',
'spine-godot/spine_godot/**.cpp'
clangFormat("12.0.1").pathToExe("$System.env.CLANGFORMAT").style('file') clangFormat("12.0.1").pathToExe("$System.env.CLANGFORMAT").style('file')
} }

View File

@ -35,42 +35,42 @@
#include <iostream> #include <iostream>
spine::SpineExtension *spine::getDefaultExtension() { spine::SpineExtension *spine::getDefaultExtension() {
return new GodotSpineExtension(); return new GodotSpineExtension();
} }
GodotSpineExtension::GodotSpineExtension(){} GodotSpineExtension::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);
} }
void *GodotSpineExtension::_calloc(size_t size, const char *file, int line){ void *GodotSpineExtension::_calloc(size_t size, const char *file, int line) {
auto p = memalloc(size); auto p = memalloc(size);
memset(p, 0, size); memset(p, 0, size);
return p; return p;
} }
void *GodotSpineExtension::_realloc(void *ptr, size_t size, const char *file, int line){ void *GodotSpineExtension::_realloc(void *ptr, size_t size, const char *file, int line) {
return memrealloc(ptr, size); return memrealloc(ptr, size);
} }
void GodotSpineExtension::_free(void *mem, const char *file, int line){ void GodotSpineExtension::_free(void *mem, const char *file, int line) {
memfree(mem); memfree(mem);
} }
char *GodotSpineExtension::_readFile(const spine::String &path, int *length){ char *GodotSpineExtension::_readFile(const spine::String &path, int *length) {
Error error; Error error;
auto res = FileAccess::get_file_as_array(String(path.buffer()), &error); auto res = FileAccess::get_file_as_array(String(path.buffer()), &error);
if (error != OK){ if (error != OK) {
if(length) *length = 0; if (length) *length = 0;
return NULL; return NULL;
} }
if(length) *length = res.size(); if (length) *length = res.size();
auto r = alloc<char>(res.size(), __FILE__, __LINE__); auto r = alloc<char>(res.size(), __FILE__, __LINE__);
for(size_t i=0;i<res.size();++i) for (size_t i = 0; i < res.size(); ++i)
r[i] = res[i]; r[i] = res[i];
return r; return r;
} }

View File

@ -51,7 +51,4 @@ protected:
}; };
#endif//GODOT_SPINEEXTENSION_H
#endif //GODOT_SPINEEXTENSION_H

View File

@ -29,7 +29,7 @@
#include "PackedSpineSkinResource.h" #include "PackedSpineSkinResource.h"
void PackedSpineSkinResource::_bind_methods(){ void PackedSpineSkinResource::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_skin_name", "v"), &PackedSpineSkinResource::set_skin_name); ClassDB::bind_method(D_METHOD("set_skin_name", "v"), &PackedSpineSkinResource::set_skin_name);
ClassDB::bind_method(D_METHOD("get_skin_name"), &PackedSpineSkinResource::get_skin_name); ClassDB::bind_method(D_METHOD("get_skin_name"), &PackedSpineSkinResource::get_skin_name);
ClassDB::bind_method(D_METHOD("set_sub_skin_names", "v"), &PackedSpineSkinResource::set_sub_skin_names); ClassDB::bind_method(D_METHOD("set_sub_skin_names", "v"), &PackedSpineSkinResource::set_sub_skin_names);
@ -41,21 +41,21 @@ void PackedSpineSkinResource::_bind_methods(){
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "sub_skin_names"), "set_sub_skin_names", "get_sub_skin_names"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "sub_skin_names"), "set_sub_skin_names", "get_sub_skin_names");
} }
PackedSpineSkinResource::PackedSpineSkinResource():skin_name("custom_skin_name"){} PackedSpineSkinResource::PackedSpineSkinResource() : skin_name("custom_skin_name") {}
PackedSpineSkinResource::~PackedSpineSkinResource(){} PackedSpineSkinResource::~PackedSpineSkinResource() {}
void PackedSpineSkinResource::set_skin_name(const String &v){ void PackedSpineSkinResource::set_skin_name(const String &v) {
skin_name = v; skin_name = v;
emit_signal("property_changed"); emit_signal("property_changed");
} }
String PackedSpineSkinResource::get_skin_name(){ String PackedSpineSkinResource::get_skin_name() {
return skin_name; return skin_name;
} }
void PackedSpineSkinResource::set_sub_skin_names(Array v){ void PackedSpineSkinResource::set_sub_skin_names(Array v) {
sub_skin_names = v; sub_skin_names = v;
emit_signal("property_changed"); emit_signal("property_changed");
} }
Array PackedSpineSkinResource::get_sub_skin_names(){ Array PackedSpineSkinResource::get_sub_skin_names() {
return sub_skin_names; return sub_skin_names;
} }

View File

@ -34,7 +34,7 @@
#include "SpineSkin.h" #include "SpineSkin.h"
class PackedSpineSkinResource : public Resource{ class PackedSpineSkinResource : public Resource {
GDCLASS(PackedSpineSkinResource, Resource); GDCLASS(PackedSpineSkinResource, Resource);
protected: protected:
@ -53,7 +53,6 @@ public:
void set_sub_skin_names(Array v); void set_sub_skin_names(Array v);
Array get_sub_skin_names(); Array get_sub_skin_names();
}; };
#endif //GODOT_PACKEDSPINESKINRESOURCE_H #endif//GODOT_PACKEDSPINESKINRESOURCE_H

View File

@ -31,26 +31,26 @@
#include "SpineAtlasResource.h" #include "SpineAtlasResource.h"
RES ResourceFormatLoaderSpineAtlas::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderSpineAtlas::load(const String &p_path, const String &p_original_path, Error *r_error) {
Ref<SpineAtlasResource> atlas = memnew(SpineAtlasResource); Ref<SpineAtlasResource> atlas = memnew(SpineAtlasResource);
atlas->load_from_file(p_path); atlas->load_from_file(p_path);
if(r_error){ if (r_error) {
*r_error = OK; *r_error = OK;
} }
return atlas; return atlas;
} }
void ResourceFormatLoaderSpineAtlas::get_recognized_extensions(List<String> *r_extensions) const { void ResourceFormatLoaderSpineAtlas::get_recognized_extensions(List<String> *r_extensions) const {
const char atlas_ext[] = "spatlas"; const char atlas_ext[] = "spatlas";
if(!r_extensions->find(atlas_ext)) { if (!r_extensions->find(atlas_ext)) {
r_extensions->push_back(atlas_ext); r_extensions->push_back(atlas_ext);
} }
} }
String ResourceFormatLoaderSpineAtlas::get_resource_type(const String &p_path) const { String ResourceFormatLoaderSpineAtlas::get_resource_type(const String &p_path) const {
return "SpineAtlasResource"; return "SpineAtlasResource";
} }
bool ResourceFormatLoaderSpineAtlas::handles_type(const String &p_type) const { bool ResourceFormatLoaderSpineAtlas::handles_type(const String &p_type) const {
return p_type == "SpineAtlasResource" || ClassDB::is_parent_class(p_type, "SpineAtlasResource"); return p_type == "SpineAtlasResource" || ClassDB::is_parent_class(p_type, "SpineAtlasResource");
} }

View File

@ -32,14 +32,15 @@
#include "core/io/resource_loader.h" #include "core/io/resource_loader.h"
class ResourceFormatLoaderSpineAtlas : public ResourceFormatLoader{ class ResourceFormatLoaderSpineAtlas : public ResourceFormatLoader {
GDCLASS(ResourceFormatLoaderSpineAtlas, ResourceFormatLoader); GDCLASS(ResourceFormatLoaderSpineAtlas, ResourceFormatLoader);
public: public:
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL); virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL);
virtual void get_recognized_extensions(List<String> *r_extensions) const; virtual void get_recognized_extensions(List<String> *r_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;
}; };
#endif //GODOT_RESOURCEFORMATLOADERSPINEATLAS_H #endif//GODOT_RESOURCEFORMATLOADERSPINEATLAS_H

View File

@ -31,26 +31,26 @@
#include "SpineSkeletonJsonDataResource.h" #include "SpineSkeletonJsonDataResource.h"
RES ResourceFormatLoaderSpineSkeletonJsonData::load(const String &p_path, const String &p_original_path, Error *r_error) { RES ResourceFormatLoaderSpineSkeletonJsonData::load(const String &p_path, const String &p_original_path, Error *r_error) {
Ref<SpineSkeletonJsonDataResource> skeleton = memnew(SpineSkeletonJsonDataResource); Ref<SpineSkeletonJsonDataResource> skeleton = memnew(SpineSkeletonJsonDataResource);
skeleton->load_from_file(p_path); skeleton->load_from_file(p_path);
if(r_error){ if (r_error) {
*r_error = OK; *r_error = OK;
} }
return skeleton; return skeleton;
} }
void ResourceFormatLoaderSpineSkeletonJsonData::get_recognized_extensions(List<String> *r_extensions) const { void ResourceFormatLoaderSpineSkeletonJsonData::get_recognized_extensions(List<String> *r_extensions) const {
const char json_ext[] = "spjson"; const char json_ext[] = "spjson";
if(!r_extensions->find(json_ext)) { if (!r_extensions->find(json_ext)) {
r_extensions->push_back(json_ext); r_extensions->push_back(json_ext);
} }
} }
String ResourceFormatLoaderSpineSkeletonJsonData::get_resource_type(const String &p_path) const { String ResourceFormatLoaderSpineSkeletonJsonData::get_resource_type(const String &p_path) const {
return "SpineSkeletonJsonDataResource"; return "SpineSkeletonJsonDataResource";
} }
bool ResourceFormatLoaderSpineSkeletonJsonData::handles_type(const String &p_type) const { bool ResourceFormatLoaderSpineSkeletonJsonData::handles_type(const String &p_type) const {
return p_type == "SpineSkeletonJsonDataResource" || ClassDB::is_parent_class(p_type, "SpineSkeletonJsonDataResource"); return p_type == "SpineSkeletonJsonDataResource" || ClassDB::is_parent_class(p_type, "SpineSkeletonJsonDataResource");
} }

View File

@ -34,11 +34,12 @@
class ResourceFormatLoaderSpineSkeletonJsonData : public ResourceFormatLoader { class ResourceFormatLoaderSpineSkeletonJsonData : public ResourceFormatLoader {
GDCLASS(ResourceFormatLoaderSpineSkeletonJsonData, ResourceFormatLoader); GDCLASS(ResourceFormatLoaderSpineSkeletonJsonData, ResourceFormatLoader);
public: public:
virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL); virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL);
virtual void get_recognized_extensions(List<String> *r_extensions) const; virtual void get_recognized_extensions(List<String> *r_extensions) const;
virtual bool handles_type(const String &p_type) const; virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const; virtual String get_resource_type(const String &p_path) const;
}; };
#endif //GODOT_RESOURCEFORMATLOADERSPINESKELETONJSONDATA_H #endif//GODOT_RESOURCEFORMATLOADERSPINESKELETONJSONDATA_H

View File

@ -32,17 +32,17 @@
#include "SpineAtlasResource.h" #include "SpineAtlasResource.h"
Error ResourceFormatSaverSpineAtlas::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { Error ResourceFormatSaverSpineAtlas::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
Ref<SpineAtlasResource> res = p_resource.get_ref_ptr(); Ref<SpineAtlasResource> res = p_resource.get_ref_ptr();
Error error = res->save_to_file(p_path); Error error = res->save_to_file(p_path);
return error; return error;
} }
void ResourceFormatSaverSpineAtlas::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { void ResourceFormatSaverSpineAtlas::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
if (Object::cast_to<SpineAtlasResource>(*p_resource)) { if (Object::cast_to<SpineAtlasResource>(*p_resource)) {
p_extensions->push_back("spatlas"); p_extensions->push_back("spatlas");
} }
} }
bool ResourceFormatSaverSpineAtlas::recognize(const RES &p_resource) const { bool ResourceFormatSaverSpineAtlas::recognize(const RES &p_resource) const {
return Object::cast_to<SpineAtlasResource>(*p_resource) != nullptr; return Object::cast_to<SpineAtlasResource>(*p_resource) != nullptr;
} }

View File

@ -32,13 +32,14 @@
#include "core/io/resource_saver.h" #include "core/io/resource_saver.h"
class ResourceFormatSaverSpineAtlas : public ResourceFormatSaver{ class ResourceFormatSaverSpineAtlas : public ResourceFormatSaver {
GDCLASS(ResourceFormatSaverSpineAtlas, ResourceFormatSaver); GDCLASS(ResourceFormatSaverSpineAtlas, ResourceFormatSaver);
public: public:
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override; Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override;
void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const override; void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const override;
bool recognize(const RES &p_resource) const override; bool recognize(const RES &p_resource) const override;
}; };
#endif //GODOT_RESOURCEFORMATSAVERSPINEATLAS_H #endif//GODOT_RESOURCEFORMATSAVERSPINEATLAS_H

View File

@ -32,17 +32,17 @@
#include "SpineSkeletonJsonDataResource.h" #include "SpineSkeletonJsonDataResource.h"
Error ResourceFormatSaverSpineSkeletonJsonData::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { Error ResourceFormatSaverSpineSkeletonJsonData::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
Ref<SpineSkeletonJsonDataResource> res = p_resource.get_ref_ptr(); Ref<SpineSkeletonJsonDataResource> res = p_resource.get_ref_ptr();
Error error = res->save_to_file(p_path); Error error = res->save_to_file(p_path);
return error; return error;
} }
void ResourceFormatSaverSpineSkeletonJsonData::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const { void ResourceFormatSaverSpineSkeletonJsonData::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
if (Object::cast_to<SpineSkeletonJsonDataResource>(*p_resource)) { if (Object::cast_to<SpineSkeletonJsonDataResource>(*p_resource)) {
p_extensions->push_back("spjson"); p_extensions->push_back("spjson");
} }
} }
bool ResourceFormatSaverSpineSkeletonJsonData::recognize(const RES &p_resource) const { bool ResourceFormatSaverSpineSkeletonJsonData::recognize(const RES &p_resource) const {
return Object::cast_to<SpineSkeletonJsonDataResource>(*p_resource) != nullptr; return Object::cast_to<SpineSkeletonJsonDataResource>(*p_resource) != nullptr;
} }

View File

@ -32,13 +32,14 @@
#include "core/io/resource_saver.h" #include "core/io/resource_saver.h"
class ResourceFormatSaverSpineSkeletonJsonData : public ResourceFormatSaver{ class ResourceFormatSaverSpineSkeletonJsonData : public ResourceFormatSaver {
GDCLASS(ResourceFormatSaverSpineSkeletonJsonData, ResourceFormatSaver); GDCLASS(ResourceFormatSaverSpineSkeletonJsonData, ResourceFormatSaver);
public: public:
Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override; Error save(const String &p_path, const RES &p_resource, uint32_t p_flags = 0) override;
void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const override; void get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const override;
bool recognize(const RES &p_resource) const override; bool recognize(const RES &p_resource) const override;
}; };
#endif //GODOT_RESOURCEFORMATSAVERSPINESKELETONJSONDATA_H #endif//GODOT_RESOURCEFORMATSAVERSPINESKELETONJSONDATA_H

View File

@ -46,8 +46,8 @@ void SpineAnimation::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_timeline", "ids"), &SpineAnimation::has_timeline); ClassDB::bind_method(D_METHOD("has_timeline", "ids"), &SpineAnimation::has_timeline);
} }
SpineAnimation::SpineAnimation():animation(NULL) {} SpineAnimation::SpineAnimation() : animation(NULL) {}
SpineAnimation::~SpineAnimation(){} SpineAnimation::~SpineAnimation() {}
String SpineAnimation::get_anim_name() { String SpineAnimation::get_anim_name() {
return animation->getName().buffer(); return animation->getName().buffer();
@ -61,36 +61,36 @@ void SpineAnimation::set_duration(float v) {
} }
void SpineAnimation::apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, bool loop, void SpineAnimation::apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, bool loop,
Array pEvents, float alpha, SpineConstant::MixBlend blend, Array pEvents, float alpha, SpineConstant::MixBlend blend,
SpineConstant::MixDirection direction) { SpineConstant::MixDirection direction) {
spine::Vector<spine::Event*> events; spine::Vector<spine::Event *> events;
events.setSize(pEvents.size(), nullptr); events.setSize(pEvents.size(), nullptr);
for (size_t i=0; i<events.size(); ++i) { for (size_t i = 0; i < events.size(); ++i) {
events[i] = ((Ref<SpineEvent>)(pEvents[i]))->get_spine_object(); events[i] = ((Ref<SpineEvent>) (pEvents[i]))->get_spine_object();
} }
animation->apply(*(skeleton->get_spine_object()), lastTime, time, loop, &events, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction); animation->apply(*(skeleton->get_spine_object()), lastTime, time, loop, &events, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction);
} }
Array SpineAnimation::get_timelines() { Array SpineAnimation::get_timelines() {
auto &timelines = animation->getTimelines(); auto &timelines = animation->getTimelines();
Array res; Array res;
res.resize(timelines.size()); res.resize(timelines.size());
for (size_t i=0; i<res.size(); ++i) { for (size_t i = 0; i < res.size(); ++i) {
auto a = Ref<SpineTimeline>(memnew(SpineTimeline)); auto a = Ref<SpineTimeline>(memnew(SpineTimeline));
a->set_spine_object(timelines[i]); a->set_spine_object(timelines[i]);
res.set(i, a); res.set(i, a);
} }
return res; return res;
} }
bool SpineAnimation::has_timeline(Array ids) { bool SpineAnimation::has_timeline(Array ids) {
spine::Vector<spine::PropertyId> list; spine::Vector<spine::PropertyId> list;
list.setSize(ids.size(), 0); list.setSize(ids.size(), 0);
for (size_t i=0; i<list.size(); ++i) { for (size_t i = 0; i < list.size(); ++i) {
list[i] = ids[i]; list[i] = ids[i];
} }
return animation->hasTimeline(list); return animation->hasTimeline(list);
} }

View File

@ -40,7 +40,7 @@ class SpineEvent;
class SpineSkeleton; class SpineSkeleton;
class SpineTimeline; class SpineTimeline;
class SpineAnimation : public Reference{ class SpineAnimation : public Reference {
GDCLASS(SpineAnimation, Reference); GDCLASS(SpineAnimation, Reference);
private: private:
@ -53,22 +53,22 @@ public:
SpineAnimation(); SpineAnimation();
~SpineAnimation(); ~SpineAnimation();
inline void set_spine_object(spine::Animation *a){ inline void set_spine_object(spine::Animation *a) {
animation = a; animation = a;
} }
inline spine::Animation *get_spine_object(){ inline spine::Animation *get_spine_object() {
return animation; return animation;
} }
// Vector<Ref<SpineEvent>> pEvents // Vector<Ref<SpineEvent>> pEvents
void apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, bool loop, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction); void apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, bool loop, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction);
Array get_timelines(); // Vector<Ref<SpineTimeline>> Array get_timelines(); // Vector<Ref<SpineTimeline>>
bool has_timeline(Array ids); // Vector<SpineConstant::PropertyId> bool has_timeline(Array ids);// Vector<SpineConstant::PropertyId>
String get_anim_name(); String get_anim_name();
float get_duration(); float get_duration();
void set_duration(float v); void set_duration(float v);
}; };
#endif //GODOT_SPINEANIMATION_H #endif//GODOT_SPINEANIMATION_H

View File

@ -44,25 +44,22 @@ void SpineAnimationState::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &SpineAnimationState::set_time_scale); ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &SpineAnimationState::set_time_scale);
ClassDB::bind_method(D_METHOD("disable_queue"), &SpineAnimationState::disable_queue); ClassDB::bind_method(D_METHOD("disable_queue"), &SpineAnimationState::disable_queue);
ClassDB::bind_method(D_METHOD("enable_queue"), &SpineAnimationState::enable_queue); ClassDB::bind_method(D_METHOD("enable_queue"), &SpineAnimationState::enable_queue);
// ClassDB::bind_method(D_METHOD("reload"), &SpineAnimationState::reload_animation_state); // ClassDB::bind_method(D_METHOD("reload"), &SpineAnimationState::reload_animation_state);
ClassDB::bind_method(D_METHOD("get_current", "track_id"), &SpineAnimationState::get_current); ClassDB::bind_method(D_METHOD("get_current", "track_id"), &SpineAnimationState::get_current);
} }
SpineAnimationState::SpineAnimationState():animation_state(NULL) { SpineAnimationState::SpineAnimationState() : animation_state(NULL) {
} }
SpineAnimationState::~SpineAnimationState() { SpineAnimationState::~SpineAnimationState() {
if(animation_state) if (animation_state) {
{
delete animation_state; delete animation_state;
animation_state = NULL; animation_state = NULL;
} }
} }
void SpineAnimationState::load_animation_state(Ref<SpineAnimationStateDataResource> ad) { void SpineAnimationState::load_animation_state(Ref<SpineAnimationStateDataResource> ad) {
if(animation_state) if (animation_state) {
{
delete animation_state; delete animation_state;
animation_state = NULL; animation_state = NULL;
} }
@ -71,28 +68,33 @@ void SpineAnimationState::load_animation_state(Ref<SpineAnimationStateDataResour
} }
void SpineAnimationState::reload_animation_state() { void SpineAnimationState::reload_animation_state() {
if(!anim_state_data_res.is_valid()) if (!anim_state_data_res.is_valid()) {
{
ERR_PRINT(" Reload animation state fail, because anim_state_data_res not set!"); ERR_PRINT(" Reload animation state fail, because anim_state_data_res not set!");
return; return;
} }
if(animation_state) if (animation_state) {
{
delete animation_state; delete animation_state;
animation_state = NULL; animation_state = NULL;
} }
animation_state = new spine::AnimationState(anim_state_data_res->get_animation_state_data()); animation_state = new spine::AnimationState(anim_state_data_res->get_animation_state_data());
} }
#define CHECK_V if(!animation_state){ERR_PRINT("The animation state is not loaded yet!");return;} #define CHECK_V \
#define CHECK_X(x) if(!animation_state){ERR_PRINT("The animation state is not loaded yet!");return x;} if (!animation_state) { \
ERR_PRINT("The animation state is not loaded yet!"); \
return; \
}
#define CHECK_X(x) \
if (!animation_state) { \
ERR_PRINT("The animation state is not loaded yet!"); \
return x; \
}
#define S_T(x) (spine::String(x.utf8())) #define S_T(x) (spine::String(x.utf8()))
Ref<SpineTrackEntry> SpineAnimationState::set_animation(const String &anim_name, bool loop, uint64_t track) { Ref<SpineTrackEntry> SpineAnimationState::set_animation(const String &anim_name, bool loop, uint64_t track) {
CHECK_X(NULL); CHECK_X(NULL);
auto skeleton_data = anim_state_data_res->get_skeleton(); auto skeleton_data = anim_state_data_res->get_skeleton();
auto anim = skeleton_data->find_animation(anim_name); auto anim = skeleton_data->find_animation(anim_name);
if(!anim.is_valid() || anim->get_spine_object() == NULL) if (!anim.is_valid() || anim->get_spine_object() == NULL) {
{
ERR_PRINT(String("Can not find animation: ") + anim_name) ERR_PRINT(String("Can not find animation: ") + anim_name)
return NULL; return NULL;
} }
@ -105,8 +107,7 @@ Ref<SpineTrackEntry> SpineAnimationState::add_animation(const String &anim_name,
CHECK_X(NULL); CHECK_X(NULL);
auto skeleton_data = anim_state_data_res->get_skeleton(); auto skeleton_data = anim_state_data_res->get_skeleton();
auto anim = skeleton_data->find_animation(anim_name); auto anim = skeleton_data->find_animation(anim_name);
if(!anim.is_valid() || anim->get_spine_object() == NULL) if (!anim.is_valid() || anim->get_spine_object() == NULL) {
{
ERR_PRINT(String("Can not find animation: ") + anim_name) ERR_PRINT(String("Can not find animation: ") + anim_name)
return NULL; return NULL;
} }
@ -135,11 +136,11 @@ void SpineAnimationState::set_empty_animations(float mix_duration) {
animation_state->setEmptyAnimations(mix_duration); animation_state->setEmptyAnimations(mix_duration);
} }
void SpineAnimationState::update(float delta){ void SpineAnimationState::update(float delta) {
CHECK_V; CHECK_V;
animation_state->update(delta); animation_state->update(delta);
} }
bool SpineAnimationState::apply(Ref<SpineSkeleton> skeleton){ bool SpineAnimationState::apply(Ref<SpineSkeleton> skeleton) {
CHECK_X(false); CHECK_X(false);
return animation_state->apply(*(skeleton->get_spine_object())); return animation_state->apply(*(skeleton->get_spine_object()));
} }
@ -181,7 +182,7 @@ Ref<SpineTrackEntry> SpineAnimationState::get_current(uint64_t track_index) {
CHECK_X(NULL); CHECK_X(NULL);
Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry)); Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry));
auto entry = animation_state->getCurrent(track_index); auto entry = animation_state->getCurrent(track_index);
if(entry == NULL) return NULL; if (entry == NULL) return NULL;
gd_entry->set_spine_object(entry); gd_entry->set_spine_object(entry);
return gd_entry; return gd_entry;
} }

View File

@ -36,7 +36,7 @@
#include "SpineSkeleton.h" #include "SpineSkeleton.h"
#include "SpineTrackEntry.h" #include "SpineTrackEntry.h"
class SpineAnimationState : public Reference{ class SpineAnimationState : public Reference {
GDCLASS(SpineAnimationState, Reference); GDCLASS(SpineAnimationState, Reference);
protected: protected:
@ -46,21 +46,22 @@ private:
spine::AnimationState *animation_state; spine::AnimationState *animation_state;
Ref<SpineAnimationStateDataResource> anim_state_data_res; Ref<SpineAnimationStateDataResource> anim_state_data_res;
public: public:
void load_animation_state(Ref<SpineAnimationStateDataResource> ad); void load_animation_state(Ref<SpineAnimationStateDataResource> ad);
inline void set_animation_state(spine::AnimationState *a){ inline void set_animation_state(spine::AnimationState *a) {
animation_state = a; animation_state = a;
} }
inline spine::AnimationState *get_animation_state(){ inline spine::AnimationState *get_animation_state() {
return animation_state; return animation_state;
} }
void reload_animation_state(); void reload_animation_state();
Ref<SpineTrackEntry> set_animation(const String &anim_name, bool loop, uint64_t track_id); Ref<SpineTrackEntry> set_animation(const String &anim_name, bool loop, uint64_t track_id);
inline void set_animation_by_ref(Ref<SpineAnimation> anim, bool loop, uint64_t track_id){ inline void set_animation_by_ref(Ref<SpineAnimation> anim, bool loop, uint64_t track_id) {
if(anim.is_valid()){ if (anim.is_valid()) {
animation_state->setAnimation(track_id, anim->get_spine_object(), loop); animation_state->setAnimation(track_id, anim->get_spine_object(), loop);
} }
} }
@ -90,4 +91,4 @@ public:
~SpineAnimationState(); ~SpineAnimationState();
}; };
#endif //GODOT_SPINEANIMATIONSTATE_H #endif//GODOT_SPINEANIMATIONSTATE_H

View File

@ -29,12 +29,10 @@
#include "SpineAnimationStateDataResource.h" #include "SpineAnimationStateDataResource.h"
SpineAnimationStateDataResource::SpineAnimationStateDataResource():animation_state_data(NULL),animation_state_data_created(false),default_mix(0.5f) { SpineAnimationStateDataResource::SpineAnimationStateDataResource() : animation_state_data(NULL), animation_state_data_created(false), default_mix(0.5f) {
} }
SpineAnimationStateDataResource::~SpineAnimationStateDataResource() { SpineAnimationStateDataResource::~SpineAnimationStateDataResource() {
if(animation_state_data) if (animation_state_data) {
{
delete animation_state_data; delete animation_state_data;
animation_state_data = NULL; animation_state_data = NULL;
} }
@ -63,27 +61,22 @@ void SpineAnimationStateDataResource::set_skeleton(const Ref<SpineSkeletonDataRe
skeleton = s; skeleton = s;
_on_skeleton_data_changed(); _on_skeleton_data_changed();
if(skeleton.is_valid()) if (skeleton.is_valid()) {
{
skeleton->connect("skeleton_data_loaded", this, "_on_skeleton_data_loaded"); skeleton->connect("skeleton_data_loaded", this, "_on_skeleton_data_loaded");
skeleton->connect("atlas_res_changed", this, "_on_skeleton_data_changed"); skeleton->connect("atlas_res_changed", this, "_on_skeleton_data_changed");
skeleton->connect("skeleton_json_res_changed", this, "_on_skeleton_data_changed"); skeleton->connect("skeleton_json_res_changed", this, "_on_skeleton_data_changed");
if(skeleton->is_skeleton_data_loaded()) if (skeleton->is_skeleton_data_loaded()) {
{
_on_skeleton_data_loaded(); _on_skeleton_data_loaded();
} }
}else{ } else {
if(animation_state_data) if (animation_state_data) {
{
delete animation_state_data; delete animation_state_data;
animation_state_data = NULL; animation_state_data = NULL;
animation_state_data_created = false; animation_state_data_created = false;
// print_line("Animation state data deleted."); // print_line("Animation state data deleted.");
} }
} }
} }
Ref<SpineSkeletonDataResource> SpineAnimationStateDataResource::get_skeleton() { Ref<SpineSkeletonDataResource> SpineAnimationStateDataResource::get_skeleton() {
return skeleton; return skeleton;
@ -91,18 +84,17 @@ Ref<SpineSkeletonDataResource> SpineAnimationStateDataResource::get_skeleton() {
void SpineAnimationStateDataResource::set_default_mix(float m) { void SpineAnimationStateDataResource::set_default_mix(float m) {
default_mix = m; default_mix = m;
if(!is_animation_state_data_created()) if (!is_animation_state_data_created()) {
{ // ERR_PRINT("'set_default_mix' fail. Animation state data is not created!");
// ERR_PRINT("'set_default_mix' fail. Animation state data is not created!");
return; return;
} }
animation_state_data->setDefaultMix(((m >= 0 && m <= 1) ? m : m <= 0 ? 0 : 1)); animation_state_data->setDefaultMix(((m >= 0 && m <= 1) ? m : m <= 0 ? 0
// emit_signal("animation_state_data_changed"); : 1));
// emit_signal("animation_state_data_changed");
} }
float SpineAnimationStateDataResource::get_default_mix() { float SpineAnimationStateDataResource::get_default_mix() {
if(!is_animation_state_data_created()) if (!is_animation_state_data_created()) {
{ // ERR_PRINT("'get_default_mix' fail. Animation state data is not created!");
// ERR_PRINT("'get_default_mix' fail. Animation state data is not created!");
return default_mix; return default_mix;
} }
default_mix = animation_state_data->getDefaultMix(); default_mix = animation_state_data->getDefaultMix();
@ -110,40 +102,34 @@ float SpineAnimationStateDataResource::get_default_mix() {
} }
void SpineAnimationStateDataResource::set_mix(const String &from, const String &to, float mix_duration) { void SpineAnimationStateDataResource::set_mix(const String &from, const String &to, float mix_duration) {
if(!is_animation_state_data_created()) if (!is_animation_state_data_created()) {
{
ERR_PRINT("'set_mix' fail. Animation state data is not created!"); ERR_PRINT("'set_mix' fail. Animation state data is not created!");
return; return;
} }
auto anim_from = get_skeleton()->find_animation(from); auto anim_from = get_skeleton()->find_animation(from);
auto anim_to = get_skeleton()->find_animation(to); auto anim_to = get_skeleton()->find_animation(to);
if(!anim_from.is_valid()) if (!anim_from.is_valid()) {
{
ERR_PRINT("'set_mix' fail. From animation animation not found!"); ERR_PRINT("'set_mix' fail. From animation animation not found!");
return; return;
} }
if(!anim_to.is_valid()) if (!anim_to.is_valid()) {
{
ERR_PRINT("'set_mix' fail. To animation animation not found!"); ERR_PRINT("'set_mix' fail. To animation animation not found!");
return; return;
} }
animation_state_data->setMix(anim_from->get_spine_object(), anim_to->get_spine_object(), mix_duration); animation_state_data->setMix(anim_from->get_spine_object(), anim_to->get_spine_object(), mix_duration);
} }
float SpineAnimationStateDataResource::get_mix(const String &from, const String &to) { float SpineAnimationStateDataResource::get_mix(const String &from, const String &to) {
if(!is_animation_state_data_created()) if (!is_animation_state_data_created()) {
{
ERR_PRINT("'set_mix' fail. Animation state data is not created!"); ERR_PRINT("'set_mix' fail. Animation state data is not created!");
return 0; return 0;
} }
auto anim_from = get_skeleton()->find_animation(from); auto anim_from = get_skeleton()->find_animation(from);
auto anim_to = get_skeleton()->find_animation(to); auto anim_to = get_skeleton()->find_animation(to);
if(!anim_from.is_valid()) if (!anim_from.is_valid()) {
{
ERR_PRINT("'set_mix' fail. From animation animation not found!"); ERR_PRINT("'set_mix' fail. From animation animation not found!");
return 0; return 0;
} }
if(!anim_to.is_valid()) if (!anim_to.is_valid()) {
{
ERR_PRINT("'set_mix' fail. To animation animation not found!"); ERR_PRINT("'set_mix' fail. To animation animation not found!");
return 0; return 0;
} }
@ -152,7 +138,7 @@ float SpineAnimationStateDataResource::get_mix(const String &from, const String
void SpineAnimationStateDataResource::_on_skeleton_data_loaded() { void SpineAnimationStateDataResource::_on_skeleton_data_loaded() {
animation_state_data = new spine::AnimationStateData(skeleton->get_skeleton_data()); animation_state_data = new spine::AnimationStateData(skeleton->get_skeleton_data());
// print_line("Animation state data created."); // print_line("Animation state data created.");
emit_signal("animation_state_data_created"); emit_signal("animation_state_data_created");
@ -162,17 +148,16 @@ void SpineAnimationStateDataResource::_on_skeleton_data_loaded() {
void SpineAnimationStateDataResource::_on_skeleton_data_changed() { void SpineAnimationStateDataResource::_on_skeleton_data_changed() {
animation_state_data_created = false; animation_state_data_created = false;
if(animation_state_data) if (animation_state_data) {
{
delete animation_state_data; delete animation_state_data;
animation_state_data = NULL; animation_state_data = NULL;
// print_line("Animation state data deleted."); // print_line("Animation state data deleted.");
} }
// print_line("skeleton_data_res_changed emitted"); // print_line("skeleton_data_res_changed emitted");
emit_signal("skeleton_data_res_changed"); emit_signal("skeleton_data_res_changed");
} }
bool SpineAnimationStateDataResource::is_animation_state_data_created(){ bool SpineAnimationStateDataResource::is_animation_state_data_created() {
return animation_state_data_created; return animation_state_data_created;
} }

View File

@ -34,7 +34,7 @@
#include "SpineSkeletonDataResource.h" #include "SpineSkeletonDataResource.h"
class SpineAnimationStateDataResource : public Resource{ class SpineAnimationStateDataResource : public Resource {
GDCLASS(SpineAnimationStateDataResource, Resource); GDCLASS(SpineAnimationStateDataResource, Resource);
protected: protected:
@ -48,12 +48,12 @@ private:
bool animation_state_data_created; bool animation_state_data_created;
float default_mix; float default_mix;
public:
public:
void set_skeleton(const Ref<SpineSkeletonDataResource> &s); void set_skeleton(const Ref<SpineSkeletonDataResource> &s);
Ref<SpineSkeletonDataResource> get_skeleton(); Ref<SpineSkeletonDataResource> get_skeleton();
inline spine::AnimationStateData *get_animation_state_data(){ inline spine::AnimationStateData *get_animation_state_data() {
return animation_state_data; return animation_state_data;
} }
@ -73,4 +73,4 @@ public:
~SpineAnimationStateDataResource(); ~SpineAnimationStateDataResource();
}; };
#endif //GODOT_SPINEANIMATIONSTATEDATARESOURCE_H #endif//GODOT_SPINEANIMATIONSTATEDATARESOURCE_H

View File

@ -34,97 +34,93 @@
class GodotSpineTextureLoader : public spine::TextureLoader { class GodotSpineTextureLoader : public spine::TextureLoader {
private: private:
Array *tex_list, *ntex_list; Array *textures, *normal_maps;
String normal_tex_prefix; String normal_maps_prefix;
public: public:
GodotSpineTextureLoader(Array *t, Array *nt, const String &p) : textures(t), normal_maps(nt), normal_maps_prefix(p) {
if (textures) textures->clear();
if (normal_maps) normal_maps->clear();
}
GodotSpineTextureLoader(Array *t, Array *nt, const String &p):tex_list(t), ntex_list(nt), normal_tex_prefix(p){ String fixPathIssue(const String &path) {
if (tex_list) tex_list->clear(); if (path.size() > 5 && path[4] == '/' && path[5] == '/') return path;
if (ntex_list) ntex_list->clear(); const String prefix = "res:/";
} auto i = path.find(prefix);
auto sub_str_pos = i + prefix.size() - 1;
if (sub_str_pos < 0) return path;
auto res = path.substr(sub_str_pos);
String fixPathIssue(const String &path){ if (res.size() > 0) {
if(path.size() > 5 && path[4] == '/' && path[5] == '/') return path; if (res[0] != '/') {
const String prefix = "res:/"; return prefix + "/" + res;
auto i = path.find(prefix); } else {
// print_line(String("Found i at ") + String(Variant(i))); return prefix + res;
auto sub_str_pos = i+prefix.size()-1; }
if(sub_str_pos < 0) return path; }
auto res = path.substr(sub_str_pos); return path;
// print_line(String("rest of it: ") + res); }
if(res.size() > 0)
{
if(res[0] != '/')
{
return prefix + "/" + res;
} else
{
return prefix + res;
}
}
return path;
}
virtual void load(spine::AtlasPage &page, const spine::String &path){ virtual void load(spine::AtlasPage &page, const spine::String &path) {
Error err = OK; Error err = OK;
// print_line(String("Spine is loading texture: ") + String(path.buffer())); // print_line(String("Spine is loading texture: ") + String(path.buffer()));
auto fixed_path = fixPathIssue(String(path.buffer())); auto fixed_path = fixPathIssue(String(path.buffer()));
// print_line("Fixed path: " + fixed_path); // print_line("Fixed path: " + fixed_path);
// Load texture (e.g. tex.png) // Load texture (e.g. tex.png)
Ref<Texture> tex = ResourceLoader::load(fixed_path, "", false, &err); Ref<Texture> tex = ResourceLoader::load(fixed_path, "", false, &err);
if (err != OK) { if (err != OK) {
print_error(vformat("Can't load texture: \"%s\"", String(path.buffer()))); print_error(vformat("Can't load texture: \"%s\"", String(path.buffer())));
page.setRendererObject((void*)memnew(SpineRendererObject {nullptr})); page.setRendererObject((void *) memnew(SpineRendererObject{nullptr}));
return; return;
} }
if (tex_list) tex_list->append(tex); if (textures) textures->append(tex);
auto p_spine_renderer_object = memnew(SpineRendererObject); auto p_spine_renderer_object = memnew(SpineRendererObject);
p_spine_renderer_object->tex = tex; p_spine_renderer_object->tex = tex;
// Load normal texture (e.g. n_tex.png) // Load normal texture (e.g. n_tex.png)
String temppath = fixed_path; String temppath = fixed_path;
String newpath = vformat("%s/%s_%s", temppath.get_base_dir(), normal_tex_prefix, temppath.get_file()); String newpath = vformat("%s/%s_%s", temppath.get_base_dir(), normal_maps_prefix, temppath.get_file());
// print_line(vformat("try n tex: %s", newpath)); // print_line(vformat("try n tex: %s", newpath));
if (ResourceLoader::exists(newpath)){ if (ResourceLoader::exists(newpath)) {
Ref<Texture> normal_tex = ResourceLoader::load(newpath); Ref<Texture> normal_tex = ResourceLoader::load(newpath);
if (ntex_list) ntex_list->append(normal_tex); if (normal_maps) normal_maps->append(normal_tex);
p_spine_renderer_object->normal_tex = normal_tex; p_spine_renderer_object->normal_tex = normal_tex;
// print_line(String("From atlas resource load: ") + String(" ro ") + String(Variant((long long) p_spine_renderer_object))); // print_line(String("From atlas resource load: ") + String(" ro ") + String(Variant((long long) p_spine_renderer_object)));
// print_line(String("From atlas resource load: ") + String(Variant(p_spine_renderer_object->tex)) + String(", ") + String(Variant(p_spine_renderer_object->normal_tex))); // print_line(String("From atlas resource load: ") + String(Variant(p_spine_renderer_object->tex)) + String(", ") + String(Variant(p_spine_renderer_object->normal_tex)));
} }
page.setRendererObject((void*)p_spine_renderer_object); page.setRendererObject((void *) p_spine_renderer_object);
page.width = tex->get_width(); page.width = tex->get_width();
page.height = tex->get_height(); page.height = tex->get_height();
} }
virtual void unload(void *p){ virtual void unload(void *p) {
// print_line("I'm out."); // print_line("I'm out.");
auto p_spine_renderer_object = (SpineRendererObject*) p; auto p_spine_renderer_object = (SpineRendererObject *) p;
Ref<Texture> &tex = p_spine_renderer_object->tex; Ref<Texture> &tex = p_spine_renderer_object->tex;
Ref<Texture> &normal_tex = p_spine_renderer_object->normal_tex; Ref<Texture> &normal_tex = p_spine_renderer_object->normal_tex;
if (tex.is_valid()) tex.unref(); if (tex.is_valid()) tex.unref();
if (normal_tex.is_valid()) normal_tex.unref(); if (normal_tex.is_valid()) normal_tex.unref();
memdelete(p_spine_renderer_object); memdelete(p_spine_renderer_object);
} }
}; };
SpineAtlasResource::SpineAtlasResource():atlas(nullptr), normal_texture_prefix("n"){} SpineAtlasResource::SpineAtlasResource() : atlas(nullptr), normal_texture_prefix("n") {}
SpineAtlasResource::~SpineAtlasResource(){ SpineAtlasResource::~SpineAtlasResource() {
if (atlas) delete atlas; if (atlas) delete atlas;
} }
void SpineAtlasResource::_bind_methods(){ void SpineAtlasResource::_bind_methods() {
ClassDB::bind_method(D_METHOD("load_from_atlas_file", "path"), &SpineAtlasResource::load_from_atlas_file); ClassDB::bind_method(D_METHOD("load_from_atlas_file", "path"), &SpineAtlasResource::load_from_atlas_file);
ClassDB::bind_method(D_METHOD("get_source_path"), &SpineAtlasResource::get_source_path); ClassDB::bind_method(D_METHOD("get_source_path"), &SpineAtlasResource::get_source_path);
ClassDB::bind_method(D_METHOD("get_textures"), &SpineAtlasResource::get_textures); ClassDB::bind_method(D_METHOD("get_textures"), &SpineAtlasResource::get_textures);
ClassDB::bind_method(D_METHOD("get_normal_textures"), &SpineAtlasResource::get_normal_textures); ClassDB::bind_method(D_METHOD("get_normal_textures"), &SpineAtlasResource::get_normal_textures);
@ -140,90 +136,90 @@ Array SpineAtlasResource::get_textures() {
} }
Array SpineAtlasResource::get_normal_textures() { Array SpineAtlasResource::get_normal_textures() {
return ntex_list; return ntex_list;
} }
String SpineAtlasResource::get_source_path() { String SpineAtlasResource::get_source_path() {
return source_path; return source_path;
} }
Error SpineAtlasResource::load_from_atlas_file(const String &p_path) { Error SpineAtlasResource::load_from_atlas_file(const String &p_path) {
// print_line(vformat("Importing atlas file: %s", p_path)); // print_line(vformat("Importing atlas file: %s", p_path));
source_path = p_path; source_path = p_path;
Error err; Error err;
atlas_data = FileAccess::get_file_as_string(p_path, &err); atlas_data = FileAccess::get_file_as_string(p_path, &err);
if (err != OK) return err; if (err != OK) return err;
if (atlas) delete atlas; if (atlas) delete atlas;
tex_list.clear(); tex_list.clear();
ntex_list.clear(); ntex_list.clear();
atlas = new spine::Atlas(atlas_data.utf8(), atlas_data.size(), source_path.get_base_dir().utf8(), new GodotSpineTextureLoader(&tex_list, &ntex_list, normal_texture_prefix)); atlas = new spine::Atlas(atlas_data.utf8(), atlas_data.size(), source_path.get_base_dir().utf8(), new GodotSpineTextureLoader(&tex_list, &ntex_list, normal_texture_prefix));
// print_line(vformat("atlas loaded!")); // print_line(vformat("atlas loaded!"));
if (atlas) if (atlas)
return OK; return OK;
tex_list.clear(); tex_list.clear();
ntex_list.clear(); ntex_list.clear();
return ERR_FILE_UNRECOGNIZED; return ERR_FILE_UNRECOGNIZED;
} }
Error SpineAtlasResource::load_from_file(const String &p_path) { Error SpineAtlasResource::load_from_file(const String &p_path) {
Error err; Error err;
String json_string = FileAccess::get_file_as_string(p_path, &err); String json_string = FileAccess::get_file_as_string(p_path, &err);
if (err != OK) return err; if (err != OK) return err;
String error_string; String error_string;
int error_line; int error_line;
JSON json; JSON json;
Variant result; Variant result;
err = json.parse(json_string, result, error_string, error_line); err = json.parse(json_string, result, error_string, error_line);
if (err != OK) { if (err != OK) {
return err; return err;
} }
Dictionary content = Dictionary(result); Dictionary content = Dictionary(result);
source_path = content["source_path"]; source_path = content["source_path"];
atlas_data = content["atlas_data"]; atlas_data = content["atlas_data"];
normal_texture_prefix = content["normal_texture_prefix"]; normal_texture_prefix = content["normal_texture_prefix"];
if (atlas) delete atlas; if (atlas) delete atlas;
tex_list.clear(); tex_list.clear();
ntex_list.clear(); ntex_list.clear();
atlas = new spine::Atlas(atlas_data.utf8(), atlas_data.size(), source_path.get_base_dir().utf8(), new GodotSpineTextureLoader(&tex_list, &ntex_list, normal_texture_prefix)); atlas = new spine::Atlas(atlas_data.utf8(), atlas_data.size(), source_path.get_base_dir().utf8(), new GodotSpineTextureLoader(&tex_list, &ntex_list, normal_texture_prefix));
if (atlas) if (atlas)
return OK; return OK;
tex_list.clear(); tex_list.clear();
ntex_list.clear(); ntex_list.clear();
return ERR_FILE_UNRECOGNIZED; return ERR_FILE_UNRECOGNIZED;
} }
Error SpineAtlasResource::save_to_file(const String &p_path) { Error SpineAtlasResource::save_to_file(const String &p_path) {
Error err; Error err;
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
if (err != OK) { if (err != OK) {
// print_line(vformat("save file err: %d", err)); // print_line(vformat("save file err: %d", err));
if (file) file->close(); if (file) file->close();
return err; return err;
} }
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_texture_prefix; content["normal_texture_prefix"] = normal_texture_prefix;
// print_line(vformat("storing source_path: %s", source_path)); // print_line(vformat("storing source_path: %s", source_path));
file->store_string(JSON::print(content)); file->store_string(JSON::print(content));
file->close(); file->close();
return OK; return OK;
} }

View File

@ -31,7 +31,6 @@
#define GODOT_SPINEATLASRESOURCE_H #define GODOT_SPINEATLASRESOURCE_H
#include "core/variant_parser.h" #include "core/variant_parser.h"
#include <spine/SpineString.h> #include <spine/SpineString.h>
@ -41,39 +40,40 @@
#include <core/io/image_loader.h> #include <core/io/image_loader.h>
#include "SpineRendererObject.h" #include "SpineRendererObject.h"
class SpineAtlasResource : public Resource{ class SpineAtlasResource : public Resource {
GDCLASS(SpineAtlasResource, Resource); GDCLASS(SpineAtlasResource, Resource);
protected: protected:
static void _bind_methods(); static void _bind_methods();
spine::Atlas *atlas; spine::Atlas *atlas;
String source_path; String source_path;
String atlas_data; String atlas_data;
String normal_texture_prefix; String normal_texture_prefix;
Array tex_list;
Array ntex_list;
Array tex_list;
Array ntex_list;
public: public:
inline String &get_atlas_data() {return atlas_data;} inline String &get_atlas_data() { return atlas_data; }
inline spine::Atlas *get_spine_atlas() {return atlas;} inline spine::Atlas *get_spine_atlas() { return atlas; }
inline void set_normal_texture_prefix(const String &p) {normal_texture_prefix = p;} inline void set_normal_texture_prefix(const String &p) { normal_texture_prefix = p; }
Error load_from_atlas_file(const String &p_path); // .atlas Error load_from_atlas_file(const String &p_path);// .atlas
Error load_from_file(const String &p_path); // .spatlas Error load_from_file(const String &p_path);// .spatlas
Error save_to_file(const String &p_path); // .spatlas Error save_to_file(const String &p_path); // .spatlas
String get_source_path(); String get_source_path();
Array get_textures(); Array get_textures();
Array get_normal_textures(); Array get_normal_textures();
SpineAtlasResource(); SpineAtlasResource();
virtual ~SpineAtlasResource(); virtual ~SpineAtlasResource();
}; };
#endif //GODOT_SPINEATLASRESOURCE_H #endif//GODOT_SPINEATLASRESOURCE_H

View File

@ -34,21 +34,21 @@ void SpineAttachment::_bind_methods() {
ClassDB::bind_method(D_METHOD("copy"), &SpineAttachment::copy); ClassDB::bind_method(D_METHOD("copy"), &SpineAttachment::copy);
} }
SpineAttachment::SpineAttachment():attachment(NULL) {} SpineAttachment::SpineAttachment() : attachment(NULL) {}
SpineAttachment::~SpineAttachment() { SpineAttachment::~SpineAttachment() {
if(attachment){ if (attachment) {
attachment->dereference(); attachment->dereference();
attachment = NULL; attachment = NULL;
} }
} }
String SpineAttachment::get_attachment_name(){ String SpineAttachment::get_attachment_name() {
return attachment->getName().buffer(); return attachment->getName().buffer();
} }
Ref<SpineAttachment> SpineAttachment::copy(){ Ref<SpineAttachment> SpineAttachment::copy() {
auto a = attachment->copy(); auto a = attachment->copy();
if(a == NULL) return NULL; if (a == NULL) return NULL;
Ref<SpineAttachment> gd_attachment(memnew(SpineAttachment)); Ref<SpineAttachment> gd_attachment(memnew(SpineAttachment));
gd_attachment->set_spine_object(a); gd_attachment->set_spine_object(a);
return gd_attachment; return gd_attachment;

View File

@ -47,12 +47,12 @@ public:
SpineAttachment(); SpineAttachment();
~SpineAttachment(); ~SpineAttachment();
inline void set_spine_object(spine::Attachment *a){ inline void set_spine_object(spine::Attachment *a) {
attachment = a; attachment = a;
if(attachment) if (attachment)
attachment->reference(); attachment->reference();
} }
inline spine::Attachment *get_spine_object(){ inline spine::Attachment *get_spine_object() {
return attachment; return attachment;
} }
@ -61,4 +61,4 @@ public:
Ref<SpineAttachment> copy(); Ref<SpineAttachment> copy();
}; };
#endif //GODOT_SPINEATTACHMENT_H #endif//GODOT_SPINEATTACHMENT_H

View File

@ -34,52 +34,52 @@
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);
// void set_to_setup_pose(); // void set_to_setup_pose();
// //
// Vector2 world_to_local(Vector2 world_position); // Vector2 world_to_local(Vector2 world_position);
// //
// Vector2 local_to_world(Vector2 local_position); // Vector2 local_to_world(Vector2 local_position);
// //
// float world_to_local_rotation(float world_rotation); // float world_to_local_rotation(float world_rotation);
// //
// float local_to_world_rotation(float local_rotation); // float local_to_world_rotation(float local_rotation);
// //
// void rotate_world(float degrees); // void rotate_world(float degrees);
ClassDB::bind_method(D_METHOD("set_to_setup_pose"), &SpineBone::set_to_setup_pose); ClassDB::bind_method(D_METHOD("set_to_setup_pose"), &SpineBone::set_to_setup_pose);
ClassDB::bind_method(D_METHOD("world_to_local", "world_position"), &SpineBone::world_to_local); ClassDB::bind_method(D_METHOD("world_to_local", "world_position"), &SpineBone::world_to_local);
ClassDB::bind_method(D_METHOD("local_to_world", "local_position"), &SpineBone::local_to_world); ClassDB::bind_method(D_METHOD("local_to_world", "local_position"), &SpineBone::local_to_world);
ClassDB::bind_method(D_METHOD("world_to_local_rotation", "world_rotation"), &SpineBone::world_to_local_rotation); ClassDB::bind_method(D_METHOD("world_to_local_rotation", "world_rotation"), &SpineBone::world_to_local_rotation);
ClassDB::bind_method(D_METHOD("local_to_world_rotation", "local_rotation"), &SpineBone::local_to_world_rotation); ClassDB::bind_method(D_METHOD("local_to_world_rotation", "local_rotation"), &SpineBone::local_to_world_rotation);
ClassDB::bind_method(D_METHOD("rotate_world"), &SpineBone::rotate_world); ClassDB::bind_method(D_METHOD("rotate_world"), &SpineBone::rotate_world);
// //
// float get_world_to_local_rotation_x(); // float get_world_to_local_rotation_x();
// float get_world_to_local_rotation_y(); // float get_world_to_local_rotation_y();
// //
// Ref<SpineBoneData> get_data(); // Ref<SpineBoneData> get_data();
// //
// Ref<SpineSkeleton> get_skeleton(); // Ref<SpineSkeleton> get_skeleton();
// //
// Ref<SpineBone> get_parent(); // Ref<SpineBone> get_parent();
// //
// Array get_children(); // Array get_children();
ClassDB::bind_method(D_METHOD("get_world_to_local_rotation_x"), &SpineBone::get_world_to_local_rotation_x); ClassDB::bind_method(D_METHOD("get_world_to_local_rotation_x"), &SpineBone::get_world_to_local_rotation_x);
ClassDB::bind_method(D_METHOD("get_world_to_local_rotation_y"), &SpineBone::get_world_to_local_rotation_y); ClassDB::bind_method(D_METHOD("get_world_to_local_rotation_y"), &SpineBone::get_world_to_local_rotation_y);
ClassDB::bind_method(D_METHOD("get_data"), &SpineBone::get_data); ClassDB::bind_method(D_METHOD("get_data"), &SpineBone::get_data);
ClassDB::bind_method(D_METHOD("get_skeleton"), &SpineBone::get_skeleton); ClassDB::bind_method(D_METHOD("get_skeleton"), &SpineBone::get_skeleton);
ClassDB::bind_method(D_METHOD("get_parent"), &SpineBone::get_parent); ClassDB::bind_method(D_METHOD("get_parent"), &SpineBone::get_parent);
ClassDB::bind_method(D_METHOD("get_children"), &SpineBone::get_children); ClassDB::bind_method(D_METHOD("get_children"), &SpineBone::get_children);
// //
// 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_rotation(); // float get_rotation();
// void set_rotation(float v); // void set_rotation(float v);
// //
// float get_scale_x(); // float get_scale_x();
// void set_scale_x(float v); // void set_scale_x(float v);
ClassDB::bind_method(D_METHOD("get_x"), &SpineBone::get_x); ClassDB::bind_method(D_METHOD("get_x"), &SpineBone::get_x);
ClassDB::bind_method(D_METHOD("set_x", "v"), &SpineBone::set_x); ClassDB::bind_method(D_METHOD("set_x", "v"), &SpineBone::set_x);
ClassDB::bind_method(D_METHOD("get_y"), &SpineBone::get_y); ClassDB::bind_method(D_METHOD("get_y"), &SpineBone::get_y);
@ -88,18 +88,18 @@ void SpineBone::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_rotation", "v"), &SpineBone::set_rotation); ClassDB::bind_method(D_METHOD("set_rotation", "v"), &SpineBone::set_rotation);
ClassDB::bind_method(D_METHOD("get_scale_x"), &SpineBone::get_scale_x); ClassDB::bind_method(D_METHOD("get_scale_x"), &SpineBone::get_scale_x);
ClassDB::bind_method(D_METHOD("set_scale_x", "v"), &SpineBone::set_scale_x); ClassDB::bind_method(D_METHOD("set_scale_x", "v"), &SpineBone::set_scale_x);
// //
// float get_scale_y(); // float get_scale_y();
// void set_scale_y(float v); // void set_scale_y(float v);
// //
// float get_shear_x(); // float get_shear_x();
// void set_shear_x(float v); // void set_shear_x(float v);
// //
// float get_shear_y(); // float get_shear_y();
// void set_shear_y(float v); // void set_shear_y(float v);
// //
// float get_applied_rotation(); // float get_applied_rotation();
// void set_applied_rotation(float v); // void set_applied_rotation(float v);
ClassDB::bind_method(D_METHOD("get_scale_y"), &SpineBone::get_scale_y); ClassDB::bind_method(D_METHOD("get_scale_y"), &SpineBone::get_scale_y);
ClassDB::bind_method(D_METHOD("set_scale_y", "v"), &SpineBone::set_scale_y); ClassDB::bind_method(D_METHOD("set_scale_y", "v"), &SpineBone::set_scale_y);
ClassDB::bind_method(D_METHOD("get_shear_x"), &SpineBone::get_shear_x); ClassDB::bind_method(D_METHOD("get_shear_x"), &SpineBone::get_shear_x);
@ -108,18 +108,18 @@ void SpineBone::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_shear_y", "v"), &SpineBone::set_shear_y); ClassDB::bind_method(D_METHOD("set_shear_y", "v"), &SpineBone::set_shear_y);
ClassDB::bind_method(D_METHOD("get_applied_rotation"), &SpineBone::get_applied_rotation); ClassDB::bind_method(D_METHOD("get_applied_rotation"), &SpineBone::get_applied_rotation);
ClassDB::bind_method(D_METHOD("set_applied_rotation", "v"), &SpineBone::set_applied_rotation); ClassDB::bind_method(D_METHOD("set_applied_rotation", "v"), &SpineBone::set_applied_rotation);
// //
// float get_a_x(); // float get_a_x();
// void set_a_x(float v); // void set_a_x(float v);
// //
// float get_a_y(); // float get_a_y();
// void set_a_y(float v); // void set_a_y(float v);
// //
// float get_a_scale_x(); // float get_a_scale_x();
// void set_a_scale_x(float v); // void set_a_scale_x(float v);
// //
// float get_a_scale_y(); // float get_a_scale_y();
// void set_a_scale_y(float v); // void set_a_scale_y(float v);
ClassDB::bind_method(D_METHOD("get_a_x"), &SpineBone::get_a_x); ClassDB::bind_method(D_METHOD("get_a_x"), &SpineBone::get_a_x);
ClassDB::bind_method(D_METHOD("set_a_x", "v"), &SpineBone::set_a_x); ClassDB::bind_method(D_METHOD("set_a_x", "v"), &SpineBone::set_a_x);
ClassDB::bind_method(D_METHOD("get_a_y"), &SpineBone::get_a_y); ClassDB::bind_method(D_METHOD("get_a_y"), &SpineBone::get_a_y);
@ -128,18 +128,18 @@ void SpineBone::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_a_scale_x", "v"), &SpineBone::set_a_scale_x); ClassDB::bind_method(D_METHOD("set_a_scale_x", "v"), &SpineBone::set_a_scale_x);
ClassDB::bind_method(D_METHOD("get_a_scale_y"), &SpineBone::get_a_scale_y); ClassDB::bind_method(D_METHOD("get_a_scale_y"), &SpineBone::get_a_scale_y);
ClassDB::bind_method(D_METHOD("set_a_scale_y", "v"), &SpineBone::set_a_scale_y); ClassDB::bind_method(D_METHOD("set_a_scale_y", "v"), &SpineBone::set_a_scale_y);
// //
// float get_a_shear_x(); // float get_a_shear_x();
// void set_a_shear_x(float v); // void set_a_shear_x(float v);
// //
// float get_a_shear_y(); // float get_a_shear_y();
// void set_a_shear_y(float v); // void set_a_shear_y(float v);
// //
// float get_a(); // float get_a();
// void set_a(float v); // void set_a(float v);
// //
// float get_b(); // float get_b();
// void set_b(float v); // void set_b(float v);
ClassDB::bind_method(D_METHOD("get_a_shear_x"), &SpineBone::get_a_shear_x); ClassDB::bind_method(D_METHOD("get_a_shear_x"), &SpineBone::get_a_shear_x);
ClassDB::bind_method(D_METHOD("set_a_shear_x", "v"), &SpineBone::set_a_shear_x); ClassDB::bind_method(D_METHOD("set_a_shear_x", "v"), &SpineBone::set_a_shear_x);
ClassDB::bind_method(D_METHOD("get_a_shear_y"), &SpineBone::get_a_shear_y); ClassDB::bind_method(D_METHOD("get_a_shear_y"), &SpineBone::get_a_shear_y);
@ -148,18 +148,18 @@ void SpineBone::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_a", "v"), &SpineBone::set_a); ClassDB::bind_method(D_METHOD("set_a", "v"), &SpineBone::set_a);
ClassDB::bind_method(D_METHOD("get_b"), &SpineBone::get_b); ClassDB::bind_method(D_METHOD("get_b"), &SpineBone::get_b);
ClassDB::bind_method(D_METHOD("set_b", "v"), &SpineBone::set_b); ClassDB::bind_method(D_METHOD("set_b", "v"), &SpineBone::set_b);
// //
// float get_c(); // float get_c();
// void set_c(float v); // void set_c(float v);
// //
// float get_d(); // float get_d();
// void set_d(float v); // void set_d(float v);
// //
// float get_world_x(); // float get_world_x();
// void set_world_x(float v); // void set_world_x(float v);
// //
// float get_world_y(); // float get_world_y();
// void set_world_y(float v); // void set_world_y(float v);
ClassDB::bind_method(D_METHOD("get_c"), &SpineBone::get_c); ClassDB::bind_method(D_METHOD("get_c"), &SpineBone::get_c);
ClassDB::bind_method(D_METHOD("set_c", "v"), &SpineBone::set_c); ClassDB::bind_method(D_METHOD("set_c", "v"), &SpineBone::set_c);
ClassDB::bind_method(D_METHOD("get_d"), &SpineBone::get_d); ClassDB::bind_method(D_METHOD("get_d"), &SpineBone::get_d);
@ -168,18 +168,18 @@ void SpineBone::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_world_x", "v"), &SpineBone::set_world_x); ClassDB::bind_method(D_METHOD("set_world_x", "v"), &SpineBone::set_world_x);
ClassDB::bind_method(D_METHOD("get_world_y"), &SpineBone::get_world_y); ClassDB::bind_method(D_METHOD("get_world_y"), &SpineBone::get_world_y);
ClassDB::bind_method(D_METHOD("set_world_y", "v"), &SpineBone::set_world_y); ClassDB::bind_method(D_METHOD("set_world_y", "v"), &SpineBone::set_world_y);
// //
// float get_world_rotation_x(); // float get_world_rotation_x();
// float get_world_rotation_y(); // float get_world_rotation_y();
// //
// float get_world_scale_x(); // float get_world_scale_x();
// float get_world_scale_y(); // float get_world_scale_y();
// //
// bool is_applied_valid(); // bool is_applied_valid();
// void set_applied_valid(bool v); // void set_applied_valid(bool v);
// //
// bool is_active(); // bool is_active();
// void set_active(bool v); // void set_active(bool v);
ClassDB::bind_method(D_METHOD("get_world_rotation_x"), &SpineBone::get_world_rotation_x); ClassDB::bind_method(D_METHOD("get_world_rotation_x"), &SpineBone::get_world_rotation_x);
ClassDB::bind_method(D_METHOD("get_world_rotation_y"), &SpineBone::get_world_rotation_y); ClassDB::bind_method(D_METHOD("get_world_rotation_y"), &SpineBone::get_world_rotation_y);
ClassDB::bind_method(D_METHOD("get_world_scale_x"), &SpineBone::get_world_scale_x); ClassDB::bind_method(D_METHOD("get_world_scale_x"), &SpineBone::get_world_scale_x);
@ -189,62 +189,62 @@ void SpineBone::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_godot_transform"), &SpineBone::get_godot_transform); ClassDB::bind_method(D_METHOD("get_godot_transform"), &SpineBone::get_godot_transform);
ClassDB::bind_method(D_METHOD("set_godot_transform", "local_transform"), &SpineBone::set_godot_transform); ClassDB::bind_method(D_METHOD("set_godot_transform", "local_transform"), &SpineBone::set_godot_transform);
ClassDB::bind_method(D_METHOD("get_godot_global_transform"), &SpineBone::get_godot_global_transform); ClassDB::bind_method(D_METHOD("get_godot_global_transform"), &SpineBone::get_godot_global_transform);
ClassDB::bind_method(D_METHOD("set_godot_global_transform", "global_transform"), &SpineBone::set_godot_global_transform); ClassDB::bind_method(D_METHOD("set_godot_global_transform", "global_transform"), &SpineBone::set_godot_global_transform);
ClassDB::bind_method(D_METHOD("apply_world_transform_2d", "node2d"), &SpineBone::apply_world_transform_2d); ClassDB::bind_method(D_METHOD("apply_world_transform_2d", "node2d"), &SpineBone::apply_world_transform_2d);
} }
SpineBone::SpineBone():bone(NULL), the_sprite(nullptr) {} SpineBone::SpineBone() : bone(NULL), the_sprite(nullptr) {}
SpineBone::~SpineBone() {} SpineBone::~SpineBone() {}
void SpineBone::update_world_transform(){ void SpineBone::update_world_transform() {
bone->updateWorldTransform(); bone->updateWorldTransform();
} }
void SpineBone::set_to_setup_pose(){ void SpineBone::set_to_setup_pose() {
bone->setToSetupPose(); bone->setToSetupPose();
} }
Vector2 SpineBone::world_to_local(Vector2 world_position){ Vector2 SpineBone::world_to_local(Vector2 world_position) {
float x, y; float x, y;
bone->worldToLocal(world_position.x, world_position.y, x, y); bone->worldToLocal(world_position.x, world_position.y, x, y);
return Vector2(x, y); return Vector2(x, y);
} }
Vector2 SpineBone::local_to_world(Vector2 local_position){ Vector2 SpineBone::local_to_world(Vector2 local_position) {
float x, y; float x, y;
bone->localToWorld(local_position.x, local_position.y, x, y); bone->localToWorld(local_position.x, local_position.y, x, y);
return Vector2(x, y); return Vector2(x, y);
} }
float SpineBone::world_to_local_rotation(float world_rotation){ float SpineBone::world_to_local_rotation(float world_rotation) {
return bone->worldToLocalRotation(world_rotation); return bone->worldToLocalRotation(world_rotation);
} }
float SpineBone::local_to_world_rotation(float local_rotation){ float SpineBone::local_to_world_rotation(float local_rotation) {
return bone->localToWorldRotation(local_rotation); return bone->localToWorldRotation(local_rotation);
} }
void SpineBone::rotate_world(float degrees){ void SpineBone::rotate_world(float degrees) {
bone->rotateWorld(degrees); bone->rotateWorld(degrees);
} }
float SpineBone::get_world_to_local_rotation_x(){ float SpineBone::get_world_to_local_rotation_x() {
return bone->getWorldToLocalRotationX(); return bone->getWorldToLocalRotationX();
} }
float SpineBone::get_world_to_local_rotation_y(){ float SpineBone::get_world_to_local_rotation_y() {
return bone->getWorldToLocalRotationY(); return bone->getWorldToLocalRotationY();
} }
Ref<SpineBoneData> SpineBone::get_data(){ Ref<SpineBoneData> SpineBone::get_data() {
auto &bd = bone->getData(); auto &bd = bone->getData();
Ref<SpineBoneData> gd_bd(memnew(SpineBoneData)); Ref<SpineBoneData> gd_bd(memnew(SpineBoneData));
gd_bd->set_spine_object(&bd); gd_bd->set_spine_object(&bd);
return gd_bd; return gd_bd;
} }
Ref<SpineSkeleton> SpineBone::get_skeleton(){ Ref<SpineSkeleton> SpineBone::get_skeleton() {
auto &s = bone->getSkeleton(); auto &s = bone->getSkeleton();
Ref<SpineSkeleton> gd_s(memnew(SpineSkeleton)); Ref<SpineSkeleton> gd_s(memnew(SpineSkeleton));
gd_s->set_spine_object(&s); gd_s->set_spine_object(&s);
@ -252,22 +252,22 @@ Ref<SpineSkeleton> SpineBone::get_skeleton(){
return gd_s; return gd_s;
} }
Ref<SpineBone> SpineBone::get_parent(){ Ref<SpineBone> SpineBone::get_parent() {
auto b = bone->getParent(); auto b = bone->getParent();
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineBone> gd_b(memnew(SpineBone)); Ref<SpineBone> gd_b(memnew(SpineBone));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
gd_b->set_spine_sprite(the_sprite); gd_b->set_spine_sprite(the_sprite);
return gd_b; return gd_b;
} }
Array SpineBone::get_children(){ Array SpineBone::get_children() {
auto bs = bone->getChildren(); auto bs = bone->getChildren();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
auto b = bs[i]; auto b = bs[i];
if(b == NULL) gd_bs[i] = Ref<SpineBone>(NULL); if (b == NULL) gd_bs[i] = Ref<SpineBone>(NULL);
Ref<SpineBone> gd_b(memnew(SpineBone)); Ref<SpineBone> gd_b(memnew(SpineBone));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
gd_b->set_spine_sprite(the_sprite); gd_b->set_spine_sprite(the_sprite);
@ -276,179 +276,178 @@ Array SpineBone::get_children(){
return gd_bs; return gd_bs;
} }
float SpineBone::get_x(){ float SpineBone::get_x() {
return bone->getX(); return bone->getX();
} }
void SpineBone::set_x(float v){ void SpineBone::set_x(float v) {
bone->setX(v); bone->setX(v);
} }
float SpineBone::get_y(){ float SpineBone::get_y() {
return bone->getY(); return bone->getY();
} }
void SpineBone::set_y(float v){ void SpineBone::set_y(float v) {
bone->setY(v); bone->setY(v);
} }
float SpineBone::get_rotation(){ float SpineBone::get_rotation() {
return bone->getRotation(); return bone->getRotation();
} }
void SpineBone::set_rotation(float v){ void SpineBone::set_rotation(float v) {
bone->setRotation(v); bone->setRotation(v);
} }
float SpineBone::get_scale_x(){ float SpineBone::get_scale_x() {
return bone->getScaleX(); return bone->getScaleX();
} }
void SpineBone::set_scale_x(float v){ void SpineBone::set_scale_x(float v) {
bone->setScaleX(v); bone->setScaleX(v);
} }
float SpineBone::get_scale_y(){ float SpineBone::get_scale_y() {
return bone->getScaleY(); return bone->getScaleY();
} }
void SpineBone::set_scale_y(float v){ void SpineBone::set_scale_y(float v) {
bone->setScaleY(v); bone->setScaleY(v);
} }
float SpineBone::get_shear_x(){ float SpineBone::get_shear_x() {
return bone->getShearX(); return bone->getShearX();
} }
void SpineBone::set_shear_x(float v){ void SpineBone::set_shear_x(float v) {
bone->setShearX(v); bone->setShearX(v);
} }
float SpineBone::get_shear_y(){ float SpineBone::get_shear_y() {
return bone->getShearY(); return bone->getShearY();
} }
void SpineBone::set_shear_y(float v){ void SpineBone::set_shear_y(float v) {
bone->setShearY(v); bone->setShearY(v);
} }
float SpineBone::get_applied_rotation(){ float SpineBone::get_applied_rotation() {
return bone->getAppliedRotation(); return bone->getAppliedRotation();
} }
void SpineBone::set_applied_rotation(float v){ void SpineBone::set_applied_rotation(float v) {
bone->setAppliedRotation(v); bone->setAppliedRotation(v);
} }
float SpineBone::get_a_x(){ float SpineBone::get_a_x() {
return bone->getAX(); return bone->getAX();
} }
void SpineBone::set_a_x(float v){ void SpineBone::set_a_x(float v) {
bone->setAX(v); bone->setAX(v);
} }
float SpineBone::get_a_y(){ float SpineBone::get_a_y() {
return bone->getAY(); return bone->getAY();
} }
void SpineBone::set_a_y(float v){ void SpineBone::set_a_y(float v) {
bone->setAY(v); bone->setAY(v);
} }
float SpineBone::get_a_scale_x(){ float SpineBone::get_a_scale_x() {
return bone->getAScaleX(); return bone->getAScaleX();
} }
void SpineBone::set_a_scale_x(float v){ void SpineBone::set_a_scale_x(float v) {
bone->setAScaleX(v); bone->setAScaleX(v);
} }
float SpineBone::get_a_scale_y(){ float SpineBone::get_a_scale_y() {
return bone->getAScaleY(); return bone->getAScaleY();
} }
void SpineBone::set_a_scale_y(float v){ void SpineBone::set_a_scale_y(float v) {
bone->setAScaleY(v); bone->setAScaleY(v);
} }
float SpineBone::get_a_shear_x(){ float SpineBone::get_a_shear_x() {
return bone->getAShearX(); return bone->getAShearX();
} }
void SpineBone::set_a_shear_x(float v){ void SpineBone::set_a_shear_x(float v) {
bone->setAShearX(v); bone->setAShearX(v);
} }
float SpineBone::get_a_shear_y(){ float SpineBone::get_a_shear_y() {
return bone->getAShearY(); return bone->getAShearY();
} }
void SpineBone::set_a_shear_y(float v){ void SpineBone::set_a_shear_y(float v) {
bone->setAShearY(v); bone->setAShearY(v);
} }
float SpineBone::get_a(){ float SpineBone::get_a() {
return bone->getA(); return bone->getA();
} }
void SpineBone::set_a(float v){ void SpineBone::set_a(float v) {
bone->setA(v); bone->setA(v);
} }
float SpineBone::get_b(){ float SpineBone::get_b() {
return bone->getB(); return bone->getB();
} }
void SpineBone::set_b(float v){ void SpineBone::set_b(float v) {
bone->setB(v); bone->setB(v);
} }
float SpineBone::get_c(){ float SpineBone::get_c() {
return bone->getC(); return bone->getC();
} }
void SpineBone::set_c(float v){ void SpineBone::set_c(float v) {
bone->setC(v); bone->setC(v);
} }
float SpineBone::get_d(){ float SpineBone::get_d() {
return bone->getD(); return bone->getD();
} }
void SpineBone::set_d(float v){ void SpineBone::set_d(float v) {
bone->setD(v); bone->setD(v);
} }
float SpineBone::get_world_x(){ float SpineBone::get_world_x() {
return bone->getWorldX(); return bone->getWorldX();
} }
void SpineBone::set_world_x(float v){ void SpineBone::set_world_x(float v) {
bone->setWorldX(v); bone->setWorldX(v);
} }
float SpineBone::get_world_y(){ float SpineBone::get_world_y() {
return bone->getWorldY(); return bone->getWorldY();
} }
void SpineBone::set_world_y(float v){ void SpineBone::set_world_y(float v) {
bone->setWorldY(v); bone->setWorldY(v);
} }
float SpineBone::get_world_rotation_x(){ float SpineBone::get_world_rotation_x() {
return bone->getWorldRotationX(); return bone->getWorldRotationX();
} }
float SpineBone::get_world_rotation_y(){ float SpineBone::get_world_rotation_y() {
return bone->getWorldRotationY(); return bone->getWorldRotationY();
} }
float SpineBone::get_world_scale_x(){ float SpineBone::get_world_scale_x() {
return bone->getWorldScaleX(); return bone->getWorldScaleX();
} }
float SpineBone::get_world_scale_y(){ float SpineBone::get_world_scale_y() {
return bone->getWorldScaleY(); return bone->getWorldScaleY();
} }
bool SpineBone::is_active(){ bool SpineBone::is_active() {
return bone->isActive(); return bone->isActive();
} }
void SpineBone::set_active(bool v){ void SpineBone::set_active(bool v) {
bone->setActive(v); bone->setActive(v);
} }
// External feature functions // External feature functions
void SpineBone::apply_world_transform_2d(Variant o){ void SpineBone::apply_world_transform_2d(Variant o) {
if(o.get_type() == Variant::OBJECT){ if (o.get_type() == Variant::OBJECT) {
auto node = (Node*) o; auto node = (Node *) o;
if(node->is_class("Node2D")){ if (node->is_class("Node2D")) {
auto node2d = (Node2D*) node; 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(),
get_b(), get_d(), get_b(), get_d(),
get_world_x(), -get_world_y()) get_world_x(), -get_world_y()));
);
// Fix the rotation // Fix the rotation
auto pos = node2d->get_position(); auto pos = node2d->get_position();
node2d->translate(-pos); node2d->translate(-pos);
@ -459,79 +458,79 @@ void SpineBone::apply_world_transform_2d(Variant o){
} }
Transform2D SpineBone::get_godot_transform() { Transform2D SpineBone::get_godot_transform() {
if (get_spine_object() == nullptr) if (get_spine_object() == nullptr)
return Transform2D(); return Transform2D();
Transform2D trans; Transform2D trans;
trans.translate(get_x(), -get_y()); trans.translate(get_x(), -get_y());
// It seems that spine uses degree for rotation // It seems that spine uses degree for rotation
trans.rotate(Math::deg2rad(-get_rotation())); trans.rotate(Math::deg2rad(-get_rotation()));
trans.scale(Size2(get_scale_x(), get_scale_y())); trans.scale(Size2(get_scale_x(), get_scale_y()));
return trans; return trans;
} }
void SpineBone::set_godot_transform(Transform2D trans) { void SpineBone::set_godot_transform(Transform2D trans) {
if (get_spine_object() == nullptr) if (get_spine_object() == nullptr)
return; return;
Vector2 position = trans.get_origin(); Vector2 position = trans.get_origin();
position.y *= -1; position.y *= -1;
real_t rotation = trans.get_rotation(); real_t rotation = trans.get_rotation();
rotation = Math::rad2deg(-rotation); rotation = Math::rad2deg(-rotation);
Vector2 scale = trans.get_scale(); Vector2 scale = trans.get_scale();
set_x(position.x); set_x(position.x);
set_y(position.y); set_y(position.y);
set_rotation(rotation); set_rotation(rotation);
set_scale_x(scale.x); set_scale_x(scale.x);
set_scale_y(scale.y); set_scale_y(scale.y);
} }
Transform2D SpineBone::get_godot_global_transform() { Transform2D SpineBone::get_godot_global_transform() {
if (get_spine_object() == nullptr) if (get_spine_object() == nullptr)
return Transform2D(); return Transform2D();
if (the_sprite == nullptr) if (the_sprite == nullptr)
return get_godot_transform(); return get_godot_transform();
Transform2D res = the_sprite->get_transform(); Transform2D res = the_sprite->get_transform();
res.translate(get_world_x(), -get_world_y()); res.translate(get_world_x(), -get_world_y());
res.rotate(Math::deg2rad(-get_world_rotation_x())); res.rotate(Math::deg2rad(-get_world_rotation_x()));
res.scale(Vector2(get_world_scale_x(), get_world_scale_y())); res.scale(Vector2(get_world_scale_x(), get_world_scale_y()));
auto p = the_sprite->get_parent() ? Object::cast_to<CanvasItem>(the_sprite->get_parent()) : nullptr; auto p = the_sprite->get_parent() ? Object::cast_to<CanvasItem>(the_sprite->get_parent()) : nullptr;
if (p) { if (p) {
return p->get_global_transform() * res; return p->get_global_transform() * res;
} }
return res; return res;
} }
void SpineBone::set_godot_global_transform(Transform2D transform) { void SpineBone::set_godot_global_transform(Transform2D transform) {
if (get_spine_object() == nullptr) if (get_spine_object() == nullptr)
return; return;
if (the_sprite == nullptr) if (the_sprite == nullptr)
set_godot_transform(transform); set_godot_transform(transform);
transform = the_sprite->get_global_transform().affine_inverse() * transform; transform = the_sprite->get_global_transform().affine_inverse() * transform;
Vector2 position = transform.get_origin(); Vector2 position = transform.get_origin();
real_t rotation = transform.get_rotation(); real_t rotation = transform.get_rotation();
Vector2 scale = transform.get_scale(); Vector2 scale = transform.get_scale();
position.y *= -1; position.y *= -1;
auto parent = get_parent(); auto parent = get_parent();
if (parent.is_valid()) { if (parent.is_valid()) {
position = parent->world_to_local(position); position = parent->world_to_local(position);
if (parent->get_world_scale_x() != 0) if (parent->get_world_scale_x() != 0)
scale.x /= parent->get_world_scale_x(); scale.x /= parent->get_world_scale_x();
else else
print_error("The parent scale.x is zero."); print_error("The parent scale.x is zero.");
if (parent->get_world_scale_y() != 0) if (parent->get_world_scale_y() != 0)
scale.y /= parent->get_world_scale_y(); scale.y /= parent->get_world_scale_y();
else else
print_error("The parent scale.y is zero."); print_error("The parent scale.y is zero.");
} }
rotation = world_to_local_rotation(Math::rad2deg(-rotation)); rotation = world_to_local_rotation(Math::rad2deg(-rotation));
set_x(position.x); set_x(position.x);
set_y(position.y); set_y(position.y);
set_rotation(rotation); set_rotation(rotation);
set_scale_x(scale.x); set_scale_x(scale.x);
set_scale_y(scale.y); set_scale_y(scale.y);
} }
void SpineBone::set_spine_sprite(SpineSprite *s) { void SpineBone::set_spine_sprite(SpineSprite *s) {
the_sprite = s; the_sprite = s;
} }

View File

@ -54,14 +54,15 @@ private:
spine::Bone *bone; spine::Bone *bone;
SpineSprite *the_sprite; SpineSprite *the_sprite;
public: public:
SpineBone(); SpineBone();
~SpineBone(); ~SpineBone();
inline void set_spine_object(spine::Bone *b){ inline void set_spine_object(spine::Bone *b) {
bone = b; bone = b;
} }
inline spine::Bone *get_spine_object(){ inline spine::Bone *get_spine_object() {
return bone; return bone;
} }
@ -171,4 +172,4 @@ public:
void set_godot_global_transform(Transform2D trans); void set_godot_global_transform(Transform2D trans);
}; };
#endif //GODOT_SPINEBONE_H #endif//GODOT_SPINEBONE_H

View File

@ -71,93 +71,93 @@ void SpineBoneData::_bind_methods() {
BIND_ENUM_CONSTANT(TRANSFORMMODE_NOSCALEORREFLECTION); BIND_ENUM_CONSTANT(TRANSFORMMODE_NOSCALEORREFLECTION);
} }
SpineBoneData::SpineBoneData():bone_data(NULL) {} SpineBoneData::SpineBoneData() : bone_data(NULL) {}
SpineBoneData::~SpineBoneData() {} SpineBoneData::~SpineBoneData() {}
int SpineBoneData::get_index(){ int SpineBoneData::get_index() {
return bone_data->getIndex(); return bone_data->getIndex();
} }
String SpineBoneData::get_bone_name(){ String SpineBoneData::get_bone_name() {
return bone_data->getName().buffer(); return bone_data->getName().buffer();
} }
Ref<SpineBoneData> SpineBoneData::get_parent(){ Ref<SpineBoneData> SpineBoneData::get_parent() {
auto p = bone_data->getParent(); auto p = bone_data->getParent();
if(p == NULL) return NULL; if (p == NULL) return NULL;
Ref<SpineBoneData> gd_bone_data(memnew(SpineBoneData)); Ref<SpineBoneData> gd_bone_data(memnew(SpineBoneData));
gd_bone_data->set_spine_object(p); gd_bone_data->set_spine_object(p);
return gd_bone_data; return gd_bone_data;
} }
float SpineBoneData::get_length(){ float SpineBoneData::get_length() {
return bone_data->getLength(); return bone_data->getLength();
} }
void SpineBoneData::set_length(float v){ void SpineBoneData::set_length(float v) {
bone_data->setLength(v); bone_data->setLength(v);
} }
float SpineBoneData::get_x(){ float SpineBoneData::get_x() {
return bone_data->getX(); return bone_data->getX();
} }
void SpineBoneData::set_x(float v){ void SpineBoneData::set_x(float v) {
bone_data->setX(v); bone_data->setX(v);
} }
float SpineBoneData::get_y(){ float SpineBoneData::get_y() {
return bone_data->getY(); return bone_data->getY();
} }
void SpineBoneData::set_y(float v){ void SpineBoneData::set_y(float v) {
bone_data->setY(v); bone_data->setY(v);
} }
float SpineBoneData::get_rotation(){ float SpineBoneData::get_rotation() {
return bone_data->getRotation(); return bone_data->getRotation();
} }
void SpineBoneData::set_rotation(float v){ void SpineBoneData::set_rotation(float v) {
bone_data->setRotation(v); bone_data->setRotation(v);
} }
float SpineBoneData::get_scale_x(){ float SpineBoneData::get_scale_x() {
return bone_data->getScaleX(); return bone_data->getScaleX();
} }
void SpineBoneData::set_scale_x(float v){ void SpineBoneData::set_scale_x(float v) {
bone_data->setScaleX(v); bone_data->setScaleX(v);
} }
float SpineBoneData::get_scale_y(){ float SpineBoneData::get_scale_y() {
return bone_data->getScaleY(); return bone_data->getScaleY();
} }
void SpineBoneData::set_scale_y(float v){ void SpineBoneData::set_scale_y(float v) {
bone_data->setScaleY(v); bone_data->setScaleY(v);
} }
float SpineBoneData::get_shear_x(){ float SpineBoneData::get_shear_x() {
return bone_data->getShearX(); return bone_data->getShearX();
} }
void SpineBoneData::set_shear_x(float v){ void SpineBoneData::set_shear_x(float v) {
bone_data->setShearX(v); bone_data->setShearX(v);
} }
float SpineBoneData::get_shear_y(){ float SpineBoneData::get_shear_y() {
return bone_data->getShearY(); return bone_data->getShearY();
} }
void SpineBoneData::set_shear_y(float v){ void SpineBoneData::set_shear_y(float v) {
bone_data->setShearY(v); bone_data->setShearY(v);
} }
SpineBoneData::TransformMode SpineBoneData::get_transform_mode(){ SpineBoneData::TransformMode SpineBoneData::get_transform_mode() {
auto tm = (int)bone_data->getTransformMode(); auto tm = (int) bone_data->getTransformMode();
return (TransformMode) tm; return (TransformMode) tm;
} }
void SpineBoneData::set_transform_mode(TransformMode v){ void SpineBoneData::set_transform_mode(TransformMode v) {
auto tm = (int) v; auto tm = (int) v;
bone_data->setTransformMode((spine::TransformMode)tm); bone_data->setTransformMode((spine::TransformMode) tm);
} }
bool SpineBoneData::is_skin_required(){ bool SpineBoneData::is_skin_required() {
return bone_data->isSkinRequired(); return bone_data->isSkinRequired();
} }
void SpineBoneData::set_skin_required(bool v){ void SpineBoneData::set_skin_required(bool v) {
bone_data->setSkinRequired(v); bone_data->setSkinRequired(v);
} }

View File

@ -47,10 +47,10 @@ public:
SpineBoneData(); SpineBoneData();
~SpineBoneData(); ~SpineBoneData();
inline void set_spine_object(spine::BoneData *b){ inline void set_spine_object(spine::BoneData *b) {
bone_data = b; bone_data = b;
} }
inline spine::BoneData *get_spine_object(){ inline spine::BoneData *get_spine_object() {
return bone_data; return bone_data;
} }
@ -97,8 +97,7 @@ public:
bool is_skin_required(); bool is_skin_required();
void set_skin_required(bool v); void set_skin_required(bool v);
}; };
VARIANT_ENUM_CAST(SpineBoneData::TransformMode); VARIANT_ENUM_CAST(SpineBoneData::TransformMode);
#endif //GODOT_SPINEBONEDATA_H #endif//GODOT_SPINEBONEDATA_H

View File

@ -32,173 +32,165 @@
#include "SpineSprite.h" #include "SpineSprite.h"
void SpineCollisionShapeProxy::_bind_methods() { void SpineCollisionShapeProxy::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_spine_sprite_path"), &SpineCollisionShapeProxy::get_spine_sprite_path); ClassDB::bind_method(D_METHOD("get_spine_sprite_path"), &SpineCollisionShapeProxy::get_spine_sprite_path);
ClassDB::bind_method(D_METHOD("set_spine_sprite_path", "v"), &SpineCollisionShapeProxy::set_spine_sprite_path); ClassDB::bind_method(D_METHOD("set_spine_sprite_path", "v"), &SpineCollisionShapeProxy::set_spine_sprite_path);
ClassDB::bind_method(D_METHOD("get_slot"), &SpineCollisionShapeProxy::get_slot); ClassDB::bind_method(D_METHOD("get_slot"), &SpineCollisionShapeProxy::get_slot);
ClassDB::bind_method(D_METHOD("set_slot", "v"), &SpineCollisionShapeProxy::set_slot); ClassDB::bind_method(D_METHOD("set_slot", "v"), &SpineCollisionShapeProxy::set_slot);
ClassDB::bind_method(D_METHOD("get_sync_transform"), &SpineCollisionShapeProxy::get_sync_transform); ClassDB::bind_method(D_METHOD("get_sync_transform"), &SpineCollisionShapeProxy::get_sync_transform);
ClassDB::bind_method(D_METHOD("set_sync_transform", "v"), &SpineCollisionShapeProxy::set_sync_transform); ClassDB::bind_method(D_METHOD("set_sync_transform", "v"), &SpineCollisionShapeProxy::set_sync_transform);
ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "spine_sprite_path"), "set_spine_sprite_path", "get_spine_sprite_path"); ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "spine_sprite_path"), "set_spine_sprite_path", "get_spine_sprite_path");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sync_transform"), "set_sync_transform", "get_sync_transform"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sync_transform"), "set_sync_transform", "get_sync_transform");
} }
SpineCollisionShapeProxy::SpineCollisionShapeProxy():sync_transform(true) { SpineCollisionShapeProxy::SpineCollisionShapeProxy() : sync_transform(true) {
} }
SpineCollisionShapeProxy::~SpineCollisionShapeProxy() { SpineCollisionShapeProxy::~SpineCollisionShapeProxy() {
} }
void SpineCollisionShapeProxy::_notification(int p_what) { void SpineCollisionShapeProxy::_notification(int p_what) {
switch (p_what) { switch (p_what) {
case NOTIFICATION_READY: { case NOTIFICATION_READY: {
set_process_internal(true); set_process_internal(true);
} break; } break;
case NOTIFICATION_INTERNAL_PROCESS: { case NOTIFICATION_INTERNAL_PROCESS: {
if (!disabled) { if (!disabled) {
if (sync_transform) _sync_transform(get_spine_sprite()); if (sync_transform) _sync_transform(get_spine_sprite());
_update_polygon_from_spine_sprite(get_spine_sprite()); _update_polygon_from_spine_sprite(get_spine_sprite());
if (is_visible()) update(); if (is_visible()) update();
} }
} break; } break;
} }
} }
SpineSprite *SpineCollisionShapeProxy::get_spine_sprite() const { SpineSprite *SpineCollisionShapeProxy::get_spine_sprite() const {
return (SpineSprite*) get_node_or_null(spine_sprite_path); return (SpineSprite *) get_node_or_null(spine_sprite_path);
} }
NodePath SpineCollisionShapeProxy::get_spine_sprite_path() { NodePath SpineCollisionShapeProxy::get_spine_sprite_path() {
return spine_sprite_path; return spine_sprite_path;
} }
void SpineCollisionShapeProxy::set_spine_sprite_path(NodePath v) { void SpineCollisionShapeProxy::set_spine_sprite_path(NodePath v) {
spine_sprite_path = v; spine_sprite_path = v;
_update_polygon_from_spine_sprite(get_spine_sprite()); _update_polygon_from_spine_sprite(get_spine_sprite());
} }
String SpineCollisionShapeProxy::get_slot() const { String SpineCollisionShapeProxy::get_slot() const {
return slot; return slot;
} }
void SpineCollisionShapeProxy::set_slot(const String &v) { void SpineCollisionShapeProxy::set_slot(const String &v) {
slot = v; slot = v;
_update_polygon_from_spine_sprite(get_spine_sprite()); _update_polygon_from_spine_sprite(get_spine_sprite());
} }
void SpineCollisionShapeProxy::_update_polygon_from_spine_sprite(SpineSprite *sprite) { void SpineCollisionShapeProxy::_update_polygon_from_spine_sprite(SpineSprite *sprite) {
_clear_polygon(); _clear_polygon();
if (sprite == nullptr || slot.empty()) { if (sprite == nullptr || slot.empty()) {
return; return;
} }
if (!sprite->get_skeleton().is_valid()) { if (!sprite->get_skeleton().is_valid()) {
return; return;
} }
auto sk = sprite->get_skeleton()->get_spine_object(); auto sk = sprite->get_skeleton()->get_spine_object();
spine::Vector<float> vertices; spine::Vector<float> vertices;
spine::Slot *s = sk->findSlot(spine::String(slot.utf8())); spine::Slot *s = sk->findSlot(spine::String(slot.utf8()));
if (!s) { if (!s) {
return; return;
} }
spine::Attachment *attachment = s->getAttachment(); spine::Attachment *attachment = s->getAttachment();
if(!attachment){ if (!attachment) {
return; return;
} }
if (attachment->getRTTI().isExactly(spine::BoundingBoxAttachment::rtti)) { if (attachment->getRTTI().isExactly(spine::BoundingBoxAttachment::rtti)) {
auto *box = (spine::BoundingBoxAttachment*) attachment; auto *box = (spine::BoundingBoxAttachment *) attachment;
vertices.setSize(box->getWorldVerticesLength(), 0); vertices.setSize(box->getWorldVerticesLength(), 0);
box->computeWorldVertices(*s, vertices); box->computeWorldVertices(*s, vertices);
} else { } else {
return; return;
} }
polygon.resize(vertices.size()/2); polygon.resize(vertices.size() / 2);
for (size_t j=0; j < vertices.size(); j+=2) { for (size_t j = 0; j < vertices.size(); j += 2) {
polygon.set(j/2, Vector2(vertices[j], -vertices[j + 1])); polygon.set(j / 2, Vector2(vertices[j], -vertices[j + 1]));
} }
set_polygon(polygon); set_polygon(polygon);
} }
void SpineCollisionShapeProxy::_clear_polygon() { void SpineCollisionShapeProxy::_clear_polygon() {
polygon.clear(); polygon.clear();
set_polygon(polygon); set_polygon(polygon);
} }
void SpineCollisionShapeProxy::_sync_transform(SpineSprite *sprite) { void SpineCollisionShapeProxy::_sync_transform(SpineSprite *sprite) {
if (sprite == nullptr) return; if (sprite == nullptr) return;
set_global_transform(sprite->get_global_transform()); set_global_transform(sprite->get_global_transform());
} }
bool SpineCollisionShapeProxy::get_sync_transform() { bool SpineCollisionShapeProxy::get_sync_transform() {
return sync_transform; return sync_transform;
} }
void SpineCollisionShapeProxy::set_sync_transform(bool v) { void SpineCollisionShapeProxy::set_sync_transform(bool v) {
sync_transform = v; sync_transform = v;
} }
void SpineCollisionShapeProxy::_get_property_list(List<PropertyInfo> *p_list) const { void SpineCollisionShapeProxy::_get_property_list(List<PropertyInfo> *p_list) const {
PropertyInfo p; PropertyInfo p;
Vector<String> res; Vector<String> res;
p.name = "slot"; p.name = "slot";
p.type = Variant::STRING; p.type = Variant::STRING;
_get_slot_list(res); _get_slot_list(res);
if (res.empty()) res.push_back("No Slot"); if (res.empty()) res.push_back("No Slot");
p.hint_string = String(",").join(res); p.hint_string = String(",").join(res);
p.hint = PROPERTY_HINT_ENUM; p.hint = PROPERTY_HINT_ENUM;
p_list->push_back(p); p_list->push_back(p);
} }
bool SpineCollisionShapeProxy::_get(const StringName &p_property, Variant &r_value) const { bool SpineCollisionShapeProxy::_get(const StringName &p_property, Variant &r_value) const {
if (p_property == "slot") { if (p_property == "slot") {
r_value = get_slot(); r_value = get_slot();
return true; return true;
} }
return false; return false;
} }
bool SpineCollisionShapeProxy::_set(const StringName &p_property, const Variant &p_value) { bool SpineCollisionShapeProxy::_set(const StringName &p_property, const Variant &p_value) {
if (p_property == "slot") { if (p_property == "slot") {
set_slot(p_value); set_slot(p_value);
return true; return true;
} }
return false; return false;
} }
void SpineCollisionShapeProxy::_get_slot_list(Vector<String> &res) const { void SpineCollisionShapeProxy::_get_slot_list(Vector<String> &res) const {
if (get_spine_sprite() == nullptr) { if (get_spine_sprite() == nullptr) {
return; return;
} }
auto sprite = get_spine_sprite(); auto sprite = get_spine_sprite();
if (!sprite->get_skeleton().is_valid()) { if (!sprite->get_skeleton().is_valid()) {
return; return;
} }
auto slots = sprite->get_skeleton()->get_slots(); auto slots = sprite->get_skeleton()->get_slots();
res.resize(slots.size()); res.resize(slots.size());
for (size_t i=0; i < res.size(); ++i) { for (size_t i = 0; i < res.size(); ++i) {
auto slot = (Ref<SpineSlot>)slots[i]; auto slot = (Ref<SpineSlot>) slots[i];
if (slot.is_valid()) if (slot.is_valid())
res.set(i, slot->get_data()->get_slot_name()); res.set(i, slot->get_data()->get_slot_name());
} }
} }

View File

@ -36,43 +36,45 @@ class SpineSprite;
class SpineAnimationState; class SpineAnimationState;
class SpineSkeleton; class SpineSkeleton;
class SpineCollisionShapeProxy : public CollisionPolygon2D{ class SpineCollisionShapeProxy : public CollisionPolygon2D {
GDCLASS(SpineCollisionShapeProxy, CollisionPolygon2D) GDCLASS(SpineCollisionShapeProxy, CollisionPolygon2D)
protected: protected:
static void _bind_methods(); static void _bind_methods();
NodePath spine_sprite_path; NodePath spine_sprite_path;
String slot; String slot;
bool sync_transform;
bool sync_transform;
protected: protected:
void _notification(int p_what); void _notification(int p_what);
void _get_property_list(List<PropertyInfo> *p_list) const; void _get_property_list(List<PropertyInfo> *p_list) const;
bool _get(const StringName &p_property, Variant &r_value) const; bool _get(const StringName &p_property, Variant &r_value) const;
bool _set(const StringName &p_property, const Variant &p_value); bool _set(const StringName &p_property, const Variant &p_value);
SpineSprite *get_spine_sprite() const; SpineSprite *get_spine_sprite() const;
void _update_polygon_from_spine_sprite(SpineSprite *sprite); void _update_polygon_from_spine_sprite(SpineSprite *sprite);
void _clear_polygon(); void _clear_polygon();
void _sync_transform(SpineSprite *sprite); void _sync_transform(SpineSprite *sprite);
void _get_slot_list(Vector<String> &res) const;
void _get_slot_list(Vector<String> &res) const;
public: public:
SpineCollisionShapeProxy(); SpineCollisionShapeProxy();
~SpineCollisionShapeProxy(); ~SpineCollisionShapeProxy();
NodePath get_spine_sprite_path(); NodePath get_spine_sprite_path();
void set_spine_sprite_path(NodePath v); void set_spine_sprite_path(NodePath v);
String get_slot() const; String get_slot() const;
void set_slot(const String &v); void set_slot(const String &v);
bool get_sync_transform(); bool get_sync_transform();
void set_sync_transform(bool v); void set_sync_transform(bool v);
}; };
#endif //GODOT_SPINECOLLISIONSHAPEPROXY_H #endif//GODOT_SPINECOLLISIONSHAPEPROXY_H

View File

@ -30,33 +30,31 @@
#include "SpineConstant.h" #include "SpineConstant.h"
void SpineConstant::_bind_methods() { void SpineConstant::_bind_methods() {
BIND_ENUM_CONSTANT(MixBlend_Setup); BIND_ENUM_CONSTANT(MixBlend_Setup);
BIND_ENUM_CONSTANT(MixBlend_First); BIND_ENUM_CONSTANT(MixBlend_First);
BIND_ENUM_CONSTANT(MixBlend_Replace); BIND_ENUM_CONSTANT(MixBlend_Replace);
BIND_ENUM_CONSTANT(MixBlend_Add); BIND_ENUM_CONSTANT(MixBlend_Add);
BIND_ENUM_CONSTANT(MixDirection_In);
BIND_ENUM_CONSTANT(MixDirection_Out);
BIND_ENUM_CONSTANT(Property_Rotate);
BIND_ENUM_CONSTANT(Property_X);
BIND_ENUM_CONSTANT(Property_Y);
BIND_ENUM_CONSTANT(Property_ScaleX);
BIND_ENUM_CONSTANT( Property_ScaleY);
BIND_ENUM_CONSTANT(Property_ShearX);
BIND_ENUM_CONSTANT(Property_ShearY);
BIND_ENUM_CONSTANT(Property_Rgb);
BIND_ENUM_CONSTANT(Property_Alpha);
BIND_ENUM_CONSTANT(Property_Rgb2);
BIND_ENUM_CONSTANT(Property_Attachment);
BIND_ENUM_CONSTANT(Property_Deform);
BIND_ENUM_CONSTANT(Property_Event);
BIND_ENUM_CONSTANT(Property_DrawOrder);
BIND_ENUM_CONSTANT(Property_IkConstraint);
BIND_ENUM_CONSTANT(Property_TransformConstraint);
BIND_ENUM_CONSTANT(Property_PathConstraintPosition);
BIND_ENUM_CONSTANT(Property_PathConstraintSpacing);
BIND_ENUM_CONSTANT(Property_PathConstraintMix);
BIND_ENUM_CONSTANT(MixDirection_In);
BIND_ENUM_CONSTANT(MixDirection_Out);
BIND_ENUM_CONSTANT(Property_Rotate);
BIND_ENUM_CONSTANT(Property_X);
BIND_ENUM_CONSTANT(Property_Y);
BIND_ENUM_CONSTANT(Property_ScaleX);
BIND_ENUM_CONSTANT(Property_ScaleY);
BIND_ENUM_CONSTANT(Property_ShearX);
BIND_ENUM_CONSTANT(Property_ShearY);
BIND_ENUM_CONSTANT(Property_Rgb);
BIND_ENUM_CONSTANT(Property_Alpha);
BIND_ENUM_CONSTANT(Property_Rgb2);
BIND_ENUM_CONSTANT(Property_Attachment);
BIND_ENUM_CONSTANT(Property_Deform);
BIND_ENUM_CONSTANT(Property_Event);
BIND_ENUM_CONSTANT(Property_DrawOrder);
BIND_ENUM_CONSTANT(Property_IkConstraint);
BIND_ENUM_CONSTANT(Property_TransformConstraint);
BIND_ENUM_CONSTANT(Property_PathConstraintPosition);
BIND_ENUM_CONSTANT(Property_PathConstraintSpacing);
BIND_ENUM_CONSTANT(Property_PathConstraintMix);
} }

View File

@ -32,49 +32,50 @@
#include "core/variant_parser.h" #include "core/variant_parser.h"
class SpineConstant : public Object{ class SpineConstant : public Object {
GDCLASS(SpineConstant, Object); GDCLASS(SpineConstant, Object);
protected: protected:
static void _bind_methods(); static void _bind_methods();
public: public:
enum MixBlend { enum MixBlend {
MixBlend_Setup = 0, MixBlend_Setup = 0,
MixBlend_First, MixBlend_First,
MixBlend_Replace, MixBlend_Replace,
MixBlend_Add MixBlend_Add
}; };
enum MixDirection { enum MixDirection {
MixDirection_In = 0, MixDirection_In = 0,
MixDirection_Out MixDirection_Out
}; };
enum PropertyId { enum PropertyId {
Property_Rotate = 1 << 0, Property_Rotate = 1 << 0,
Property_X = 1 << 1, Property_X = 1 << 1,
Property_Y = 1 << 2, Property_Y = 1 << 2,
Property_ScaleX = 1 << 3, Property_ScaleX = 1 << 3,
Property_ScaleY = 1 << 4, Property_ScaleY = 1 << 4,
Property_ShearX = 1 << 5, Property_ShearX = 1 << 5,
Property_ShearY = 1 << 6, Property_ShearY = 1 << 6,
Property_Rgb = 1 << 7, Property_Rgb = 1 << 7,
Property_Alpha = 1 << 8, Property_Alpha = 1 << 8,
Property_Rgb2 = 1 << 9, Property_Rgb2 = 1 << 9,
Property_Attachment = 1 << 10, Property_Attachment = 1 << 10,
Property_Deform = 1 << 11, Property_Deform = 1 << 11,
Property_Event = 1 << 12, Property_Event = 1 << 12,
Property_DrawOrder = 1 << 13, Property_DrawOrder = 1 << 13,
Property_IkConstraint = 1 << 14, Property_IkConstraint = 1 << 14,
Property_TransformConstraint = 1 << 15, Property_TransformConstraint = 1 << 15,
Property_PathConstraintPosition = 1 << 16, Property_PathConstraintPosition = 1 << 16,
Property_PathConstraintSpacing = 1 << 17, Property_PathConstraintSpacing = 1 << 17,
Property_PathConstraintMix = 1 << 18 Property_PathConstraintMix = 1 << 18
}; };
}; };
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);
#endif //GODOT_SPINECONSTANT_H #endif//GODOT_SPINECONSTANT_H

View File

@ -37,23 +37,23 @@ void SpineConstraintData::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_skin_required", "v"), &SpineConstraintData::set_skin_required); ClassDB::bind_method(D_METHOD("set_skin_required", "v"), &SpineConstraintData::set_skin_required);
} }
SpineConstraintData::SpineConstraintData():constraint_data(NULL) {} SpineConstraintData::SpineConstraintData() : constraint_data(NULL) {}
SpineConstraintData::~SpineConstraintData() {} SpineConstraintData::~SpineConstraintData() {}
String SpineConstraintData::get_constraint_data_name(){ String SpineConstraintData::get_constraint_data_name() {
return constraint_data->getName().buffer(); return constraint_data->getName().buffer();
} }
uint64_t SpineConstraintData::get_order(){ uint64_t SpineConstraintData::get_order() {
return constraint_data->getOrder(); return constraint_data->getOrder();
} }
void SpineConstraintData::set_order(uint64_t v){ void SpineConstraintData::set_order(uint64_t v) {
constraint_data->setOrder(v); constraint_data->setOrder(v);
} }
bool SpineConstraintData::is_skin_required(){ bool SpineConstraintData::is_skin_required() {
return constraint_data->isSkinRequired(); return constraint_data->isSkinRequired();
} }
void SpineConstraintData::set_skin_required(bool v){ void SpineConstraintData::set_skin_required(bool v) {
constraint_data->setSkinRequired(v); constraint_data->setSkinRequired(v);
} }

View File

@ -47,10 +47,10 @@ public:
SpineConstraintData(); SpineConstraintData();
~SpineConstraintData(); ~SpineConstraintData();
inline void set_spine_object(spine::ConstraintData *c){ inline void set_spine_object(spine::ConstraintData *c) {
constraint_data = c; constraint_data = c;
} }
virtual inline spine::ConstraintData *get_spine_object(){ virtual inline spine::ConstraintData *get_spine_object() {
return constraint_data; return constraint_data;
} }
@ -63,4 +63,4 @@ public:
void set_skin_required(bool v); void set_skin_required(bool v);
}; };
#endif //GODOT_SPINECONSTRAINTDATA_H #endif//GODOT_SPINECONSTRAINTDATA_H

View File

@ -43,19 +43,19 @@ void SpineEvent::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_volume", "v"), &SpineEvent::set_volume); ClassDB::bind_method(D_METHOD("set_volume", "v"), &SpineEvent::set_volume);
ClassDB::bind_method(D_METHOD("get_balance"), &SpineEvent::get_balance); ClassDB::bind_method(D_METHOD("get_balance"), &SpineEvent::get_balance);
ClassDB::bind_method(D_METHOD("set_balance", "v"), &SpineEvent::set_balance); ClassDB::bind_method(D_METHOD("set_balance", "v"), &SpineEvent::set_balance);
// //
// BIND_ENUM_CONSTANT(EVENTTYPE_START); // BIND_ENUM_CONSTANT(EVENTTYPE_START);
// BIND_ENUM_CONSTANT(EVENTTYPE_INTERRUPT); // BIND_ENUM_CONSTANT(EVENTTYPE_INTERRUPT);
// BIND_ENUM_CONSTANT(EVENTTYPE_END); // BIND_ENUM_CONSTANT(EVENTTYPE_END);
// BIND_ENUM_CONSTANT(EVENTTYPE_COMPLETE); // BIND_ENUM_CONSTANT(EVENTTYPE_COMPLETE);
// BIND_ENUM_CONSTANT(EVENTTYPE_DISPOSE); // BIND_ENUM_CONSTANT(EVENTTYPE_DISPOSE);
// BIND_ENUM_CONSTANT(EVENTTYPE_EVENT); // BIND_ENUM_CONSTANT(EVENTTYPE_EVENT);
} }
SpineEvent::SpineEvent():event(NULL) {} SpineEvent::SpineEvent() : event(NULL) {}
SpineEvent::~SpineEvent(){} SpineEvent::~SpineEvent() {}
Ref<SpineEventData> SpineEvent::get_data(){ Ref<SpineEventData> SpineEvent::get_data() {
Ref<SpineEventData> event_data(memnew(SpineEventData)); Ref<SpineEventData> event_data(memnew(SpineEventData));
event_data->set_spine_object(&(event->getData())); event_data->set_spine_object(&(event->getData()));
return event_data; return event_data;
@ -65,46 +65,46 @@ String SpineEvent::get_event_name() {
return event->getData().getName().buffer(); return event->getData().getName().buffer();
} }
float SpineEvent::get_time(){ float SpineEvent::get_time() {
return event->getTime(); return event->getTime();
} }
int SpineEvent::get_int_value(){ int SpineEvent::get_int_value() {
return event->getIntValue(); return event->getIntValue();
} }
void SpineEvent::set_int_value(int v){ void SpineEvent::set_int_value(int v) {
event->setIntValue(v); event->setIntValue(v);
} }
float SpineEvent::get_float_value(){ float SpineEvent::get_float_value() {
return event->getFloatValue(); return event->getFloatValue();
} }
void SpineEvent::set_float_value(float v){ void SpineEvent::set_float_value(float v) {
event->setFloatValue(v); event->setFloatValue(v);
} }
String SpineEvent::get_string_value(){ String SpineEvent::get_string_value() {
return event->getStringValue().buffer(); return event->getStringValue().buffer();
} }
void SpineEvent::set_string_value(const String &v){ void SpineEvent::set_string_value(const String &v) {
event->setStringValue(spine::String(v.utf8())); event->setStringValue(spine::String(v.utf8()));
} }
float SpineEvent::get_volume(){ float SpineEvent::get_volume() {
return event->getVolume(); return event->getVolume();
} }
void SpineEvent::set_volume(float v){ void SpineEvent::set_volume(float v) {
event->setVolume(v); event->setVolume(v);
} }
float SpineEvent::get_balance(){ float SpineEvent::get_balance() {
return event->getBalance(); return event->getBalance();
} }
void SpineEvent::set_balance(float v){ void SpineEvent::set_balance(float v) {
event->setBalance(v); event->setBalance(v);
} }

View File

@ -36,25 +36,27 @@
#include "SpineEventData.h" #include "SpineEventData.h"
class SpineEvent : public Reference{ class SpineEvent : public Reference {
GDCLASS(SpineEvent, Reference); GDCLASS(SpineEvent, Reference);
protected: protected:
static void _bind_methods(); static void _bind_methods();
private: private:
spine::Event *event; spine::Event *event;
public: public:
SpineEvent(); SpineEvent();
~SpineEvent(); ~SpineEvent();
inline void set_spine_object(spine::Event *e){ inline void set_spine_object(spine::Event *e) {
event = e; event = e;
} }
inline spine::Event *get_spine_object() const{ inline spine::Event *get_spine_object() const {
return event; return event;
} }
enum EventType{ enum EventType {
EVENTTYPE_START = spine::EventType_Start, EVENTTYPE_START = spine::EventType_Start,
EVENTTYPE_INTERRUPT = spine::EventType_Interrupt, EVENTTYPE_INTERRUPT = spine::EventType_Interrupt,
EVENTTYPE_END = spine::EventType_End, EVENTTYPE_END = spine::EventType_End,
@ -86,4 +88,4 @@ public:
void set_balance(float inValue); void set_balance(float inValue);
}; };
#endif //GODOT_SPINEEVENT_H #endif//GODOT_SPINEEVENT_H

View File

@ -30,8 +30,7 @@
#include "SpineEventData.h" #include "SpineEventData.h"
void SpineEventData::_bind_methods() { void SpineEventData::_bind_methods() {
} }
SpineEventData::SpineEventData():event_data(NULL) {} SpineEventData::SpineEventData() : event_data(NULL) {}
SpineEventData::~SpineEventData(){} SpineEventData::~SpineEventData() {}

View File

@ -34,23 +34,25 @@
#include <spine/spine.h> #include <spine/spine.h>
class SpineEventData : public Reference{ class SpineEventData : public Reference {
GDCLASS(SpineEventData, Reference); GDCLASS(SpineEventData, Reference);
protected: protected:
static void _bind_methods(); static void _bind_methods();
private: private:
const spine::EventData *event_data; const spine::EventData *event_data;
public: public:
SpineEventData(); SpineEventData();
~SpineEventData(); ~SpineEventData();
inline void set_spine_object(const spine::EventData *e){ inline void set_spine_object(const spine::EventData *e) {
event_data = e; event_data = e;
} }
inline const spine::EventData *get_spine_object(){ inline const spine::EventData *get_spine_object() {
return event_data; return event_data;
} }
}; };
#endif //GODOT_SPINEEVENTDATA_H #endif//GODOT_SPINEEVENTDATA_H

View File

@ -52,35 +52,35 @@ void SpineIkConstraint::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_active", "v"), &SpineIkConstraint::set_active); ClassDB::bind_method(D_METHOD("set_active", "v"), &SpineIkConstraint::set_active);
} }
SpineIkConstraint::SpineIkConstraint():ik_constraint(NULL) {} SpineIkConstraint::SpineIkConstraint() : ik_constraint(NULL) {}
SpineIkConstraint::~SpineIkConstraint() {} SpineIkConstraint::~SpineIkConstraint() {}
// void SpineIkConstraint::apply(){ // void SpineIkConstraint::apply(){
// ik_constraint->apply(); // ik_constraint->apply();
// } // }
void SpineIkConstraint::update(){ void SpineIkConstraint::update() {
ik_constraint->update(); ik_constraint->update();
} }
int SpineIkConstraint::get_order(){ int SpineIkConstraint::get_order() {
return ik_constraint->getOrder(); return ik_constraint->getOrder();
} }
Ref<SpineIkConstraintData> SpineIkConstraint::get_data(){ Ref<SpineIkConstraintData> SpineIkConstraint::get_data() {
auto &ikc = ik_constraint->getData(); auto &ikc = ik_constraint->getData();
Ref<SpineIkConstraintData> gd_ikc(memnew(SpineIkConstraintData)); Ref<SpineIkConstraintData> gd_ikc(memnew(SpineIkConstraintData));
gd_ikc->set_spine_object(&ikc); gd_ikc->set_spine_object(&ikc);
return gd_ikc; return gd_ikc;
} }
Array SpineIkConstraint::get_bones(){ Array SpineIkConstraint::get_bones() {
auto &bs = ik_constraint->getBones(); auto &bs = ik_constraint->getBones();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i<bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
auto b = bs[i]; auto b = bs[i];
if(b == NULL) gd_bs[i] = Ref<SpineBone>(NULL); if (b == NULL) gd_bs[i] = Ref<SpineBone>(NULL);
Ref<SpineBone> gd_b(memnew(SpineBone)); Ref<SpineBone> gd_b(memnew(SpineBone));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
gd_bs[i] = gd_b; gd_bs[i] = gd_b;
@ -88,59 +88,59 @@ Array SpineIkConstraint::get_bones(){
return gd_bs; return gd_bs;
} }
Ref<SpineBone> SpineIkConstraint::get_target(){ Ref<SpineBone> SpineIkConstraint::get_target() {
auto b = ik_constraint->getTarget(); auto b = ik_constraint->getTarget();
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineBone> gd_b(memnew(SpineBone)); Ref<SpineBone> gd_b(memnew(SpineBone));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
return gd_b; return gd_b;
} }
void SpineIkConstraint::set_target(Ref<SpineBone> v){ void SpineIkConstraint::set_target(Ref<SpineBone> v) {
if(v.is_valid()){ if (v.is_valid()) {
ik_constraint->setTarget(v->get_spine_object()); ik_constraint->setTarget(v->get_spine_object());
} else{ } else {
ik_constraint->setTarget(NULL); ik_constraint->setTarget(NULL);
} }
} }
int SpineIkConstraint::get_bend_direction(){ int SpineIkConstraint::get_bend_direction() {
return ik_constraint->getBendDirection(); return ik_constraint->getBendDirection();
} }
void SpineIkConstraint::set_bend_direction(int v){ void SpineIkConstraint::set_bend_direction(int v) {
ik_constraint->setBendDirection(v); ik_constraint->setBendDirection(v);
} }
bool SpineIkConstraint::get_compress(){ bool SpineIkConstraint::get_compress() {
return ik_constraint->getCompress(); return ik_constraint->getCompress();
} }
void SpineIkConstraint::set_compress(bool v){ void SpineIkConstraint::set_compress(bool v) {
ik_constraint->setCompress(v); ik_constraint->setCompress(v);
} }
bool SpineIkConstraint::get_stretch(){ bool SpineIkConstraint::get_stretch() {
return ik_constraint->getStretch(); return ik_constraint->getStretch();
} }
void SpineIkConstraint::set_stretch(bool v){ void SpineIkConstraint::set_stretch(bool v) {
ik_constraint->setStretch(v); ik_constraint->setStretch(v);
} }
float SpineIkConstraint::get_mix(){ float SpineIkConstraint::get_mix() {
return ik_constraint->getMix(); return ik_constraint->getMix();
} }
void SpineIkConstraint::set_mix(float v){ void SpineIkConstraint::set_mix(float v) {
ik_constraint->setMix(v); ik_constraint->setMix(v);
} }
float SpineIkConstraint::get_softness(){ float SpineIkConstraint::get_softness() {
return ik_constraint->getSoftness(); return ik_constraint->getSoftness();
} }
void SpineIkConstraint::set_softness(float v){ void SpineIkConstraint::set_softness(float v) {
ik_constraint->setSoftness(v); ik_constraint->setSoftness(v);
} }
bool SpineIkConstraint::is_active(){ bool SpineIkConstraint::is_active() {
return ik_constraint->isActive(); return ik_constraint->isActive();
} }
void SpineIkConstraint::set_active(bool v){ void SpineIkConstraint::set_active(bool v) {
ik_constraint->setActive(v); ik_constraint->setActive(v);
} }

View File

@ -51,15 +51,15 @@ public:
SpineIkConstraint(); SpineIkConstraint();
~SpineIkConstraint(); ~SpineIkConstraint();
inline void set_spine_object(spine::IkConstraint * ic){ inline void set_spine_object(spine::IkConstraint *ic) {
ik_constraint = ic; ik_constraint = ic;
} }
inline spine::IkConstraint *get_spine_object(){ inline spine::IkConstraint *get_spine_object() {
return ik_constraint; return ik_constraint;
} }
// The spine-runtime-cpp 4.0 seems to not have a apply function implementation. // The spine-runtime-cpp 4.0 seems to not have a apply function implementation.
// void apply(); // void apply();
void update(); void update();
@ -89,7 +89,6 @@ public:
bool is_active(); bool is_active();
void set_active(bool v); void set_active(bool v);
}; };
#endif //GODOT_SPINEIKCONSTRAINT_H #endif//GODOT_SPINEIKCONSTRAINT_H

View File

@ -50,12 +50,12 @@ void SpineIkConstraintData::_bind_methods() {
SpineIkConstraintData::SpineIkConstraintData() {} SpineIkConstraintData::SpineIkConstraintData() {}
SpineIkConstraintData::~SpineIkConstraintData() {} SpineIkConstraintData::~SpineIkConstraintData() {}
Array SpineIkConstraintData::get_bones(){ Array SpineIkConstraintData::get_bones() {
auto bs = get_spine_data()->getBones(); auto bs = get_spine_data()->getBones();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
if(bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL); if (bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL);
else { else {
Ref<SpineBoneData> gd_b(memnew(SpineBoneData)); Ref<SpineBoneData> gd_b(memnew(SpineBoneData));
gd_b->set_spine_object(bs[i]); gd_b->set_spine_object(bs[i]);
@ -65,59 +65,59 @@ Array SpineIkConstraintData::get_bones(){
return gd_bs; return gd_bs;
} }
Ref<SpineBoneData> SpineIkConstraintData::get_target(){ Ref<SpineBoneData> SpineIkConstraintData::get_target() {
auto b = get_spine_data()->getTarget(); auto b = get_spine_data()->getTarget();
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineBoneData> gd_b(memnew(SpineBoneData)); Ref<SpineBoneData> gd_b(memnew(SpineBoneData));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
return gd_b; return gd_b;
} }
void SpineIkConstraintData::set_target(Ref<SpineBoneData> v){ void SpineIkConstraintData::set_target(Ref<SpineBoneData> v) {
if(v.is_valid()){ if (v.is_valid()) {
get_spine_data()->setTarget(v->get_spine_object()); get_spine_data()->setTarget(v->get_spine_object());
}else{ } else {
get_spine_data()->setTarget(NULL); get_spine_data()->setTarget(NULL);
} }
} }
int SpineIkConstraintData::get_bend_direction(){ int SpineIkConstraintData::get_bend_direction() {
return get_spine_data()->getBendDirection(); return get_spine_data()->getBendDirection();
} }
void SpineIkConstraintData::set_bend_direction(int v){ void SpineIkConstraintData::set_bend_direction(int v) {
get_spine_data()->setBendDirection(v); get_spine_data()->setBendDirection(v);
} }
bool SpineIkConstraintData::get_compress(){ bool SpineIkConstraintData::get_compress() {
return get_spine_data()->getCompress(); return get_spine_data()->getCompress();
} }
void SpineIkConstraintData::set_compress(bool v){ void SpineIkConstraintData::set_compress(bool v) {
get_spine_data()->setCompress(v); get_spine_data()->setCompress(v);
} }
bool SpineIkConstraintData::get_stretch(){ bool SpineIkConstraintData::get_stretch() {
return get_spine_data()->getStretch(); return get_spine_data()->getStretch();
} }
void SpineIkConstraintData::set_stretch(bool v){ void SpineIkConstraintData::set_stretch(bool v) {
get_spine_data()->setStretch(v); get_spine_data()->setStretch(v);
} }
bool SpineIkConstraintData::get_uniform(){ bool SpineIkConstraintData::get_uniform() {
return get_spine_data()->getUniform(); return get_spine_data()->getUniform();
} }
void SpineIkConstraintData::set_uniform(bool v){ void SpineIkConstraintData::set_uniform(bool v) {
get_spine_data()->setUniform(v); get_spine_data()->setUniform(v);
} }
float SpineIkConstraintData::get_mix(){ float SpineIkConstraintData::get_mix() {
return get_spine_data()->getMix(); return get_spine_data()->getMix();
} }
void SpineIkConstraintData::set_mix(float v){ void SpineIkConstraintData::set_mix(float v) {
get_spine_data()->setMix(v); get_spine_data()->setMix(v);
} }
float SpineIkConstraintData::get_softness(){ float SpineIkConstraintData::get_softness() {
return get_spine_data()->getSoftness(); return get_spine_data()->getSoftness();
} }
void SpineIkConstraintData::set_softness(float v){ void SpineIkConstraintData::set_softness(float v) {
get_spine_data()->setSoftness(v); get_spine_data()->setSoftness(v);
} }

View File

@ -47,8 +47,8 @@ public:
SpineIkConstraintData(); SpineIkConstraintData();
~SpineIkConstraintData(); ~SpineIkConstraintData();
virtual inline spine::IkConstraintData *get_spine_data(){ virtual inline spine::IkConstraintData *get_spine_data() {
return (spine::IkConstraintData*) SpineConstraintData::get_spine_object(); return (spine::IkConstraintData *) SpineConstraintData::get_spine_object();
} }
Array get_bones(); Array get_bones();
@ -73,7 +73,6 @@ public:
float get_softness(); float get_softness();
void set_softness(float v); void set_softness(float v);
}; };
#endif //GODOT_SPINEIKCONSTRAINTDATA_H #endif//GODOT_SPINEIKCONSTRAINTDATA_H

View File

@ -29,7 +29,7 @@
#include "SpinePathConstraint.h" #include "SpinePathConstraint.h"
void SpinePathConstraint::_bind_methods(){ void SpinePathConstraint::_bind_methods() {
// ClassDB::bind_method(D_METHOD("apply"), &SpinePathConstraint::apply); // 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);
@ -51,63 +51,63 @@ 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(NULL) {}
SpinePathConstraint::~SpinePathConstraint() {} SpinePathConstraint::~SpinePathConstraint() {}
// void SpinePathConstraint::apply(){ // void SpinePathConstraint::apply(){
// path_constraint->apply(); // path_constraint->apply();
// } // }
void SpinePathConstraint::update(){ void SpinePathConstraint::update() {
path_constraint->update(); path_constraint->update();
} }
int SpinePathConstraint::get_order(){ int SpinePathConstraint::get_order() {
return path_constraint->getOrder(); return path_constraint->getOrder();
} }
float SpinePathConstraint::get_position(){ float SpinePathConstraint::get_position() {
return path_constraint->getPosition(); return path_constraint->getPosition();
} }
void SpinePathConstraint::set_position(float v){ void SpinePathConstraint::set_position(float v) {
path_constraint->setPosition(v); path_constraint->setPosition(v);
} }
float SpinePathConstraint::get_spacing(){ float SpinePathConstraint::get_spacing() {
return path_constraint->getSpacing(); return path_constraint->getSpacing();
} }
void SpinePathConstraint::set_spacing(float v){ void SpinePathConstraint::set_spacing(float v) {
path_constraint->setSpacing(v); path_constraint->setSpacing(v);
} }
float SpinePathConstraint::get_mix_rotate(){ float SpinePathConstraint::get_mix_rotate() {
return path_constraint->getMixRotate(); return path_constraint->getMixRotate();
} }
void SpinePathConstraint::set_mix_rotate(float v){ void SpinePathConstraint::set_mix_rotate(float v) {
path_constraint->setMixRotate(v); path_constraint->setMixRotate(v);
} }
float SpinePathConstraint::get_mix_x(){ float SpinePathConstraint::get_mix_x() {
return path_constraint->getMixX(); return path_constraint->getMixX();
} }
void SpinePathConstraint::set_mix_x(float v){ void SpinePathConstraint::set_mix_x(float v) {
path_constraint->setMixX(v); path_constraint->setMixX(v);
} }
float SpinePathConstraint::get_mix_y(){ float SpinePathConstraint::get_mix_y() {
return path_constraint->getMixY(); return path_constraint->getMixY();
} }
void SpinePathConstraint::set_mix_y(float v){ void SpinePathConstraint::set_mix_y(float v) {
path_constraint->setMixY(v); path_constraint->setMixY(v);
} }
Array SpinePathConstraint::get_bones(){ Array SpinePathConstraint::get_bones() {
auto &bs = path_constraint->getBones(); auto &bs = path_constraint->getBones();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i<bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
auto b = bs[i]; auto b = bs[i];
if(b == NULL) gd_bs[i] = Ref<SpineBone>(NULL); if (b == NULL) gd_bs[i] = Ref<SpineBone>(NULL);
Ref<SpineBone> gd_b(memnew(SpineBone)); Ref<SpineBone> gd_b(memnew(SpineBone));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
gd_bs[i] = gd_b; gd_bs[i] = gd_b;
@ -115,31 +115,31 @@ Array SpinePathConstraint::get_bones(){
return gd_bs; return gd_bs;
} }
Ref<SpineSlot> SpinePathConstraint::get_target(){ Ref<SpineSlot> SpinePathConstraint::get_target() {
auto s = path_constraint->getTarget(); auto s = path_constraint->getTarget();
if(s == NULL) return NULL; if (s == NULL) return NULL;
Ref<SpineSlot> gd_s(memnew(SpineSlot)); Ref<SpineSlot> gd_s(memnew(SpineSlot));
gd_s->set_spine_object(s); gd_s->set_spine_object(s);
return gd_s; return gd_s;
} }
void SpinePathConstraint::set_target(Ref<SpineSlot> v){ void SpinePathConstraint::set_target(Ref<SpineSlot> v) {
if(v.is_valid()){ if (v.is_valid()) {
path_constraint->setTarget(v->get_spine_object()); path_constraint->setTarget(v->get_spine_object());
}else{ } else {
path_constraint->setTarget(NULL); path_constraint->setTarget(NULL);
} }
} }
Ref<SpinePathConstraintData> SpinePathConstraint::get_data(){ Ref<SpinePathConstraintData> SpinePathConstraint::get_data() {
auto &sd = path_constraint->getData(); auto &sd = path_constraint->getData();
Ref<SpinePathConstraintData> gd_sd(memnew(SpinePathConstraintData)); Ref<SpinePathConstraintData> gd_sd(memnew(SpinePathConstraintData));
gd_sd->set_spine_object(&sd); gd_sd->set_spine_object(&sd);
return gd_sd; return gd_sd;
} }
bool SpinePathConstraint::is_active(){ bool SpinePathConstraint::is_active() {
return path_constraint->isActive(); return path_constraint->isActive();
} }
void SpinePathConstraint::set_active(bool v){ void SpinePathConstraint::set_active(bool v) {
path_constraint->setActive(v); path_constraint->setActive(v);
} }

View File

@ -38,7 +38,7 @@
#include "SpineSlot.h" #include "SpineSlot.h"
#include "SpinePathConstraintData.h" #include "SpinePathConstraintData.h"
class SpinePathConstraint : public Reference{ class SpinePathConstraint : public Reference {
GDCLASS(SpinePathConstraint, Reference); GDCLASS(SpinePathConstraint, Reference);
protected: protected:
@ -51,15 +51,15 @@ public:
SpinePathConstraint(); SpinePathConstraint();
~SpinePathConstraint(); ~SpinePathConstraint();
inline void set_spine_object(spine::PathConstraint *pc){ inline void set_spine_object(spine::PathConstraint *pc) {
path_constraint = pc; path_constraint = pc;
} }
inline spine::PathConstraint *get_spine_object(){ inline spine::PathConstraint *get_spine_object() {
return path_constraint; return path_constraint;
} }
// The spine-runtime-cpp 4.0 seems to not have a apply function implementation. // The spine-runtime-cpp 4.0 seems to not have a apply function implementation.
// void apply(); // void apply();
void update(); void update();
@ -91,4 +91,4 @@ public:
void set_active(bool v); void set_active(bool v);
}; };
#endif //GODOT_SPINEPATHCONSTRAINT_H #endif//GODOT_SPINEPATHCONSTRAINT_H

View File

@ -68,12 +68,12 @@ void SpinePathConstraintData::_bind_methods() {
SpinePathConstraintData::SpinePathConstraintData() {} SpinePathConstraintData::SpinePathConstraintData() {}
SpinePathConstraintData::~SpinePathConstraintData() {} SpinePathConstraintData::~SpinePathConstraintData() {}
Array SpinePathConstraintData::get_bones(){ Array SpinePathConstraintData::get_bones() {
auto bs = get_spine_data()->getBones(); auto bs = get_spine_data()->getBones();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
if(bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL); if (bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL);
else { else {
Ref<SpineBoneData> gd_b(memnew(SpineBoneData)); Ref<SpineBoneData> gd_b(memnew(SpineBoneData));
gd_b->set_spine_object(bs[i]); gd_b->set_spine_object(bs[i]);
@ -83,86 +83,86 @@ Array SpinePathConstraintData::get_bones(){
return gd_bs; return gd_bs;
} }
Ref<SpineSlotData> SpinePathConstraintData::get_target(){ Ref<SpineSlotData> SpinePathConstraintData::get_target() {
auto s = get_spine_data()->getTarget(); auto s = get_spine_data()->getTarget();
if(s == NULL) return NULL; if (s == NULL) return NULL;
Ref<SpineSlotData> gd_s(memnew(SpineSlotData)); Ref<SpineSlotData> gd_s(memnew(SpineSlotData));
gd_s->set_spine_object(s); gd_s->set_spine_object(s);
return gd_s; return gd_s;
} }
void SpinePathConstraintData::set_target(Ref<SpineSlotData> v){ void SpinePathConstraintData::set_target(Ref<SpineSlotData> v) {
if(v.is_valid()){ if (v.is_valid()) {
get_spine_data()->setTarget(v->get_spine_object()); get_spine_data()->setTarget(v->get_spine_object());
}else{ } else {
get_spine_data()->setTarget(NULL); get_spine_data()->setTarget(NULL);
} }
} }
SpinePathConstraintData::PositionMode SpinePathConstraintData::get_position_mode(){ SpinePathConstraintData::PositionMode SpinePathConstraintData::get_position_mode() {
auto m = (int) get_spine_data()->getPositionMode(); auto m = (int) get_spine_data()->getPositionMode();
return (PositionMode) m; return (PositionMode) m;
} }
void SpinePathConstraintData::set_position_mode(PositionMode v){ void SpinePathConstraintData::set_position_mode(PositionMode v) {
auto m = (int) v; auto m = (int) v;
get_spine_data()->setPositionMode((spine::PositionMode)m); get_spine_data()->setPositionMode((spine::PositionMode) m);
} }
SpinePathConstraintData::SpacingMode SpinePathConstraintData::get_spacing_mode(){ SpinePathConstraintData::SpacingMode SpinePathConstraintData::get_spacing_mode() {
auto m = (int) get_spine_data()->getSpacingMode(); auto m = (int) get_spine_data()->getSpacingMode();
return (SpacingMode) m; return (SpacingMode) m;
} }
void SpinePathConstraintData::set_spacing_mode(SpacingMode v){ void SpinePathConstraintData::set_spacing_mode(SpacingMode v) {
auto m = (int) v; auto m = (int) v;
get_spine_data()->setSpacingMode((spine::SpacingMode)m); get_spine_data()->setSpacingMode((spine::SpacingMode) m);
} }
SpinePathConstraintData::RotateMode SpinePathConstraintData::get_rotate_mode(){ SpinePathConstraintData::RotateMode SpinePathConstraintData::get_rotate_mode() {
auto m = (int) get_spine_data()->getRotateMode(); auto m = (int) get_spine_data()->getRotateMode();
return (RotateMode) m; return (RotateMode) m;
} }
void SpinePathConstraintData::set_rotate_mode(RotateMode v){ void SpinePathConstraintData::set_rotate_mode(RotateMode v) {
auto m = (int) v; auto m = (int) v;
get_spine_data()->setRotateMode((spine::RotateMode)m); get_spine_data()->setRotateMode((spine::RotateMode) m);
} }
float SpinePathConstraintData::get_offset_rotation(){ float SpinePathConstraintData::get_offset_rotation() {
return get_spine_data()->getOffsetRotation(); return get_spine_data()->getOffsetRotation();
} }
void SpinePathConstraintData::set_offset_rotation(float v){ void SpinePathConstraintData::set_offset_rotation(float v) {
get_spine_data()->setOffsetRotation(v); get_spine_data()->setOffsetRotation(v);
} }
float SpinePathConstraintData::get_position(){ float SpinePathConstraintData::get_position() {
return get_spine_data()->getPosition(); return get_spine_data()->getPosition();
} }
void SpinePathConstraintData::set_position(float v){ void SpinePathConstraintData::set_position(float v) {
get_spine_data()->setPosition(v); get_spine_data()->setPosition(v);
} }
float SpinePathConstraintData::get_spacing(){ float SpinePathConstraintData::get_spacing() {
return get_spine_data()->getSpacing(); return get_spine_data()->getSpacing();
} }
void SpinePathConstraintData::set_spacing(float v){ void SpinePathConstraintData::set_spacing(float v) {
get_spine_data()->setSpacing(v); get_spine_data()->setSpacing(v);
} }
float SpinePathConstraintData::get_mix_rotate(){ float SpinePathConstraintData::get_mix_rotate() {
return get_spine_data()->getMixRotate(); return get_spine_data()->getMixRotate();
} }
void SpinePathConstraintData::set_mix_rotate(float v){ void SpinePathConstraintData::set_mix_rotate(float v) {
get_spine_data()->setMixRotate(v); get_spine_data()->setMixRotate(v);
} }
float SpinePathConstraintData::get_mix_x(){ float SpinePathConstraintData::get_mix_x() {
return get_spine_data()->getMixX(); return get_spine_data()->getMixX();
} }
void SpinePathConstraintData::set_mix_x(float v){ void SpinePathConstraintData::set_mix_x(float v) {
get_spine_data()->setMixX(v); get_spine_data()->setMixX(v);
} }
float SpinePathConstraintData::get_mix_y(){ float SpinePathConstraintData::get_mix_y() {
return get_spine_data()->getMixY(); return get_spine_data()->getMixY();
} }
void SpinePathConstraintData::set_mix_y(float v){ void SpinePathConstraintData::set_mix_y(float v) {
get_spine_data()->setMixY(v); get_spine_data()->setMixY(v);
} }

View File

@ -48,8 +48,8 @@ public:
SpinePathConstraintData(); SpinePathConstraintData();
~SpinePathConstraintData(); ~SpinePathConstraintData();
virtual inline spine::PathConstraintData *get_spine_data(){ virtual inline spine::PathConstraintData *get_spine_data() {
return (spine::PathConstraintData*) SpineConstraintData::get_spine_object(); return (spine::PathConstraintData *) SpineConstraintData::get_spine_object();
} }
enum PositionMode { enum PositionMode {
@ -105,4 +105,4 @@ public:
VARIANT_ENUM_CAST(SpinePathConstraintData::PositionMode); VARIANT_ENUM_CAST(SpinePathConstraintData::PositionMode);
VARIANT_ENUM_CAST(SpinePathConstraintData::SpacingMode); VARIANT_ENUM_CAST(SpinePathConstraintData::SpacingMode);
VARIANT_ENUM_CAST(SpinePathConstraintData::RotateMode); VARIANT_ENUM_CAST(SpinePathConstraintData::RotateMode);
#endif //GODOT_SPINEPATHCONSTRAINTDATA_H #endif//GODOT_SPINEPATHCONSTRAINTDATA_H

View File

@ -34,9 +34,9 @@
struct SpineRendererObject { struct SpineRendererObject {
Ref<Texture> tex; Ref<Texture> tex;
Ref<Texture> normal_tex; Ref<Texture> normal_tex;
}; };
#endif #endif

View File

@ -36,64 +36,63 @@
#include "SpineSprite.h" #include "SpineSprite.h"
Error SpineAtlasResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata){ Error SpineAtlasResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
Ref<SpineAtlasResource> res(memnew(SpineAtlasResource)); Ref<SpineAtlasResource> res(memnew(SpineAtlasResource));
res->set_normal_texture_prefix(p_options["normal_texture_prefix"]); res->set_normal_texture_prefix(p_options["normal_texture_prefix"]);
res->load_from_atlas_file(p_source_file); res->load_from_atlas_file(p_source_file);
String file_name = vformat("%s.%s", p_save_path, get_save_extension()); String file_name = vformat("%s.%s", p_save_path, get_save_extension());
auto err = ResourceSaver::save(file_name, res); auto err = ResourceSaver::save(file_name, res);
return err; return err;
} }
void SpineAtlasResourceImportPlugin::get_import_options(List<ImportOption> *r_options, int p_preset) const { void SpineAtlasResourceImportPlugin::get_import_options(List<ImportOption> *r_options, int p_preset) const {
if (p_preset == 0) { if (p_preset == 0) {
ImportOption op; ImportOption op;
op.option.name = "normal_texture_prefix"; op.option.name = "normal_texture_prefix";
op.option.type = Variant::STRING; op.option.type = Variant::STRING;
op.option.hint_string = "String"; op.option.hint_string = "String";
op.default_value = String("n"); op.default_value = String("n");
r_options->push_back(op); r_options->push_back(op);
} }
} }
Error SpineJsonResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata){ Error SpineJsonResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) {
Ref<SpineSkeletonJsonDataResource> res(memnew(SpineSkeletonJsonDataResource)); Ref<SpineSkeletonJsonDataResource> res(memnew(SpineSkeletonJsonDataResource));
res->load_from_file(p_source_file); res->load_from_file(p_source_file);
String file_name = vformat("%s.%s", p_save_path, get_save_extension()); String file_name = vformat("%s.%s", p_save_path, get_save_extension());
auto err = ResourceSaver::save(file_name, res); auto err = ResourceSaver::save(file_name, res);
return err; return err;
} }
//=======================| SpineRuntimeEditorPlugin |============================ //=======================| SpineRuntimeEditorPlugin |============================
SpineRuntimeEditorPlugin::SpineRuntimeEditorPlugin(EditorNode *p_node) { SpineRuntimeEditorPlugin::SpineRuntimeEditorPlugin(EditorNode *p_node) {
add_import_plugin(memnew(SpineAtlasResourceImportPlugin)); add_import_plugin(memnew(SpineAtlasResourceImportPlugin));
add_import_plugin(memnew(SpineJsonResourceImportPlugin)); add_import_plugin(memnew(SpineJsonResourceImportPlugin));
auto animate_button = memnew(ToolButton); auto animate_button = memnew(ToolButton);
animate_button->set_text("Animate"); animate_button->set_text("Animate");
add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU, animate_button); add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU, animate_button);
animate_dialog = memnew(SpineSpriteAnimateDialog); animate_dialog = memnew(SpineSpriteAnimateDialog);
get_editor_interface()->get_base_control()->add_child(animate_dialog); get_editor_interface()->get_base_control()->add_child(animate_dialog);
animate_dialog->set_animate_button(animate_button); animate_dialog->set_animate_button(animate_button);
animate_dialog->set_plugin(this); animate_dialog->set_plugin(this);
} }
SpineRuntimeEditorPlugin::~SpineRuntimeEditorPlugin() { SpineRuntimeEditorPlugin::~SpineRuntimeEditorPlugin() {
} }
bool SpineRuntimeEditorPlugin::handles(Object *p_object) const { bool SpineRuntimeEditorPlugin::handles(Object *p_object) const {
return p_object->is_class("SpineSprite"); return p_object->is_class("SpineSprite");
} }
void SpineRuntimeEditorPlugin::make_visible(bool p_visible) { void SpineRuntimeEditorPlugin::make_visible(bool p_visible) {
if (get_editor_interface()->get_selection()->get_selected_node_list().size() != 1) { if (get_editor_interface()->get_selection()->get_selected_node_list().size() != 1) {
p_visible = false; p_visible = false;
} }
animate_dialog->get_animate_button()->set_visible(p_visible); animate_dialog->get_animate_button()->set_visible(p_visible);
} }

View File

@ -34,35 +34,43 @@
#include "editor/editor_node.h" #include "editor/editor_node.h"
class SpineAtlasResourceImportPlugin : public EditorImportPlugin { class SpineAtlasResourceImportPlugin : public EditorImportPlugin {
GDCLASS(SpineAtlasResourceImportPlugin, EditorImportPlugin); GDCLASS(SpineAtlasResourceImportPlugin, EditorImportPlugin);
public: public:
String get_importer_name() const override {return "spine.atlas";} String get_importer_name() const override { return "spine.atlas"; }
String get_visible_name() const override {return "Spine Runtime Atlas";} String get_visible_name() const override { return "Spine Runtime Atlas"; }
void get_recognized_extensions(List<String> *p_extensions) const override {p_extensions->push_back("atlas");} void get_recognized_extensions(List<String> *p_extensions) const override { p_extensions->push_back("atlas"); }
String get_preset_name(int p_idx) const override {if (p_idx == 0) return "Default"; else return "Unknown";} String get_preset_name(int p_idx) const override {
int get_preset_count() const override {return 1;} if (p_idx == 0) return "Default";
String get_save_extension() const override {return "spatlas";} else
String get_resource_type() const override {return "SpineAtlasResource";} return "Unknown";
void get_import_options(List<ImportOption> *r_options, int p_preset) const override; }
bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override {return true;} int get_preset_count() const override { return 1; }
Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) override; String get_save_extension() const override { return "spatlas"; }
String get_resource_type() const override { return "SpineAtlasResource"; }
void get_import_options(List<ImportOption> *r_options, int p_preset) const override;
bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override { return true; }
Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) override;
}; };
class SpineJsonResourceImportPlugin : public EditorImportPlugin { class SpineJsonResourceImportPlugin : public EditorImportPlugin {
GDCLASS(SpineJsonResourceImportPlugin, EditorImportPlugin); GDCLASS(SpineJsonResourceImportPlugin, EditorImportPlugin);
public: public:
String get_importer_name() const override {return "spine.json";} String get_importer_name() const override { return "spine.json"; }
String get_visible_name() const override {return "Spine Runtime Json";} String get_visible_name() const override { return "Spine Runtime Json"; }
void get_recognized_extensions(List<String> *p_extensions) const override {p_extensions->push_back("json");} void get_recognized_extensions(List<String> *p_extensions) const override { p_extensions->push_back("json"); }
String get_preset_name(int p_idx) const override {if (p_idx == 0) return "Default"; else return "Unknown";} String get_preset_name(int p_idx) const override {
int get_preset_count() const override {return 1;} if (p_idx == 0) return "Default";
String get_save_extension() const override {return "spjson";} else
String get_resource_type() const override {return "SpineSkeletonJsonDataResource";} return "Unknown";
void get_import_options(List<ImportOption> *r_options, int p_preset) const override {} }
bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override {return true;} int get_preset_count() const override { return 1; }
Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) override; String get_save_extension() const override { return "spjson"; }
String get_resource_type() const override { return "SpineSkeletonJsonDataResource"; }
void get_import_options(List<ImportOption> *r_options, int p_preset) const override {}
bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override { return true; }
Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) override;
}; };
class SpineSpriteAnimateDialog; class SpineSpriteAnimateDialog;
@ -71,10 +79,11 @@ class SpineRuntimeEditorPlugin : public EditorPlugin {
GDCLASS(SpineRuntimeEditorPlugin, EditorPlugin); GDCLASS(SpineRuntimeEditorPlugin, EditorPlugin);
protected: protected:
SpineSpriteAnimateDialog *animate_dialog; SpineSpriteAnimateDialog *animate_dialog;
public: public:
SpineRuntimeEditorPlugin(EditorNode *p_node); SpineRuntimeEditorPlugin(EditorNode *p_node);
~SpineRuntimeEditorPlugin(); ~SpineRuntimeEditorPlugin();
String get_name() const override { return "SpineRuntimeEditorPlugin"; } String get_name() const override { return "SpineRuntimeEditorPlugin"; }
bool has_main_screen() const { return false; } bool has_main_screen() const { return false; }
@ -86,4 +95,4 @@ public:
}; };
#endif #endif
#endif //GODOT_SPINERUNTIMEEDITORPLUGIN_H #endif//GODOT_SPINERUNTIMEEDITORPLUGIN_H

View File

@ -30,49 +30,49 @@
#include "SpineSkeleton.h" #include "SpineSkeleton.h"
void SpineSkeleton::_bind_methods() { void SpineSkeleton::_bind_methods() {
//void update_world_transform(); //void update_world_transform();
// //
// void set_to_setup_pose(); // void set_to_setup_pose();
// //
// void set_bones_to_setup_pose(); // void set_bones_to_setup_pose();
// //
// void set_slots_to_setup_pose(); // void set_slots_to_setup_pose();
ClassDB::bind_method(D_METHOD("update_world_transform"), &SpineSkeleton::update_world_transform); ClassDB::bind_method(D_METHOD("update_world_transform"), &SpineSkeleton::update_world_transform);
ClassDB::bind_method(D_METHOD("set_to_setup_pose"), &SpineSkeleton::set_to_setup_pose); ClassDB::bind_method(D_METHOD("set_to_setup_pose"), &SpineSkeleton::set_to_setup_pose);
ClassDB::bind_method(D_METHOD("set_bones_to_setup_pose"), &SpineSkeleton::set_bones_to_setup_pose); ClassDB::bind_method(D_METHOD("set_bones_to_setup_pose"), &SpineSkeleton::set_bones_to_setup_pose);
ClassDB::bind_method(D_METHOD("set_slots_to_setup_pose"), &SpineSkeleton::set_slots_to_setup_pose); ClassDB::bind_method(D_METHOD("set_slots_to_setup_pose"), &SpineSkeleton::set_slots_to_setup_pose);
// //
// Ref<SpineBone> find_bone(const String &name); // Ref<SpineBone> find_bone(const String &name);
// int find_bone_index(const String &name); // int find_bone_index(const String &name);
// //
// Ref<SpineSlot> find_slot(const String &name); // Ref<SpineSlot> find_slot(const String &name);
// int find_slot_index(const String &name); // int find_slot_index(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);
ClassDB::bind_method(D_METHOD("find_bone", "bone_name"), &SpineSkeleton::find_bone); ClassDB::bind_method(D_METHOD("find_bone", "bone_name"), &SpineSkeleton::find_bone);
ClassDB::bind_method(D_METHOD("find_slot", "slot_name"), &SpineSkeleton::find_slot); ClassDB::bind_method(D_METHOD("find_slot", "slot_name"), &SpineSkeleton::find_slot);
ClassDB::bind_method(D_METHOD("set_skin_by_name", "skin_name"), &SpineSkeleton::set_skin_by_name); ClassDB::bind_method(D_METHOD("set_skin_by_name", "skin_name"), &SpineSkeleton::set_skin_by_name);
ClassDB::bind_method(D_METHOD("set_skin", "new_skin"), &SpineSkeleton::set_skin); ClassDB::bind_method(D_METHOD("set_skin", "new_skin"), &SpineSkeleton::set_skin);
ClassDB::bind_method(D_METHOD("get_attachment_by_slot_name", "slot_name", "attachment_name"), &SpineSkeleton::get_attachment_by_slot_name); ClassDB::bind_method(D_METHOD("get_attachment_by_slot_name", "slot_name", "attachment_name"), &SpineSkeleton::get_attachment_by_slot_name);
ClassDB::bind_method(D_METHOD("get_attachment_by_slot_index", "slot_index", "attachment_name"), &SpineSkeleton::get_attachment_by_slot_index); ClassDB::bind_method(D_METHOD("get_attachment_by_slot_index", "slot_index", "attachment_name"), &SpineSkeleton::get_attachment_by_slot_index);
// //
// 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);
// //
// void update(float delta); // void update(float delta);
// //
// Dictionary get_bounds(); // Dictionary get_bounds();
// //
// Ref<SpineBone> get_root_bone(); // Ref<SpineBone> get_root_bone();
// //
// Ref<SpineSkeletonDataResource> get_data(); // Ref<SpineSkeletonDataResource> get_data();
ClassDB::bind_method(D_METHOD("set_attachment", "slot_name", "attachment_name"), &SpineSkeleton::set_attachment); ClassDB::bind_method(D_METHOD("set_attachment", "slot_name", "attachment_name"), &SpineSkeleton::set_attachment);
ClassDB::bind_method(D_METHOD("find_ik_constraint", "constraint_name"), &SpineSkeleton::find_ik_constraint); ClassDB::bind_method(D_METHOD("find_ik_constraint", "constraint_name"), &SpineSkeleton::find_ik_constraint);
ClassDB::bind_method(D_METHOD("find_transform_constraint", "constraint_name"), &SpineSkeleton::find_transform_constraint); ClassDB::bind_method(D_METHOD("find_transform_constraint", "constraint_name"), &SpineSkeleton::find_transform_constraint);
@ -81,15 +81,15 @@ void SpineSkeleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_bounds"), &SpineSkeleton::get_bounds); ClassDB::bind_method(D_METHOD("get_bounds"), &SpineSkeleton::get_bounds);
ClassDB::bind_method(D_METHOD("get_root_bone"), &SpineSkeleton::get_root_bone); ClassDB::bind_method(D_METHOD("get_root_bone"), &SpineSkeleton::get_root_bone);
ClassDB::bind_method(D_METHOD("get_data"), &SpineSkeleton::get_data); ClassDB::bind_method(D_METHOD("get_data"), &SpineSkeleton::get_data);
// //
// Array get_bones(); // Array get_bones();
// Array get_slots(); // Array get_slots();
// Array get_draw_orders(); // Array get_draw_orders();
// 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();
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_orders"), &SpineSkeleton::get_draw_orders);
@ -97,31 +97,31 @@ void SpineSkeleton::_bind_methods() {
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);
// //
// Color get_color(); // Color get_color();
// void set_color(Color v); // void set_color(Color v);
// //
// float get_time(); // float get_time();
// void set_time(float v); // void set_time(float v);
// //
// void set_position(Vector2 pos); // void set_position(Vector2 pos);
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("get_time"), &SpineSkeleton::get_time); ClassDB::bind_method(D_METHOD("get_time"), &SpineSkeleton::get_time);
ClassDB::bind_method(D_METHOD("set_time", "v"), &SpineSkeleton::set_time); ClassDB::bind_method(D_METHOD("set_time", "v"), &SpineSkeleton::set_time);
ClassDB::bind_method(D_METHOD("set_position", "pos"), &SpineSkeleton::set_position); ClassDB::bind_method(D_METHOD("set_position", "pos"), &SpineSkeleton::set_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);
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);
@ -132,21 +132,18 @@ void SpineSkeleton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_scale_y", "v"), &SpineSkeleton::set_scale_y); ClassDB::bind_method(D_METHOD("set_scale_y", "v"), &SpineSkeleton::set_scale_y);
} }
SpineSkeleton::SpineSkeleton():skeleton(NULL),spine_object(false),the_sprite(nullptr) { SpineSkeleton::SpineSkeleton() : skeleton(NULL), spine_object(false), the_sprite(nullptr) {
} }
SpineSkeleton::~SpineSkeleton() { SpineSkeleton::~SpineSkeleton() {
if(skeleton && !spine_object) if (skeleton && !spine_object) {
{
delete skeleton; delete skeleton;
skeleton = NULL; skeleton = NULL;
} }
} }
void SpineSkeleton::load_skeleton(Ref<SpineSkeletonDataResource> sd) { void SpineSkeleton::load_skeleton(Ref<SpineSkeletonDataResource> sd) {
if(skeleton && !spine_object) if (skeleton && !spine_object) {
{
delete skeleton; delete skeleton;
skeleton = NULL; skeleton = NULL;
} }
@ -155,103 +152,103 @@ void SpineSkeleton::load_skeleton(Ref<SpineSkeletonDataResource> sd) {
} }
#define S_T(x) (spine::String(x.utf8())) #define S_T(x) (spine::String(x.utf8()))
void SpineSkeleton::update_world_transform(){ void SpineSkeleton::update_world_transform() {
skeleton->updateWorldTransform(); skeleton->updateWorldTransform();
} }
void SpineSkeleton::set_to_setup_pose(){ void SpineSkeleton::set_to_setup_pose() {
skeleton->setToSetupPose(); skeleton->setToSetupPose();
} }
void SpineSkeleton::set_bones_to_setup_pose(){ void SpineSkeleton::set_bones_to_setup_pose() {
skeleton->setBonesToSetupPose(); skeleton->setBonesToSetupPose();
} }
void SpineSkeleton::set_slots_to_setup_pose(){ void SpineSkeleton::set_slots_to_setup_pose() {
skeleton->setSlotsToSetupPose(); skeleton->setSlotsToSetupPose();
} }
Ref<SpineBone> SpineSkeleton::find_bone(const String &name){ Ref<SpineBone> SpineSkeleton::find_bone(const String &name) {
if(name.empty()) return NULL; if (name.empty()) return NULL;
auto b = skeleton->findBone(S_T(name)); auto b = skeleton->findBone(S_T(name));
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineBone> gd_b(memnew(SpineBone)); Ref<SpineBone> gd_b(memnew(SpineBone));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
gd_b->set_spine_sprite(the_sprite); gd_b->set_spine_sprite(the_sprite);
return gd_b; return gd_b;
} }
Ref<SpineSlot> SpineSkeleton::find_slot(const String &name){ Ref<SpineSlot> SpineSkeleton::find_slot(const String &name) {
if(name.empty()) return NULL; if (name.empty()) return NULL;
auto s = skeleton->findSlot(S_T(name)); auto s = skeleton->findSlot(S_T(name));
if(s == NULL) return NULL; if (s == NULL) return NULL;
Ref<SpineSlot> gd_s(memnew(SpineSlot)); Ref<SpineSlot> gd_s(memnew(SpineSlot));
gd_s->set_spine_object(s); gd_s->set_spine_object(s);
return gd_s; return gd_s;
} }
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)); skeleton->setSkin(S_T(skin_name));
} }
void SpineSkeleton::set_skin(Ref<SpineSkin> new_skin){ void SpineSkeleton::set_skin(Ref<SpineSkin> new_skin) {
if(new_skin.is_valid()){ if (new_skin.is_valid()) {
skeleton->setSkin(new_skin->get_spine_object()); skeleton->setSkin(new_skin->get_spine_object());
}else{ } else {
skeleton->setSkin(NULL); skeleton->setSkin(NULL);
} }
} }
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)); auto a = skeleton->getAttachment(S_T(slot_name), S_T(attachment_name));
if(a == NULL) return NULL; if (a == NULL) return NULL;
Ref<SpineAttachment> gd_a(memnew(SpineAttachment)); Ref<SpineAttachment> gd_a(memnew(SpineAttachment));
gd_a->set_spine_object(a); gd_a->set_spine_object(a);
return gd_a; return gd_a;
} }
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)); auto a = skeleton->getAttachment(slot_index, S_T(attachment_name));
if(a == NULL) return NULL; if (a == NULL) return NULL;
Ref<SpineAttachment> gd_a(memnew(SpineAttachment)); Ref<SpineAttachment> gd_a(memnew(SpineAttachment));
gd_a->set_spine_object(a); gd_a->set_spine_object(a);
return gd_a; return gd_a;
} }
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()); ERR_FAIL_COND(slot_name.empty());
ERR_FAIL_COND(get_attachment_by_slot_name(slot_name, attachment_name) == NULL); ERR_FAIL_COND(get_attachment_by_slot_name(slot_name, attachment_name) == NULL);
skeleton->setAttachment(S_T(slot_name), S_T(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 NULL; if (constraint_name.empty()) return NULL;
auto c = skeleton->findIkConstraint(S_T(constraint_name)); auto c = skeleton->findIkConstraint(S_T(constraint_name));
if(c == NULL) return NULL; if (c == NULL) return NULL;
Ref<SpineIkConstraint> gd_c(memnew(SpineIkConstraint)); Ref<SpineIkConstraint> gd_c(memnew(SpineIkConstraint));
gd_c->set_spine_object(c); gd_c->set_spine_object(c);
return gd_c; return gd_c;
} }
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 NULL; if (constraint_name.empty()) return NULL;
auto c = skeleton->findTransformConstraint(S_T(constraint_name)); auto c = skeleton->findTransformConstraint(S_T(constraint_name));
if(c == NULL) return NULL; if (c == NULL) return NULL;
Ref<SpineTransformConstraint> gd_c(memnew(SpineTransformConstraint)); Ref<SpineTransformConstraint> gd_c(memnew(SpineTransformConstraint));
gd_c->set_spine_object(c); gd_c->set_spine_object(c);
return gd_c; return gd_c;
} }
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 NULL; if (constraint_name.empty()) return NULL;
auto c = skeleton->findPathConstraint(S_T(constraint_name)); auto c = skeleton->findPathConstraint(S_T(constraint_name));
if(c == NULL) return NULL; if (c == NULL) return NULL;
Ref<SpinePathConstraint> gd_c(memnew(SpinePathConstraint)); Ref<SpinePathConstraint> gd_c(memnew(SpinePathConstraint));
gd_c->set_spine_object(c); gd_c->set_spine_object(c);
return gd_c; return gd_c;
} }
void SpineSkeleton::update(float delta){ void SpineSkeleton::update(float delta) {
skeleton->update(delta); skeleton->update(delta);
} }
Dictionary SpineSkeleton::get_bounds(){ Dictionary SpineSkeleton::get_bounds() {
float x, y, w, h; float x, y, w, h;
spine::Vector<float> vertex_buffer; spine::Vector<float> vertex_buffer;
skeleton->getBounds(x, y, w, h, vertex_buffer); skeleton->getBounds(x, y, w, h, vertex_buffer);
@ -264,7 +261,7 @@ Dictionary SpineSkeleton::get_bounds(){
Array gd_a; Array gd_a;
gd_a.resize(vertex_buffer.size()); gd_a.resize(vertex_buffer.size());
for(size_t i=0; i<gd_a.size(); ++i){ for (size_t i = 0; i < gd_a.size(); ++i) {
gd_a[i] = vertex_buffer[i]; gd_a[i] = vertex_buffer[i];
} }
res["vertex_buffer"] = gd_a; res["vertex_buffer"] = gd_a;
@ -272,9 +269,9 @@ Dictionary SpineSkeleton::get_bounds(){
return res; return res;
} }
Ref<SpineBone> SpineSkeleton::get_root_bone(){ Ref<SpineBone> SpineSkeleton::get_root_bone() {
auto b = skeleton->getRootBone(); auto b = skeleton->getRootBone();
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineBone> gd_b(memnew(SpineBone)); Ref<SpineBone> gd_b(memnew(SpineBone));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
gd_b->set_spine_sprite(the_sprite); gd_b->set_spine_sprite(the_sprite);
@ -283,19 +280,19 @@ Ref<SpineBone> SpineSkeleton::get_root_bone(){
Ref<SpineSkeletonDataResource> SpineSkeleton::get_data() const { Ref<SpineSkeletonDataResource> SpineSkeleton::get_data() const {
auto sd = skeleton->getData(); auto sd = skeleton->getData();
if(sd == NULL) return NULL; if (sd == NULL) return NULL;
Ref<SpineSkeletonDataResource> gd_sd(memnew(SpineSkeletonDataResource)); Ref<SpineSkeletonDataResource> gd_sd(memnew(SpineSkeletonDataResource));
gd_sd->set_spine_object(sd); gd_sd->set_spine_object(sd);
return gd_sd; return gd_sd;
} }
Array SpineSkeleton::get_bones(){ Array SpineSkeleton::get_bones() {
auto &as = skeleton->getBones(); auto &as = skeleton->getBones();
Array gd_as; Array gd_as;
gd_as.resize(as.size()); gd_as.resize(as.size());
for(size_t i=0; i<gd_as.size(); ++i){ for (size_t i = 0; i < gd_as.size(); ++i) {
auto b = as[i]; auto b = as[i];
if(b == NULL) gd_as[i] = Ref<SpineBone>(NULL); if (b == NULL) gd_as[i] = Ref<SpineBone>(NULL);
Ref<SpineBone> gd_a(memnew(SpineBone)); Ref<SpineBone> gd_a(memnew(SpineBone));
gd_a->set_spine_object(b); gd_a->set_spine_object(b);
gd_a->set_spine_sprite(the_sprite); gd_a->set_spine_sprite(the_sprite);
@ -303,65 +300,65 @@ Array SpineSkeleton::get_bones(){
} }
return gd_as; return gd_as;
} }
Array SpineSkeleton::get_slots(){ Array SpineSkeleton::get_slots() {
auto &as = skeleton->getSlots(); auto &as = skeleton->getSlots();
Array gd_as; Array gd_as;
gd_as.resize(as.size()); gd_as.resize(as.size());
for(size_t i=0; i<gd_as.size(); ++i){ for (size_t i = 0; i < gd_as.size(); ++i) {
auto b = as[i]; auto b = as[i];
if(b == NULL) gd_as[i] = Ref<SpineSlot>(NULL); if (b == NULL) gd_as[i] = Ref<SpineSlot>(NULL);
Ref<SpineSlot> gd_a(memnew(SpineSlot)); Ref<SpineSlot> gd_a(memnew(SpineSlot));
gd_a->set_spine_object(b); gd_a->set_spine_object(b);
gd_as[i] = gd_a; gd_as[i] = gd_a;
} }
return gd_as; return gd_as;
} }
Array SpineSkeleton::get_draw_orders(){ Array SpineSkeleton::get_draw_orders() {
auto &as = skeleton->getDrawOrder(); auto &as = skeleton->getDrawOrder();
Array gd_as; Array gd_as;
gd_as.resize(as.size()); gd_as.resize(as.size());
for(size_t i=0; i<gd_as.size(); ++i){ for (size_t i = 0; i < gd_as.size(); ++i) {
auto b = as[i]; auto b = as[i];
if(b == NULL) gd_as[i] = Ref<SpineSlot>(NULL); if (b == NULL) gd_as[i] = Ref<SpineSlot>(NULL);
Ref<SpineSlot> gd_a(memnew(SpineSlot)); Ref<SpineSlot> gd_a(memnew(SpineSlot));
gd_a->set_spine_object(b); gd_a->set_spine_object(b);
gd_as[i] = gd_a; gd_as[i] = gd_a;
} }
return gd_as; return gd_as;
} }
Array SpineSkeleton::get_ik_constraints(){ Array SpineSkeleton::get_ik_constraints() {
auto &as = skeleton->getIkConstraints(); auto &as = skeleton->getIkConstraints();
Array gd_as; Array gd_as;
gd_as.resize(as.size()); gd_as.resize(as.size());
for(size_t i=0; i<gd_as.size(); ++i){ for (size_t i = 0; i < gd_as.size(); ++i) {
auto b = as[i]; auto b = as[i];
if(b == NULL) gd_as[i] = Ref<SpineIkConstraint>(NULL); if (b == NULL) gd_as[i] = Ref<SpineIkConstraint>(NULL);
Ref<SpineIkConstraint> gd_a(memnew(SpineIkConstraint)); Ref<SpineIkConstraint> gd_a(memnew(SpineIkConstraint));
gd_a->set_spine_object(b); gd_a->set_spine_object(b);
gd_as[i] = gd_a; gd_as[i] = gd_a;
} }
return gd_as; return gd_as;
} }
Array SpineSkeleton::get_path_constraints(){ Array SpineSkeleton::get_path_constraints() {
auto &as = skeleton->getPathConstraints(); auto &as = skeleton->getPathConstraints();
Array gd_as; Array gd_as;
gd_as.resize(as.size()); gd_as.resize(as.size());
for(size_t i=0; i<gd_as.size(); ++i){ for (size_t i = 0; i < gd_as.size(); ++i) {
auto b = as[i]; auto b = as[i];
if(b == NULL) gd_as[i] = Ref<SpinePathConstraint>(NULL); if (b == NULL) gd_as[i] = Ref<SpinePathConstraint>(NULL);
Ref<SpinePathConstraint> gd_a(memnew(SpinePathConstraint)); Ref<SpinePathConstraint> gd_a(memnew(SpinePathConstraint));
gd_a->set_spine_object(b); gd_a->set_spine_object(b);
gd_as[i] = gd_a; gd_as[i] = gd_a;
} }
return gd_as; return gd_as;
} }
Array SpineSkeleton::get_transform_constraints(){ Array SpineSkeleton::get_transform_constraints() {
auto &as = skeleton->getTransformConstraints(); auto &as = skeleton->getTransformConstraints();
Array gd_as; Array gd_as;
gd_as.resize(as.size()); gd_as.resize(as.size());
for(size_t i=0; i<gd_as.size(); ++i){ for (size_t i = 0; i < gd_as.size(); ++i) {
auto b = as[i]; auto b = as[i];
if(b == NULL) gd_as[i] = Ref<SpineTransformConstraint>(NULL); if (b == NULL) gd_as[i] = Ref<SpineTransformConstraint>(NULL);
Ref<SpineTransformConstraint> gd_a(memnew(SpineTransformConstraint)); Ref<SpineTransformConstraint> gd_a(memnew(SpineTransformConstraint));
gd_a->set_spine_object(b); gd_a->set_spine_object(b);
gd_as[i] = gd_a; gd_as[i] = gd_a;
@ -369,62 +366,62 @@ Array SpineSkeleton::get_transform_constraints(){
return gd_as; return gd_as;
} }
Ref<SpineSkin> SpineSkeleton::get_skin(){ Ref<SpineSkin> SpineSkeleton::get_skin() {
auto s = skeleton->getSkin(); auto s = skeleton->getSkin();
if(s == NULL) return NULL; if (s == NULL) return NULL;
Ref<SpineSkin> gd_s(memnew(SpineSkin)); Ref<SpineSkin> gd_s(memnew(SpineSkin));
gd_s->set_spine_object(s); gd_s->set_spine_object(s);
return gd_s; return gd_s;
} }
Color SpineSkeleton::get_color(){ Color SpineSkeleton::get_color() {
auto &c = skeleton->getColor(); auto &c = skeleton->getColor();
return Color(c.r, c.g, c.b, c.a); return Color(c.r, c.g, c.b, c.a);
} }
void SpineSkeleton::set_color(Color v){ void SpineSkeleton::set_color(Color v) {
auto &c = skeleton->getColor(); auto &c = skeleton->getColor();
c.set(v.r, v.g, v.b, v.a); c.set(v.r, v.g, v.b, v.a);
} }
float SpineSkeleton::get_time(){ float SpineSkeleton::get_time() {
return skeleton->getTime(); return skeleton->getTime();
} }
void SpineSkeleton::set_time(float v){ void SpineSkeleton::set_time(float v) {
skeleton->setTime(v); skeleton->setTime(v);
} }
void SpineSkeleton::set_position(Vector2 pos){ void SpineSkeleton::set_position(Vector2 pos) {
skeleton->setPosition(pos.x, pos.y); skeleton->setPosition(pos.x, pos.y);
} }
float SpineSkeleton::get_x(){ float SpineSkeleton::get_x() {
return skeleton->getX(); return skeleton->getX();
} }
void SpineSkeleton::set_x(float v){ void SpineSkeleton::set_x(float v) {
skeleton->setX(v); skeleton->setX(v);
} }
float SpineSkeleton::get_y(){ float SpineSkeleton::get_y() {
return skeleton->getY(); return skeleton->getY();
} }
void SpineSkeleton::set_y(float v){ void SpineSkeleton::set_y(float v) {
skeleton->setY(v); skeleton->setY(v);
} }
float SpineSkeleton::get_scale_x(){ float SpineSkeleton::get_scale_x() {
return skeleton->getScaleX(); return skeleton->getScaleX();
} }
void SpineSkeleton::set_scale_x(float v){ void SpineSkeleton::set_scale_x(float v) {
skeleton->setScaleX(v); skeleton->setScaleX(v);
} }
float SpineSkeleton::get_scale_y(){ float SpineSkeleton::get_scale_y() {
return skeleton->getScaleY(); return skeleton->getScaleY();
} }
void SpineSkeleton::set_scale_y(float v){ void SpineSkeleton::set_scale_y(float v) {
skeleton->setScaleY(v); skeleton->setScaleY(v);
} }
void SpineSkeleton::set_spine_sprite(SpineSprite *s) { void SpineSkeleton::set_spine_sprite(SpineSprite *s) {
the_sprite = s; the_sprite = s;
} }

View File

@ -40,7 +40,7 @@
class SpineSprite; class SpineSprite;
class SpineSkeleton : public Reference{ class SpineSkeleton : public Reference {
GDCLASS(SpineSkeleton, Reference); GDCLASS(SpineSkeleton, Reference);
protected: protected:
@ -51,18 +51,18 @@ private:
bool spine_object; bool spine_object;
SpineSprite *the_sprite; SpineSprite *the_sprite;
public:
public:
SpineSkeleton(); SpineSkeleton();
~SpineSkeleton(); ~SpineSkeleton();
void load_skeleton(Ref<SpineSkeletonDataResource> sd); void load_skeleton(Ref<SpineSkeletonDataResource> sd);
inline void set_spine_object(spine::Skeleton *s){ inline void set_spine_object(spine::Skeleton *s) {
skeleton = s; skeleton = s;
spine_object = true; spine_object = true;
} }
inline spine::Skeleton *get_spine_object(){ inline spine::Skeleton *get_spine_object() {
return skeleton; return skeleton;
} }
@ -79,7 +79,7 @@ public:
Ref<SpineBone> find_bone(const String &name); Ref<SpineBone> find_bone(const String &name);
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);
@ -129,7 +129,6 @@ public:
float get_scale_y(); float get_scale_y();
void set_scale_y(float v); void set_scale_y(float v);
}; };
#endif //GODOT_SPINESKELETON_H #endif//GODOT_SPINESKELETON_H

View File

@ -34,7 +34,7 @@ void SpineSkeletonDataResource::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_atlas_res"), &SpineSkeletonDataResource::get_atlas_res); ClassDB::bind_method(D_METHOD("get_atlas_res"), &SpineSkeletonDataResource::get_atlas_res);
ClassDB::bind_method(D_METHOD("set_skeleton_json_res", "skeleton_json_res"), &SpineSkeletonDataResource::set_skeleton_json_res); ClassDB::bind_method(D_METHOD("set_skeleton_json_res", "skeleton_json_res"), &SpineSkeletonDataResource::set_skeleton_json_res);
ClassDB::bind_method(D_METHOD("get_skeleton_json_res"), &SpineSkeletonDataResource::get_skeleton_json_res); ClassDB::bind_method(D_METHOD("get_skeleton_json_res"), &SpineSkeletonDataResource::get_skeleton_json_res);
ClassDB::bind_method(D_METHOD("is_skeleton_data_loaded"), &SpineSkeletonDataResource::is_skeleton_data_loaded); ClassDB::bind_method(D_METHOD("is_skeleton_data_loaded"), &SpineSkeletonDataResource::is_skeleton_data_loaded);
ClassDB::bind_method(D_METHOD("find_animation", "animation_name"), &SpineSkeletonDataResource::find_animation); ClassDB::bind_method(D_METHOD("find_animation", "animation_name"), &SpineSkeletonDataResource::find_animation);
ClassDB::bind_method(D_METHOD("get_sk_name"), &SpineSkeletonDataResource::get_sk_name); ClassDB::bind_method(D_METHOD("get_sk_name"), &SpineSkeletonDataResource::get_sk_name);
ClassDB::bind_method(D_METHOD("set_sk_name", "sk_name"), &SpineSkeletonDataResource::set_sk_name); ClassDB::bind_method(D_METHOD("set_sk_name", "sk_name"), &SpineSkeletonDataResource::set_sk_name);
@ -74,18 +74,16 @@ void SpineSkeletonDataResource::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skeleton_json_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineSkeletonJsonDataResource"), "set_skeleton_json_res", "get_skeleton_json_res"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "skeleton_json_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineSkeletonJsonDataResource"), "set_skeleton_json_res", "get_skeleton_json_res");
} }
SpineSkeletonDataResource::SpineSkeletonDataResource():valid(false),spine_object(false),skeleton_data(NULL) { SpineSkeletonDataResource::SpineSkeletonDataResource() : valid(false), spine_object(false), skeleton_data(NULL) {
} }
SpineSkeletonDataResource::~SpineSkeletonDataResource() { SpineSkeletonDataResource::~SpineSkeletonDataResource() {
if(skeleton_data && !spine_object) if (skeleton_data && !spine_object) {
{
delete skeleton_data; delete skeleton_data;
skeleton_data = NULL; skeleton_data = NULL;
} }
} }
bool SpineSkeletonDataResource::is_skeleton_data_loaded() const{ bool SpineSkeletonDataResource::is_skeleton_data_loaded() const {
return valid || spine_object; return valid || spine_object;
} }
@ -94,29 +92,25 @@ void SpineSkeletonDataResource::load_res(spine::Atlas *a, const String &json_str
auto path = get_path(); auto path = get_path();
spine::SkeletonJson json(a); spine::SkeletonJson json(a);
auto temp_skeleton_data = json.readSkeletonData(json_string.utf8()); auto temp_skeleton_data = json.readSkeletonData(json_string.utf8());
if(!temp_skeleton_data) if (!temp_skeleton_data) {
{
print_error(String("Error happened while loading skeleton json data: ") + path); print_error(String("Error happened while loading skeleton json data: ") + path);
print_error(String("Error msg: ") + json.getError().buffer()); print_error(String("Error msg: ") + json.getError().buffer());
return; return;
} }
if(skeleton_data) if (skeleton_data) {
{
delete skeleton_data; delete skeleton_data;
skeleton_data = NULL; skeleton_data = NULL;
} }
skeleton_data = temp_skeleton_data; skeleton_data = temp_skeleton_data;
valid = true; valid = true;
// print_line("Skeleton json data loaded!"); // print_line("Skeleton json data loaded!");
} }
void SpineSkeletonDataResource::update_skeleton_data() { void SpineSkeletonDataResource::update_skeleton_data() {
if(atlas_res.is_valid() && skeleton_json_res.is_valid()) if (atlas_res.is_valid() && skeleton_json_res.is_valid()) {
{
load_res(atlas_res->get_spine_atlas(), skeleton_json_res->get_json_string()); load_res(atlas_res->get_spine_atlas(), skeleton_json_res->get_json_string());
if(valid) if (valid) {
{
emit_signal("skeleton_data_loaded"); emit_signal("skeleton_data_loaded");
} }
} }
@ -125,12 +119,12 @@ void SpineSkeletonDataResource::update_skeleton_data() {
void SpineSkeletonDataResource::set_atlas_res(const Ref<SpineAtlasResource> &a) { void SpineSkeletonDataResource::set_atlas_res(const Ref<SpineAtlasResource> &a) {
atlas_res = a; atlas_res = a;
valid = false; valid = false;
// print_line("atlas_res_changed emitted"); // print_line("atlas_res_changed emitted");
emit_signal("atlas_res_changed"); emit_signal("atlas_res_changed");
update_skeleton_data(); update_skeleton_data();
} }
Ref<SpineAtlasResource> SpineSkeletonDataResource::get_atlas_res() { Ref<SpineAtlasResource> SpineSkeletonDataResource::get_atlas_res() {
if(spine_object){ if (spine_object) {
print_line("Getting atlas res from a spine_object skeleton! The result may be NULL!"); print_line("Getting atlas res from a spine_object skeleton! The result may be NULL!");
} }
return atlas_res; return atlas_res;
@ -139,27 +133,35 @@ Ref<SpineAtlasResource> SpineSkeletonDataResource::get_atlas_res() {
void SpineSkeletonDataResource::set_skeleton_json_res(const Ref<SpineSkeletonJsonDataResource> &s) { void SpineSkeletonDataResource::set_skeleton_json_res(const Ref<SpineSkeletonJsonDataResource> &s) {
skeleton_json_res = s; skeleton_json_res = s;
valid = false; valid = false;
// print_line("skeleton_json_res_changed emitted"); // print_line("skeleton_json_res_changed emitted");
emit_signal("skeleton_json_res_changed"); emit_signal("skeleton_json_res_changed");
update_skeleton_data(); update_skeleton_data();
} }
Ref<SpineSkeletonJsonDataResource> SpineSkeletonDataResource::get_skeleton_json_res() { Ref<SpineSkeletonJsonDataResource> SpineSkeletonDataResource::get_skeleton_json_res() {
if(spine_object){ if (spine_object) {
print_line("Getting atlas res from a spine_object skeleton! The result may be NULL!"); print_line("Getting atlas res from a spine_object skeleton! The result may be NULL!");
} }
return skeleton_json_res; return skeleton_json_res;
} }
#define CHECK_V if(!is_skeleton_data_loaded()){ERR_PRINT("skeleton data has not loaded yet!");return;} #define CHECK_V \
#define CHECK_X(x) if(!is_skeleton_data_loaded()){ERR_PRINT("skeleton data has not loaded yet!");return x;} if (!is_skeleton_data_loaded()) { \
ERR_PRINT("skeleton data has not loaded yet!"); \
return; \
}
#define CHECK_X(x) \
if (!is_skeleton_data_loaded()) { \
ERR_PRINT("skeleton data has not loaded yet!"); \
return x; \
}
#define S_T(x) (spine::String(x.utf8())) #define S_T(x) (spine::String(x.utf8()))
Ref<SpineAnimation> SpineSkeletonDataResource::find_animation(const String &animation_name) { Ref<SpineAnimation> SpineSkeletonDataResource::find_animation(const String &animation_name) {
CHECK_X(NULL); CHECK_X(NULL);
if(animation_name.empty()){ if (animation_name.empty()) {
return NULL; return NULL;
} }
auto a = skeleton_data->findAnimation(S_T(animation_name)); auto a = skeleton_data->findAnimation(S_T(animation_name));
if(!a) return NULL; if (!a) return NULL;
Ref<SpineAnimation> sa(memnew(SpineAnimation)); Ref<SpineAnimation> sa(memnew(SpineAnimation));
sa->set_spine_object(a); sa->set_spine_object(a);
return sa; return sa;
@ -209,73 +211,73 @@ void SpineSkeletonDataResource::set_fps(float v) {
skeleton_data->setFps(v); skeleton_data->setFps(v);
} }
Ref<SpineBoneData> SpineSkeletonDataResource::find_bone(const String &bone_name){ Ref<SpineBoneData> SpineSkeletonDataResource::find_bone(const String &bone_name) {
if(bone_name.empty()) return NULL; if (bone_name.empty()) return NULL;
auto b = skeleton_data->findBone(S_T(bone_name)); auto b = skeleton_data->findBone(S_T(bone_name));
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineBoneData> gd_b(memnew(SpineBoneData)); Ref<SpineBoneData> gd_b(memnew(SpineBoneData));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
return gd_b; return gd_b;
} }
Ref<SpineSlotData> SpineSkeletonDataResource::find_slot(const String &slot_name){ Ref<SpineSlotData> SpineSkeletonDataResource::find_slot(const String &slot_name) {
if(slot_name.empty()) return NULL; if (slot_name.empty()) return NULL;
auto b = skeleton_data->findSlot(S_T(slot_name)); auto b = skeleton_data->findSlot(S_T(slot_name));
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineSlotData> gd_b(memnew(SpineSlotData)); Ref<SpineSlotData> gd_b(memnew(SpineSlotData));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
return gd_b; return gd_b;
} }
Ref<SpineSkin> SpineSkeletonDataResource::find_skin(const String &skin_name){ Ref<SpineSkin> SpineSkeletonDataResource::find_skin(const String &skin_name) {
if(skin_name.empty()) return NULL; if (skin_name.empty()) return NULL;
auto b = skeleton_data->findSkin(S_T(skin_name)); auto b = skeleton_data->findSkin(S_T(skin_name));
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineSkin> gd_b(memnew(SpineSkin)); Ref<SpineSkin> gd_b(memnew(SpineSkin));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
return gd_b; return gd_b;
} }
Ref<SpineEventData> SpineSkeletonDataResource::find_event(const String &event_data_name){ Ref<SpineEventData> SpineSkeletonDataResource::find_event(const String &event_data_name) {
if(event_data_name.empty()) return NULL; if (event_data_name.empty()) return NULL;
auto b = skeleton_data->findEvent(S_T(event_data_name)); auto b = skeleton_data->findEvent(S_T(event_data_name));
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineEventData> gd_b(memnew(SpineEventData)); Ref<SpineEventData> gd_b(memnew(SpineEventData));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
return gd_b; return gd_b;
} }
Ref<SpineIkConstraintData> SpineSkeletonDataResource::find_ik_constraint(const String &constraint_name){ Ref<SpineIkConstraintData> SpineSkeletonDataResource::find_ik_constraint(const String &constraint_name) {
if(constraint_name.empty()) return NULL; if (constraint_name.empty()) return NULL;
auto b = skeleton_data->findIkConstraint(S_T(constraint_name)); auto b = skeleton_data->findIkConstraint(S_T(constraint_name));
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineIkConstraintData> gd_b(memnew(SpineIkConstraintData)); Ref<SpineIkConstraintData> gd_b(memnew(SpineIkConstraintData));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
return gd_b; return gd_b;
} }
Ref<SpineTransformConstraintData> SpineSkeletonDataResource::find_transform_constraint(const String &constraint_name){ Ref<SpineTransformConstraintData> SpineSkeletonDataResource::find_transform_constraint(const String &constraint_name) {
if(constraint_name.empty()) return NULL; if (constraint_name.empty()) return NULL;
auto b = skeleton_data->findTransformConstraint(S_T(constraint_name)); auto b = skeleton_data->findTransformConstraint(S_T(constraint_name));
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineTransformConstraintData> gd_b(memnew(SpineTransformConstraintData)); Ref<SpineTransformConstraintData> gd_b(memnew(SpineTransformConstraintData));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
return gd_b; return gd_b;
} }
Ref<SpinePathConstraintData> SpineSkeletonDataResource::find_path_constraint(const String &constraint_name){ Ref<SpinePathConstraintData> SpineSkeletonDataResource::find_path_constraint(const String &constraint_name) {
if(constraint_name.empty()) return NULL; if (constraint_name.empty()) return NULL;
auto b = skeleton_data->findPathConstraint(S_T(constraint_name)); auto b = skeleton_data->findPathConstraint(S_T(constraint_name));
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpinePathConstraintData> gd_b(memnew(SpinePathConstraintData)); Ref<SpinePathConstraintData> gd_b(memnew(SpinePathConstraintData));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
return gd_b; return gd_b;
} }
Array SpineSkeletonDataResource::get_bones(){ Array SpineSkeletonDataResource::get_bones() {
auto bs = skeleton_data->getBones(); auto bs = skeleton_data->getBones();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
if(bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL); if (bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL);
else { else {
Ref<SpineBoneData> gd_b(memnew(SpineBoneData)); Ref<SpineBoneData> gd_b(memnew(SpineBoneData));
gd_b->set_spine_object(bs[i]); gd_b->set_spine_object(bs[i]);
@ -284,12 +286,12 @@ Array SpineSkeletonDataResource::get_bones(){
} }
return gd_bs; return gd_bs;
} }
Array SpineSkeletonDataResource::get_slots(){ Array SpineSkeletonDataResource::get_slots() {
auto bs = skeleton_data->getSlots(); auto bs = skeleton_data->getSlots();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
if(bs[i] == NULL) gd_bs[i] = Ref<SpineSlotData>(NULL); if (bs[i] == NULL) gd_bs[i] = Ref<SpineSlotData>(NULL);
else { else {
Ref<SpineSlotData> gd_b(memnew(SpineSlotData)); Ref<SpineSlotData> gd_b(memnew(SpineSlotData));
gd_b->set_spine_object(bs[i]); gd_b->set_spine_object(bs[i]);
@ -298,12 +300,12 @@ Array SpineSkeletonDataResource::get_slots(){
} }
return gd_bs; return gd_bs;
} }
Array SpineSkeletonDataResource::get_skins() const{ Array SpineSkeletonDataResource::get_skins() const {
auto bs = skeleton_data->getSkins(); auto bs = skeleton_data->getSkins();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
if(bs[i] == NULL) gd_bs[i] = Ref<SpineSkin>(NULL); if (bs[i] == NULL) gd_bs[i] = Ref<SpineSkin>(NULL);
else { else {
Ref<SpineSkin> gd_b(memnew(SpineSkin)); Ref<SpineSkin> gd_b(memnew(SpineSkin));
gd_b->set_spine_object(bs[i]); gd_b->set_spine_object(bs[i]);
@ -313,26 +315,26 @@ Array SpineSkeletonDataResource::get_skins() const{
return gd_bs; return gd_bs;
} }
Ref<SpineSkin> SpineSkeletonDataResource::get_default_skin(){ Ref<SpineSkin> SpineSkeletonDataResource::get_default_skin() {
auto b = skeleton_data->getDefaultSkin(); auto b = skeleton_data->getDefaultSkin();
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineSkin> gd_b(memnew(SpineSkin)); Ref<SpineSkin> gd_b(memnew(SpineSkin));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
return gd_b; return gd_b;
} }
void SpineSkeletonDataResource::set_default_skin(Ref<SpineSkin> v){ void SpineSkeletonDataResource::set_default_skin(Ref<SpineSkin> v) {
if(v.is_valid()){ if (v.is_valid()) {
skeleton_data->setDefaultSkin(v->get_spine_object()); skeleton_data->setDefaultSkin(v->get_spine_object());
} else } else
skeleton_data->setDefaultSkin(NULL); skeleton_data->setDefaultSkin(NULL);
} }
Array SpineSkeletonDataResource::get_events(){ Array SpineSkeletonDataResource::get_events() {
auto bs = skeleton_data->getEvents(); auto bs = skeleton_data->getEvents();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
if(bs[i] == NULL) gd_bs[i] = Ref<SpineEventData>(NULL); if (bs[i] == NULL) gd_bs[i] = Ref<SpineEventData>(NULL);
else { else {
Ref<SpineEventData> gd_b(memnew(SpineEventData)); Ref<SpineEventData> gd_b(memnew(SpineEventData));
gd_b->set_spine_object(bs[i]); gd_b->set_spine_object(bs[i]);
@ -341,12 +343,12 @@ Array SpineSkeletonDataResource::get_events(){
} }
return gd_bs; return gd_bs;
} }
Array SpineSkeletonDataResource::get_animations(){ Array SpineSkeletonDataResource::get_animations() {
auto bs = skeleton_data->getAnimations(); auto bs = skeleton_data->getAnimations();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
if(bs[i] == NULL) gd_bs[i] = Ref<SpineAnimation>(NULL); if (bs[i] == NULL) gd_bs[i] = Ref<SpineAnimation>(NULL);
else { else {
Ref<SpineAnimation> gd_b(memnew(SpineAnimation)); Ref<SpineAnimation> gd_b(memnew(SpineAnimation));
gd_b->set_spine_object(bs[i]); gd_b->set_spine_object(bs[i]);
@ -355,12 +357,12 @@ Array SpineSkeletonDataResource::get_animations(){
} }
return gd_bs; return gd_bs;
} }
Array SpineSkeletonDataResource::get_ik_constraints(){ Array SpineSkeletonDataResource::get_ik_constraints() {
auto bs = skeleton_data->getIkConstraints(); auto bs = skeleton_data->getIkConstraints();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
if(bs[i] == NULL) gd_bs[i] = Ref<SpineIkConstraintData>(NULL); if (bs[i] == NULL) gd_bs[i] = Ref<SpineIkConstraintData>(NULL);
else { else {
Ref<SpineIkConstraintData> gd_b(memnew(SpineIkConstraintData)); Ref<SpineIkConstraintData> gd_b(memnew(SpineIkConstraintData));
gd_b->set_spine_object(bs[i]); gd_b->set_spine_object(bs[i]);
@ -369,12 +371,12 @@ Array SpineSkeletonDataResource::get_ik_constraints(){
} }
return gd_bs; return gd_bs;
} }
Array SpineSkeletonDataResource::get_transform_constraints(){ Array SpineSkeletonDataResource::get_transform_constraints() {
auto bs = skeleton_data->getTransformConstraints(); auto bs = skeleton_data->getTransformConstraints();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
if(bs[i] == NULL) gd_bs[i] = Ref<SpineTransformConstraintData>(NULL); if (bs[i] == NULL) gd_bs[i] = Ref<SpineTransformConstraintData>(NULL);
else { else {
Ref<SpineTransformConstraintData> gd_b(memnew(SpineTransformConstraintData)); Ref<SpineTransformConstraintData> gd_b(memnew(SpineTransformConstraintData));
gd_b->set_spine_object(bs[i]); gd_b->set_spine_object(bs[i]);
@ -383,12 +385,12 @@ Array SpineSkeletonDataResource::get_transform_constraints(){
} }
return gd_bs; return gd_bs;
} }
Array SpineSkeletonDataResource::get_path_constraints(){ Array SpineSkeletonDataResource::get_path_constraints() {
auto bs = skeleton_data->getPathConstraints(); auto bs = skeleton_data->getPathConstraints();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
if(bs[i] == NULL) gd_bs[i] = Ref<SpinePathConstraintData>(NULL); if (bs[i] == NULL) gd_bs[i] = Ref<SpinePathConstraintData>(NULL);
else { else {
Ref<SpinePathConstraintData> gd_b(memnew(SpinePathConstraintData)); Ref<SpinePathConstraintData> gd_b(memnew(SpinePathConstraintData));
gd_b->set_spine_object(bs[i]); gd_b->set_spine_object(bs[i]);
@ -402,53 +404,53 @@ Array SpineSkeletonDataResource::get_path_constraints(){
#undef CHECK_X #undef CHECK_X
//External feature functions //External feature functions
void SpineSkeletonDataResource::get_animation_names(Vector<String> &res) const{ void SpineSkeletonDataResource::get_animation_names(Vector<String> &res) const {
res.clear(); res.clear();
if(!is_skeleton_data_loaded()){ if (!is_skeleton_data_loaded()) {
return; return;
} }
auto as = skeleton_data->getAnimations(); auto as = skeleton_data->getAnimations();
for(size_t i=0; i<as.size(); ++i){ for (size_t i = 0; i < as.size(); ++i) {
auto a = as[i]; auto a = as[i];
if(a){ if (a) {
res.push_back(a->getName().buffer()); res.push_back(a->getName().buffer());
}else{ } else {
res.push_back(""); res.push_back("");
} }
} }
} }
void SpineSkeletonDataResource::get_skin_names(Vector<String> &res) const{ void SpineSkeletonDataResource::get_skin_names(Vector<String> &res) const {
res.clear(); res.clear();
if(!is_skeleton_data_loaded()){ if (!is_skeleton_data_loaded()) {
return; return;
} }
auto as = get_skins(); auto as = get_skins();
res.resize(as.size()); res.resize(as.size());
for(size_t i=0; i<as.size(); ++i){ for (size_t i = 0; i < as.size(); ++i) {
auto a = Ref<SpineSkin>(as[i]); auto a = Ref<SpineSkin>(as[i]);
if(a.is_valid()){ if (a.is_valid()) {
res.push_back(a->get_skin_name()); res.push_back(a->get_skin_name());
}else{ } else {
res.push_back(""); res.push_back("");
} }
} }
} }
void SpineSkeletonDataResource::_get_property_list(List<PropertyInfo> *p_list) const{ void SpineSkeletonDataResource::_get_property_list(List<PropertyInfo> *p_list) const {
PropertyInfo p; PropertyInfo p;
Vector<String> res; Vector<String> res;
p.name = "animations"; p.name = "animations";
p.type = Variant::STRING; p.type = Variant::STRING;
get_animation_names(res); get_animation_names(res);
p.hint_string = String(",").join(res); p.hint_string = String(",").join(res);
p.hint = PROPERTY_HINT_ENUM; p.hint = PROPERTY_HINT_ENUM;
p_list->push_back(p); p_list->push_back(p);
p.name = "skins"; p.name = "skins";
p.type = Variant::STRING; p.type = Variant::STRING;
get_skin_names(res); get_skin_names(res);
p.hint_string = String(",").join(res); p.hint_string = String(",").join(res);
p.hint = PROPERTY_HINT_ENUM; p.hint = PROPERTY_HINT_ENUM;
p_list->push_back(p); p_list->push_back(p);
} }

View File

@ -45,7 +45,7 @@
#include "SpinePathConstraintData.h" #include "SpinePathConstraintData.h"
#include "SpineEventData.h" #include "SpineEventData.h"
class SpineSkeletonDataResource : public Resource{ class SpineSkeletonDataResource : public Resource {
GDCLASS(SpineSkeletonDataResource, Resource); GDCLASS(SpineSkeletonDataResource, Resource);
protected: protected:
@ -60,14 +60,14 @@ private:
spine::SkeletonData *skeleton_data; spine::SkeletonData *skeleton_data;
void update_skeleton_data(); void update_skeleton_data();
public:
inline void set_spine_object(spine::SkeletonData *s){ public:
inline void set_spine_object(spine::SkeletonData *s) {
skeleton_data = s; skeleton_data = s;
if(s) if (s)
spine_object = true; spine_object = true;
} }
inline spine::SkeletonData *get_spine_object(){ inline spine::SkeletonData *get_spine_object() {
return skeleton_data; return skeleton_data;
} }
@ -76,7 +76,7 @@ public:
SpineSkeletonDataResource(); SpineSkeletonDataResource();
virtual ~SpineSkeletonDataResource(); virtual ~SpineSkeletonDataResource();
void _get_property_list(List<PropertyInfo> *p_list) const; void _get_property_list(List<PropertyInfo> *p_list) const;
void set_atlas_res(const Ref<SpineAtlasResource> &a); void set_atlas_res(const Ref<SpineAtlasResource> &a);
Ref<SpineAtlasResource> get_atlas_res(); Ref<SpineAtlasResource> get_atlas_res();
@ -84,17 +84,17 @@ public:
void set_skeleton_json_res(const Ref<SpineSkeletonJsonDataResource> &s); void set_skeleton_json_res(const Ref<SpineSkeletonJsonDataResource> &s);
Ref<SpineSkeletonJsonDataResource> get_skeleton_json_res(); Ref<SpineSkeletonJsonDataResource> get_skeleton_json_res();
inline spine::SkeletonData *get_skeleton_data(){return skeleton_data;} inline spine::SkeletonData *get_skeleton_data() { return skeleton_data; }
bool is_skeleton_data_loaded() const; bool is_skeleton_data_loaded() const;
void get_animation_names(Vector<String> &l) const; void get_animation_names(Vector<String> &l) const;
void get_skin_names(Vector<String> &l) const; void get_skin_names(Vector<String> &l) const;
// spine api // spine api
Ref<SpineBoneData> find_bone(const String &bone_name); Ref<SpineBoneData> find_bone(const String &bone_name);
Ref<SpineSlotData> find_slot(const String &slot_name); Ref<SpineSlotData> find_slot(const String &slot_name);
Ref<SpineSkin> find_skin(const String &skin_name); Ref<SpineSkin> find_skin(const String &skin_name);
@ -104,7 +104,7 @@ public:
Ref<SpineIkConstraintData> find_ik_constraint(const String &constraint_name); Ref<SpineIkConstraintData> find_ik_constraint(const String &constraint_name);
Ref<SpineTransformConstraintData> find_transform_constraint(const String &constraint_name); Ref<SpineTransformConstraintData> find_transform_constraint(const String &constraint_name);
Ref<SpinePathConstraintData> find_path_constraint(const String &constraint_name); Ref<SpinePathConstraintData> find_path_constraint(const String &constraint_name);
Array get_bones(); Array get_bones();
Array get_slots(); Array get_slots();
@ -137,4 +137,4 @@ public:
void set_fps(float v); void set_fps(float v);
}; };
#endif //GODOT_SPINESKELETONDATARESOURCE_H #endif//GODOT_SPINESKELETONDATARESOURCE_H

View File

@ -34,22 +34,22 @@ void SpineSkeletonJsonDataResource::_bind_methods() {
} }
Error SpineSkeletonJsonDataResource::load_from_file(const String &p_path) { Error SpineSkeletonJsonDataResource::load_from_file(const String &p_path) {
Error err; Error err;
json_string = FileAccess::get_file_as_string(p_path, &err); json_string = FileAccess::get_file_as_string(p_path, &err);
return err; return err;
} }
Error SpineSkeletonJsonDataResource::save_to_file(const String &p_path) { Error SpineSkeletonJsonDataResource::save_to_file(const String &p_path) {
Error err; Error err;
FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err);
if (err != OK) { if (err != OK) {
if (file) file->close(); if (file) file->close();
return err; return err;
} }
file->store_string(json_string); file->store_string(json_string);
file->close(); file->close();
return OK; return OK;
} }

View File

@ -32,18 +32,19 @@
#include "core/variant_parser.h" #include "core/variant_parser.h"
class SpineSkeletonJsonDataResource : public Resource{ class SpineSkeletonJsonDataResource : public Resource {
GDCLASS(SpineSkeletonJsonDataResource, Resource); GDCLASS(SpineSkeletonJsonDataResource, Resource);
protected: protected:
static void _bind_methods(); static void _bind_methods();
String json_string; String json_string;
public:
inline const String &get_json_string() {return json_string;}
Error load_from_file(const String &p_path); public:
Error save_to_file(const String &p_path); inline const String &get_json_string() { return json_string; }
Error load_from_file(const String &p_path);
Error save_to_file(const String &p_path);
}; };
#endif //GODOT_SPINESKELETONJSONDATARESOURCE_H #endif//GODOT_SPINESKELETONJSONDATARESOURCE_H

View File

@ -47,53 +47,53 @@ void SpineSkin::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_all_constraint_data"), &SpineSkin::get_constraint); ClassDB::bind_method(D_METHOD("get_all_constraint_data"), &SpineSkin::get_constraint);
} }
SpineSkin::SpineSkin():skin(NULL) {} SpineSkin::SpineSkin() : skin(NULL) {}
SpineSkin::~SpineSkin() {} SpineSkin::~SpineSkin() {}
#define S_T(x) (spine::String(x.utf8())) #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)); skin = new spine::Skin(S_T(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()){ if (!attachment.is_valid()) {
ERR_PRINT("attachment is invalid!"); ERR_PRINT("attachment is invalid!");
return; return;
} }
skin->setAttachment(slot_index, S_T(name), attachment->get_spine_object()); 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)); auto a = skin->getAttachment(slot_index, S_T(name));
if(a == NULL) return NULL; if (a == NULL) return NULL;
Ref<SpineAttachment> gd_attachment(memnew(SpineAttachment)); Ref<SpineAttachment> gd_attachment(memnew(SpineAttachment));
gd_attachment->set_spine_object(a); gd_attachment->set_spine_object(a);
return gd_attachment; return gd_attachment;
} }
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)); skin->removeAttachment(slot_index, S_T(name));
} }
Array SpineSkin::find_names_for_slot(uint64_t slot_index){ Array SpineSkin::find_names_for_slot(uint64_t slot_index) {
spine::Vector<spine::String> names; spine::Vector<spine::String> names;
skin->findNamesForSlot(slot_index, names); skin->findNamesForSlot(slot_index, names);
Array gd_names; Array gd_names;
gd_names.resize(names.size()); gd_names.resize(names.size());
for(size_t i=0; i < names.size(); ++i){ for (size_t i = 0; i < names.size(); ++i) {
gd_names[i] = names[i].buffer(); gd_names[i] = names[i].buffer();
} }
return gd_names; return gd_names;
} }
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; spine::Vector<spine::Attachment *> as;
skin->findAttachmentsForSlot(slot_index, as); skin->findAttachmentsForSlot(slot_index, as);
Array gd_as; Array gd_as;
gd_as.resize(as.size()); gd_as.resize(as.size());
for(size_t i=0; i < as.size(); ++i){ for (size_t i = 0; i < as.size(); ++i) {
if(as[i] == NULL) gd_as[i] = Ref<SpineAttachment>(NULL); if (as[i] == NULL) gd_as[i] = Ref<SpineAttachment>(NULL);
else { else {
Ref<SpineAttachment> gd_a(memnew(SpineAttachment)); Ref<SpineAttachment> gd_a(memnew(SpineAttachment));
gd_a->set_spine_object(as[i]); gd_a->set_spine_object(as[i]);
@ -103,41 +103,40 @@ Array SpineSkin::find_attachments_for_slot(uint64_t slot_index){
return gd_as; return gd_as;
} }
String SpineSkin::get_skin_name(){ String SpineSkin::get_skin_name() {
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()){ if (other.is_valid() && other->get_spine_object()) {
skin->addSkin(other->get_spine_object()); skin->addSkin(other->get_spine_object());
} else{ } else {
ERR_PRINT("other is NULL!"); ERR_PRINT("other is NULL!");
} }
} }
void SpineSkin::copy_skin(Ref<SpineSkin> other){ void SpineSkin::copy_skin(Ref<SpineSkin> other) {
if(other.is_valid() && other->get_spine_object()){ if (other.is_valid() && other->get_spine_object()) {
skin->copySkin(other->get_spine_object()); skin->copySkin(other->get_spine_object());
} else{ } else {
ERR_PRINT("other is NULL!"); ERR_PRINT("other is NULL!");
} }
} }
Ref<SpineSkinAttachmentMapEntries> SpineSkin::get_attachments(){ Ref<SpineSkinAttachmentMapEntries> SpineSkin::get_attachments() {
auto *es = new spine::Skin::AttachmentMap::Entries(skin->getAttachments()); auto *es = new spine::Skin::AttachmentMap::Entries(skin->getAttachments());
Ref<SpineSkinAttachmentMapEntries> gd_es(memnew(SpineSkinAttachmentMapEntries)); Ref<SpineSkinAttachmentMapEntries> gd_es(memnew(SpineSkinAttachmentMapEntries));
gd_es->set_spine_object(es); gd_es->set_spine_object(es);
return gd_es; return gd_es;
} }
Array SpineSkin::get_bones(){ Array SpineSkin::get_bones() {
auto bs = skin->getBones(); auto bs = skin->getBones();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
if(bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL); if (bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL);
else{ else {
Ref<SpineBoneData> gd_b(memnew(SpineBoneData)); Ref<SpineBoneData> gd_b(memnew(SpineBoneData));
gd_b->set_spine_object(bs[i]); gd_b->set_spine_object(bs[i]);
gd_bs[i] = gd_b; gd_bs[i] = gd_b;
@ -146,13 +145,13 @@ Array SpineSkin::get_bones(){
return gd_bs; return gd_bs;
} }
Array SpineSkin::get_constraint(){ Array SpineSkin::get_constraint() {
auto cs = skin->getConstraints(); auto cs = skin->getConstraints();
Array gd_cs; Array gd_cs;
gd_cs.resize(cs.size()); gd_cs.resize(cs.size());
for(size_t i=0; i < cs.size(); ++i){ for (size_t i = 0; i < cs.size(); ++i) {
if(cs[i] == NULL) gd_cs[i] = Ref<SpineConstraintData>(NULL); if (cs[i] == NULL) gd_cs[i] = Ref<SpineConstraintData>(NULL);
else{ else {
Ref<SpineConstraintData> gd_c(memnew(SpineConstraintData)); Ref<SpineConstraintData> gd_c(memnew(SpineConstraintData));
gd_c->set_spine_object(cs[i]); gd_c->set_spine_object(cs[i]);
gd_cs[i] = gd_c; gd_cs[i] = gd_c;

View File

@ -50,10 +50,10 @@ public:
SpineSkin(); SpineSkin();
~SpineSkin(); ~SpineSkin();
inline void set_spine_object(spine::Skin *s){ inline void set_spine_object(spine::Skin *s) {
skin = s; skin = s;
} }
spine::Skin *get_spine_object(){ spine::Skin *get_spine_object() {
return skin; return skin;
} }
@ -82,4 +82,4 @@ public:
Array get_constraint(); Array get_constraint();
}; };
#endif //GODOT_SPINESKIN_H #endif//GODOT_SPINESKIN_H

View File

@ -38,33 +38,33 @@ void SpineSkinAttachmentMapEntry::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_attachment", "v"), &SpineSkinAttachmentMapEntry::set_attachment); ClassDB::bind_method(D_METHOD("set_attachment", "v"), &SpineSkinAttachmentMapEntry::set_attachment);
} }
SpineSkinAttachmentMapEntry::SpineSkinAttachmentMapEntry():entry(NULL) {} SpineSkinAttachmentMapEntry::SpineSkinAttachmentMapEntry() : entry(NULL) {}
SpineSkinAttachmentMapEntry::~SpineSkinAttachmentMapEntry() {} SpineSkinAttachmentMapEntry::~SpineSkinAttachmentMapEntry() {}
uint64_t SpineSkinAttachmentMapEntry::get_slot_index(){ uint64_t SpineSkinAttachmentMapEntry::get_slot_index() {
return entry->_slotIndex; return entry->_slotIndex;
} }
void SpineSkinAttachmentMapEntry::set_slot_index(uint64_t v){ void SpineSkinAttachmentMapEntry::set_slot_index(uint64_t v) {
entry->_slotIndex = v; entry->_slotIndex = v;
} }
String SpineSkinAttachmentMapEntry::get_entry_name(){ String SpineSkinAttachmentMapEntry::get_entry_name() {
return entry->_name.buffer(); return entry->_name.buffer();
} }
void SpineSkinAttachmentMapEntry::set_entry_name(const String &v){ void SpineSkinAttachmentMapEntry::set_entry_name(const String &v) {
entry->_name = spine::String(v.utf8()); entry->_name = spine::String(v.utf8());
} }
Ref<SpineAttachment> SpineSkinAttachmentMapEntry::get_attachment(){ Ref<SpineAttachment> SpineSkinAttachmentMapEntry::get_attachment() {
if(entry->_attachment == NULL) return NULL; if (entry->_attachment == NULL) return NULL;
Ref<SpineAttachment> gd_attachment(memnew(SpineAttachment)); Ref<SpineAttachment> gd_attachment(memnew(SpineAttachment));
gd_attachment->set_spine_object(entry->_attachment); gd_attachment->set_spine_object(entry->_attachment);
return gd_attachment; return gd_attachment;
} }
void SpineSkinAttachmentMapEntry::set_attachment(Ref<SpineAttachment> v){ void SpineSkinAttachmentMapEntry::set_attachment(Ref<SpineAttachment> v) {
if(v.is_valid()){ if (v.is_valid()) {
entry->_attachment = v->get_spine_object(); entry->_attachment = v->get_spine_object();
}else{ } else {
entry->_attachment = NULL; entry->_attachment = NULL;
} }
} }
@ -74,18 +74,18 @@ void SpineSkinAttachmentMapEntries::_bind_methods() {
ClassDB::bind_method(D_METHOD("next"), &SpineSkinAttachmentMapEntries::next); ClassDB::bind_method(D_METHOD("next"), &SpineSkinAttachmentMapEntries::next);
} }
SpineSkinAttachmentMapEntries::SpineSkinAttachmentMapEntries():entries(NULL) {} SpineSkinAttachmentMapEntries::SpineSkinAttachmentMapEntries() : entries(NULL) {}
SpineSkinAttachmentMapEntries::~SpineSkinAttachmentMapEntries() { SpineSkinAttachmentMapEntries::~SpineSkinAttachmentMapEntries() {
if(entries){ if (entries) {
delete entries; delete entries;
return; return;
} }
} }
bool SpineSkinAttachmentMapEntries::has_next(){ bool SpineSkinAttachmentMapEntries::has_next() {
return entries->hasNext(); return entries->hasNext();
} }
Ref<SpineSkinAttachmentMapEntry> SpineSkinAttachmentMapEntries::next(){ Ref<SpineSkinAttachmentMapEntry> SpineSkinAttachmentMapEntries::next() {
auto &e = entries->next(); auto &e = entries->next();
Ref<SpineSkinAttachmentMapEntry> gd_entry(memnew(SpineSkinAttachmentMapEntry)); Ref<SpineSkinAttachmentMapEntry> gd_entry(memnew(SpineSkinAttachmentMapEntry));
gd_entry->set_spine_object(&e); gd_entry->set_spine_object(&e);

View File

@ -49,10 +49,10 @@ public:
SpineSkinAttachmentMapEntry(); SpineSkinAttachmentMapEntry();
~SpineSkinAttachmentMapEntry(); ~SpineSkinAttachmentMapEntry();
inline void set_spine_object(spine::Skin::AttachmentMap::Entry *e){ inline void set_spine_object(spine::Skin::AttachmentMap::Entry *e) {
entry = e; entry = e;
} }
inline spine::Skin::AttachmentMap::Entry *get_spine_object(){ inline spine::Skin::AttachmentMap::Entry *get_spine_object() {
return entry; return entry;
} }
@ -79,10 +79,10 @@ public:
SpineSkinAttachmentMapEntries(); SpineSkinAttachmentMapEntries();
~SpineSkinAttachmentMapEntries(); ~SpineSkinAttachmentMapEntries();
inline void set_spine_object(spine::Skin::AttachmentMap::Entries *e){ inline void set_spine_object(spine::Skin::AttachmentMap::Entries *e) {
entries = e; entries = e;
} }
inline spine::Skin::AttachmentMap::Entries *get_spine_object(){ inline spine::Skin::AttachmentMap::Entries *get_spine_object() {
return entries; return entries;
} }
@ -90,4 +90,4 @@ public:
Ref<SpineSkinAttachmentMapEntry> next(); Ref<SpineSkinAttachmentMapEntry> next();
}; };
#endif //GODOT_SPINESKINATTACHMENTMAPENTRIES_H #endif//GODOT_SPINESKINATTACHMENTMAPENTRIES_H

View File

@ -51,98 +51,98 @@ void SpineSlot::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_deform", "v"), &SpineSlot::set_deform); ClassDB::bind_method(D_METHOD("set_deform", "v"), &SpineSlot::set_deform);
} }
SpineSlot::SpineSlot():slot(NULL) {} SpineSlot::SpineSlot() : slot(NULL) {}
SpineSlot::~SpineSlot() {} SpineSlot::~SpineSlot() {}
void SpineSlot::set_to_setup_pos(){ void SpineSlot::set_to_setup_pos() {
slot->setToSetupPose(); slot->setToSetupPose();
} }
Ref<SpineSlotData> SpineSlot::get_data(){ Ref<SpineSlotData> SpineSlot::get_data() {
auto &sd = slot->getData(); auto &sd = slot->getData();
Ref<SpineSlotData> gd_sd(memnew(SpineSlotData)); Ref<SpineSlotData> gd_sd(memnew(SpineSlotData));
gd_sd->set_spine_object(&sd); gd_sd->set_spine_object(&sd);
return gd_sd; return gd_sd;
} }
Ref<SpineBone> SpineSlot::get_bone(){ Ref<SpineBone> SpineSlot::get_bone() {
auto &b = slot->getBone(); auto &b = slot->getBone();
Ref<SpineBone> gd_b(memnew(SpineBone)); Ref<SpineBone> gd_b(memnew(SpineBone));
gd_b->set_spine_object(&b); gd_b->set_spine_object(&b);
return gd_b; return gd_b;
} }
Ref<SpineSkeleton> SpineSlot::get_skeleton(){ Ref<SpineSkeleton> SpineSlot::get_skeleton() {
auto &s = slot->getSkeleton(); auto &s = slot->getSkeleton();
Ref<SpineSkeleton> gd_s(memnew(SpineSkeleton)); Ref<SpineSkeleton> gd_s(memnew(SpineSkeleton));
gd_s->set_spine_object(&s); gd_s->set_spine_object(&s);
return gd_s; return gd_s;
} }
Color SpineSlot::get_color(){ Color SpineSlot::get_color() {
auto &c = slot->getColor(); auto &c = slot->getColor();
return Color(c.r, c.g, c.b, c.a); return Color(c.r, c.g, c.b, c.a);
} }
void SpineSlot::set_color(Color v){ void SpineSlot::set_color(Color v) {
auto &c = slot->getColor(); auto &c = slot->getColor();
c.set(v.r, v.g, v.b, v.a); c.set(v.r, v.g, v.b, v.a);
} }
Color SpineSlot::get_dark_color(){ Color SpineSlot::get_dark_color() {
auto &c = slot->getDarkColor(); auto &c = slot->getDarkColor();
return Color(c.r, c.g, c.b, c.a); return Color(c.r, c.g, c.b, c.a);
} }
void SpineSlot::set_dark_color(Color v){ void SpineSlot::set_dark_color(Color v) {
auto &c = slot->getDarkColor(); auto &c = slot->getDarkColor();
c.set(v.r, v.g, v.b, v.a); c.set(v.r, v.g, v.b, v.a);
} }
bool SpineSlot::has_dark_color(){ bool SpineSlot::has_dark_color() {
return slot->hasDarkColor(); return slot->hasDarkColor();
} }
Ref<SpineAttachment> SpineSlot::get_attachment(){ Ref<SpineAttachment> SpineSlot::get_attachment() {
auto a = slot->getAttachment(); auto a = slot->getAttachment();
if(a == NULL) return NULL; if (a == NULL) return NULL;
Ref<SpineAttachment> gd_a(memnew(SpineAttachment)); Ref<SpineAttachment> gd_a(memnew(SpineAttachment));
gd_a->set_spine_object(a); gd_a->set_spine_object(a);
return gd_a; return gd_a;
} }
void SpineSlot::set_attachment(Ref<SpineAttachment> v){ void SpineSlot::set_attachment(Ref<SpineAttachment> v) {
if(v.is_valid()){ if (v.is_valid()) {
slot->setAttachment(v->get_spine_object()); slot->setAttachment(v->get_spine_object());
}else{ } else {
slot->setAttachment(NULL); slot->setAttachment(NULL);
} }
} }
int SpineSlot::get_attachment_state(){ int SpineSlot::get_attachment_state() {
return slot->getAttachmentState(); return slot->getAttachmentState();
} }
void SpineSlot::set_attachment_state(int v){ void SpineSlot::set_attachment_state(int v) {
slot->setAttachmentState(v); slot->setAttachmentState(v);
} }
float SpineSlot::get_attachment_time(){ float SpineSlot::get_attachment_time() {
return slot->getAttachmentTime(); return slot->getAttachmentTime();
} }
void SpineSlot::set_attachment_time(float v){ void SpineSlot::set_attachment_time(float v) {
slot->setAttachmentTime(v); slot->setAttachmentTime(v);
} }
Array SpineSlot::get_deform(){ Array SpineSlot::get_deform() {
auto &ds = slot->getDeform(); auto &ds = slot->getDeform();
Array gd_ds; Array gd_ds;
gd_ds.resize(ds.size()); gd_ds.resize(ds.size());
for(size_t i=0; i < ds.size(); ++i){ for (size_t i = 0; i < ds.size(); ++i) {
gd_ds[i] = ds[i]; gd_ds[i] = ds[i];
} }
return gd_ds; return gd_ds;
} }
void SpineSlot::set_deform(Array gd_ds){ void SpineSlot::set_deform(Array gd_ds) {
auto &ds = slot->getDeform(); auto &ds = slot->getDeform();
ds.setSize(gd_ds.size(), 0); ds.setSize(gd_ds.size(), 0);
for(size_t i=0; i < gd_ds.size(); ++i){ for (size_t i = 0; i < gd_ds.size(); ++i) {
ds[i] = gd_ds[i]; ds[i] = gd_ds[i];
} }
} }

View File

@ -41,7 +41,7 @@ class SpineSkeleton;
class SpineBone; class SpineBone;
class SpineSlot : public Reference{ class SpineSlot : public Reference {
GDCLASS(SpineSlot, Reference); GDCLASS(SpineSlot, Reference);
protected: protected:
@ -54,10 +54,10 @@ public:
SpineSlot(); SpineSlot();
~SpineSlot(); ~SpineSlot();
inline void set_spine_object(spine::Slot *s){ inline void set_spine_object(spine::Slot *s) {
slot = s; slot = s;
} }
inline spine::Slot *get_spine_object(){ inline spine::Slot *get_spine_object() {
return slot; return slot;
} }
@ -90,4 +90,4 @@ public:
void set_deform(Array v); void set_deform(Array v);
}; };
#endif //GODOT_SPINESLOT_H #endif//GODOT_SPINESLOT_H

View File

@ -51,62 +51,62 @@ void SpineSlotData::_bind_methods() {
BIND_ENUM_CONSTANT(BLENDMODE_SCREEN); BIND_ENUM_CONSTANT(BLENDMODE_SCREEN);
} }
SpineSlotData::SpineSlotData():slot_data(NULL) {} SpineSlotData::SpineSlotData() : slot_data(NULL) {}
SpineSlotData::~SpineSlotData() {} SpineSlotData::~SpineSlotData() {}
#define S_T(x) (spine::String(x.utf8())) #define S_T(x) (spine::String(x.utf8()))
int SpineSlotData::get_index(){ int SpineSlotData::get_index() {
return slot_data->getIndex(); return slot_data->getIndex();
} }
String SpineSlotData::get_slot_name(){ String SpineSlotData::get_slot_name() {
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(); auto &bd = slot_data->getBoneData();
Ref<SpineBoneData> gd_bone_data(memnew(SpineBoneData)); Ref<SpineBoneData> gd_bone_data(memnew(SpineBoneData));
gd_bone_data->set_spine_object(&bd); gd_bone_data->set_spine_object(&bd);
return gd_bone_data; return gd_bone_data;
} }
Color SpineSlotData::get_color(){ Color SpineSlotData::get_color() {
auto &c = slot_data->getColor(); auto &c = slot_data->getColor();
return Color(c.r, c.g, c.b, c.a); return Color(c.r, c.g, c.b, c.a);
} }
void SpineSlotData::set_color(Color v){ void SpineSlotData::set_color(Color v) {
auto &c = slot_data->getColor(); auto &c = slot_data->getColor();
c.set(v.r, v.g, v.b, v.a); c.set(v.r, v.g, v.b, v.a);
} }
Color SpineSlotData::get_dark_color(){ Color SpineSlotData::get_dark_color() {
auto &c = slot_data->getDarkColor(); auto &c = slot_data->getDarkColor();
return Color(c.r, c.g, c.b, c.a); return Color(c.r, c.g, c.b, c.a);
} }
void SpineSlotData::set_dark_color(Color v){ void SpineSlotData::set_dark_color(Color v) {
auto &c = slot_data->getDarkColor(); auto &c = slot_data->getDarkColor();
c.set(v.r, v.g, v.b, v.a); c.set(v.r, v.g, v.b, v.a);
} }
bool SpineSlotData::has_dark_color(){ bool SpineSlotData::has_dark_color() {
return slot_data->hasDarkColor(); return slot_data->hasDarkColor();
} }
void SpineSlotData::set_has_dark_color(bool v){ void SpineSlotData::set_has_dark_color(bool v) {
slot_data->setHasDarkColor(v); slot_data->setHasDarkColor(v);
} }
String SpineSlotData::get_attachment_name(){ String SpineSlotData::get_attachment_name() {
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)); slot_data->setAttachmentName(S_T(v));
} }
SpineSlotData::BlendMode SpineSlotData::get_blend_mode(){ SpineSlotData::BlendMode SpineSlotData::get_blend_mode() {
auto bm = (int) slot_data->getBlendMode(); auto bm = (int) slot_data->getBlendMode();
return (BlendMode) bm; return (BlendMode) bm;
} }
void SpineSlotData::set_blend_mode(BlendMode v){ void SpineSlotData::set_blend_mode(BlendMode v) {
auto bm = (int) v; auto bm = (int) v;
slot_data->setBlendMode((spine::BlendMode) bm); slot_data->setBlendMode((spine::BlendMode) bm);
} }

View File

@ -48,10 +48,10 @@ public:
SpineSlotData(); SpineSlotData();
~SpineSlotData(); ~SpineSlotData();
inline void set_spine_object(spine::SlotData *s){ inline void set_spine_object(spine::SlotData *s) {
slot_data = s; slot_data = s;
} }
inline spine::SlotData *get_spine_object(){ inline spine::SlotData *get_spine_object() {
return slot_data; return slot_data;
} }
@ -85,4 +85,4 @@ public:
}; };
VARIANT_ENUM_CAST(SpineSlotData::BlendMode); VARIANT_ENUM_CAST(SpineSlotData::BlendMode);
#endif //GODOT_SPINESLOTDATA_H #endif//GODOT_SPINESLOTDATA_H

File diff suppressed because it is too large Load Diff

View File

@ -41,31 +41,33 @@
#include "PackedSpineSkinResource.h" #include "PackedSpineSkinResource.h"
class SpineSprite : public Node2D, public spine::AnimationStateListenerObject { class SpineSprite : public Node2D, public spine::AnimationStateListenerObject {
GDCLASS(SpineSprite, Node2D); GDCLASS(SpineSprite, Node2D);
protected: protected:
static void _bind_methods(); static void _bind_methods();
void _notification(int p_what); void _notification(int p_what);
void _get_property_list(List<PropertyInfo> *p_list) const; void _get_property_list(List<PropertyInfo> *p_list) const;
bool _get(const StringName &p_property, Variant &r_value) const; bool _get(const StringName &p_property, Variant &r_value) const;
bool _set(const StringName &p_property, const Variant &p_value); bool _set(const StringName &p_property, const Variant &p_value);
void _validate_and_play_current_animations();
void _validate_and_play_current_animations();
public: public:
enum ProcessMode { enum ProcessMode {
ProcessMode_Process, ProcessMode_Process,
ProcessMode_Physics, ProcessMode_Physics,
ProcessMode_Manual ProcessMode_Manual
}; };
private:
Ref<SpineAnimationStateDataResource> animation_state_data_res; private:
Ref<SpineAnimationStateDataResource> animation_state_data_res;
Ref<SpineSkeleton> skeleton; Ref<SpineSkeleton> skeleton;
Ref<SpineAnimationState> animation_state; Ref<SpineAnimationState> animation_state;
Vector<SpineSpriteMeshInstance2D*> mesh_instances; Vector<SpineSpriteMeshInstance2D *> mesh_instances;
Array current_animations; Array current_animations;
int select_track_id; int select_track_id;
@ -75,7 +77,7 @@ private:
bool overlap; bool overlap;
Ref<PackedSpineSkinResource> skin; Ref<PackedSpineSkinResource> skin;
ProcessMode process_mode; ProcessMode process_mode;
spine::SkeletonClipping *skeleton_clipper; spine::SkeletonClipping *skeleton_clipper;
@ -83,8 +85,8 @@ public:
SpineSprite(); SpineSprite();
~SpineSprite(); ~SpineSprite();
void set_animation_state_data_res(const Ref<SpineAnimationStateDataResource> &a); void set_animation_state_data_res(const Ref<SpineAnimationStateDataResource> &a);
Ref<SpineAnimationStateDataResource> get_animation_state_data_res(); Ref<SpineAnimationStateDataResource> get_animation_state_data_res();
Ref<SpineSkeleton> get_skeleton(); Ref<SpineSkeleton> get_skeleton();
Ref<SpineAnimationState> get_animation_state(); Ref<SpineAnimationState> get_animation_state();
@ -100,7 +102,7 @@ public:
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);
virtual void callback(spine::AnimationState* state, spine::EventType type, spine::TrackEntry* entry, spine::Event* event); virtual void callback(spine::AnimationState *state, spine::EventType type, spine::TrackEntry *entry, spine::Event *event);
void _on_animation_data_created(); void _on_animation_data_created();
void _on_animation_data_changed(); void _on_animation_data_changed();
@ -150,13 +152,13 @@ public:
Ref<SpineSkin> gen_spine_skin_from_packed_resource(Ref<PackedSpineSkinResource> res); Ref<SpineSkin> gen_spine_skin_from_packed_resource(Ref<PackedSpineSkinResource> res);
// current animation count // current animation count
int64_t get_current_animation_count() const; int64_t get_current_animation_count() const;
void set_current_animation_count(int64_t v); void set_current_animation_count(int64_t v);
ProcessMode get_process_mode(); ProcessMode get_process_mode();
void set_process_mode(ProcessMode v); void set_process_mode(ProcessMode v);
}; };
VARIANT_ENUM_CAST(SpineSprite::ProcessMode); VARIANT_ENUM_CAST(SpineSprite::ProcessMode);
#endif //GODOT_SPINESPRITE_H #endif//GODOT_SPINESPRITE_H

View File

@ -34,316 +34,317 @@
#include "SpineSprite.h" #include "SpineSprite.h"
void SpineSpriteAnimateDialog::_bind_methods() { void SpineSpriteAnimateDialog::_bind_methods() {
ClassDB::bind_method(D_METHOD("_on_animate_button_pressed"), &SpineSpriteAnimateDialog::_on_animate_button_pressed); ClassDB::bind_method(D_METHOD("_on_animate_button_pressed"), &SpineSpriteAnimateDialog::_on_animate_button_pressed);
ClassDB::bind_method(D_METHOD("_on_scene_tree_selected"), &SpineSpriteAnimateDialog::_on_scene_tree_selected); ClassDB::bind_method(D_METHOD("_on_scene_tree_selected"), &SpineSpriteAnimateDialog::_on_scene_tree_selected);
ClassDB::bind_method(D_METHOD("_on_scene_tree_hide"), &SpineSpriteAnimateDialog::_on_scene_tree_hide); ClassDB::bind_method(D_METHOD("_on_scene_tree_hide"), &SpineSpriteAnimateDialog::_on_scene_tree_hide);
ClassDB::bind_method(D_METHOD("_on_animate_dialog_action"), &SpineSpriteAnimateDialog::_on_animate_dialog_action); ClassDB::bind_method(D_METHOD("_on_animate_dialog_action"), &SpineSpriteAnimateDialog::_on_animate_dialog_action);
} }
SpineSpriteAnimateDialog::SpineSpriteAnimateDialog() { SpineSpriteAnimateDialog::SpineSpriteAnimateDialog() {
animate_dialog = memnew(ConfirmationDialog); animate_dialog = memnew(ConfirmationDialog);
add_child(animate_dialog); add_child(animate_dialog);
animate_dialog->get_ok()->set_text("Generate"); animate_dialog->get_ok()->set_text("Generate");
animate_dialog_override_button = animate_dialog->add_button("Override", false, "override"); animate_dialog_override_button = animate_dialog->add_button("Override", false, "override");
animate_dialog_override_button->set_visible(false); animate_dialog_override_button->set_visible(false);
animate_dialog->set_title("Animations Generator"); animate_dialog->set_title("Animations Generator");
animate_dialog->set_resizable(true); animate_dialog->set_resizable(true);
animate_dialog->set_custom_minimum_size(Vector2(550, 400)); animate_dialog->set_custom_minimum_size(Vector2(550, 400));
animate_dialog->set_hide_on_ok(false); animate_dialog->set_hide_on_ok(false);
animate_dialog->connect("custom_action", this, "_on_animate_dialog_action"); animate_dialog->connect("custom_action", this, "_on_animate_dialog_action");
Vector<Variant> al; Vector<Variant> al;
al.push_back("confirmed"); al.push_back("confirmed");
animate_dialog->connect("confirmed", this, "_on_animate_dialog_action", al); animate_dialog->connect("confirmed", this, "_on_animate_dialog_action", al);
auto vb = memnew(VBoxContainer); auto vb = memnew(VBoxContainer);
animate_dialog->add_child(vb); animate_dialog->add_child(vb);
auto scroll = memnew(ScrollContainer); auto scroll = memnew(ScrollContainer);
scroll->set_h_size_flags(SIZE_EXPAND_FILL); scroll->set_h_size_flags(SIZE_EXPAND_FILL);
scroll->set_v_size_flags(SIZE_EXPAND_FILL); scroll->set_v_size_flags(SIZE_EXPAND_FILL);
// vb->add_margin_child("Animations", scroll); // vb->add_margin_child("Animations", scroll);
vb->add_child(scroll); vb->add_child(scroll);
animate_dialog_tree = memnew(Tree); animate_dialog_tree = memnew(Tree);
animate_dialog_tree->set_h_size_flags(SIZE_EXPAND_FILL); animate_dialog_tree->set_h_size_flags(SIZE_EXPAND_FILL);
animate_dialog_tree->set_v_size_flags(SIZE_EXPAND_FILL); animate_dialog_tree->set_v_size_flags(SIZE_EXPAND_FILL);
scroll->add_child(animate_dialog_tree); scroll->add_child(animate_dialog_tree);
animate_dialog_tree->set_columns(3); animate_dialog_tree->set_columns(3);
animate_dialog_tree->set_column_titles_visible(true); animate_dialog_tree->set_column_titles_visible(true);
animate_dialog_tree->set_hide_folding(true); animate_dialog_tree->set_hide_folding(true);
animate_dialog_tree->set_hide_root(true); animate_dialog_tree->set_hide_root(true);
animate_dialog_tree->set_column_title(0, TTR("Animation")); animate_dialog_tree->set_column_title(0, TTR("Animation"));
animate_dialog_tree->set_column_title(1, TTR("Loop")); animate_dialog_tree->set_column_title(1, TTR("Loop"));
animate_dialog_tree->set_column_title(2, TTR("Track ID")); animate_dialog_tree->set_column_title(2, TTR("Track ID"));
animate_dialog_tree->create_item(); animate_dialog_tree->create_item();
add_row("test1"); add_row("test1");
add_row("test12"); add_row("test12");
add_row("test13"); add_row("test13");
auto l = memnew(Label); auto l = memnew(Label);
l->set_text("W.I.P"); l->set_text("W.I.P");
vb->add_child(l); vb->add_child(l);
scene_tree_dialog = memnew(SceneTreeDialog); scene_tree_dialog = memnew(SceneTreeDialog);
scene_tree_dialog->set_title("Choose a AnimationPlayer to override, or choose none to create a new one."); scene_tree_dialog->set_title("Choose a AnimationPlayer to override, or choose none to create a new one.");
Vector<StringName> valid_types; Vector<StringName> valid_types;
valid_types.push_back("AnimationPlayer"); valid_types.push_back("AnimationPlayer");
scene_tree_dialog->get_scene_tree()->set_valid_types(valid_types); scene_tree_dialog->get_scene_tree()->set_valid_types(valid_types);
scene_tree_dialog->get_scene_tree()->set_show_enabled_subscene(true); scene_tree_dialog->get_scene_tree()->set_show_enabled_subscene(true);
scene_tree_dialog->get_ok()->hide(); scene_tree_dialog->get_ok()->hide();
add_child(scene_tree_dialog); add_child(scene_tree_dialog);
scene_tree_dialog->connect("selected", this, "_on_scene_tree_selected"); scene_tree_dialog->connect("selected", this, "_on_scene_tree_selected");
scene_tree_dialog->connect("popup_hide", this, "_on_scene_tree_hide"); scene_tree_dialog->connect("popup_hide", this, "_on_scene_tree_hide");
error_dialog = memnew(AcceptDialog); error_dialog = memnew(AcceptDialog);
add_child(error_dialog); add_child(error_dialog);
} }
SpineSpriteAnimateDialog::~SpineSpriteAnimateDialog() { SpineSpriteAnimateDialog::~SpineSpriteAnimateDialog() {
} }
void SpineSpriteAnimateDialog::set_animate_button(ToolButton *b) { void SpineSpriteAnimateDialog::set_animate_button(ToolButton *b) {
animate_button = b; animate_button = b;
animate_button->connect("pressed", this, "_on_animate_button_pressed"); animate_button->connect("pressed", this, "_on_animate_button_pressed");
} }
void SpineSpriteAnimateDialog::add_row(const String &animation, bool loop, int64_t track_id) { void SpineSpriteAnimateDialog::add_row(const String &animation, bool loop, int64_t track_id) {
auto item = animate_dialog_tree->create_item(); auto item = animate_dialog_tree->create_item();
item->set_text(0, animation); item->set_text(0, animation);
item->set_cell_mode(1, TreeItem::CELL_MODE_CHECK); item->set_cell_mode(1, TreeItem::CELL_MODE_CHECK);
item->set_checked(1, loop); item->set_checked(1, loop);
item->set_editable(1, true); item->set_editable(1, true);
item->set_cell_mode(2, TreeItem::CELL_MODE_RANGE); item->set_cell_mode(2, TreeItem::CELL_MODE_RANGE);
item->set_range(2, track_id); item->set_range(2, track_id);
item->set_editable(2, true); item->set_editable(2, true);
} }
void SpineSpriteAnimateDialog::clear_tree() { void SpineSpriteAnimateDialog::clear_tree() {
animate_dialog_tree->clear(); animate_dialog_tree->clear();
animate_dialog_tree->create_item(); animate_dialog_tree->create_item();
} }
void SpineSpriteAnimateDialog::error(const String &text, const String &title) { void SpineSpriteAnimateDialog::error(const String &text, const String &title) {
error_dialog->set_text(text); error_dialog->set_text(text);
error_dialog->set_title(title); error_dialog->set_title(title);
error_dialog->popup_centered(); error_dialog->popup_centered();
} }
#define ERROR_MSG(x) do{error(x);err=true;return;}while(false) #define ERROR_MSG(x) \
do { \
error(x); \
err = true; \
return; \
} while (false)
void SpineSpriteAnimateDialog::load_data_from_sprite(SpineSprite *sprite, bool &err) { void SpineSpriteAnimateDialog::load_data_from_sprite(SpineSprite *sprite, bool &err) {
if (sprite == nullptr) { if (sprite == nullptr) {
ERROR_MSG("The sprite is null."); ERROR_MSG("The sprite is null.");
} }
if (!sprite->get_animation_state().is_valid() || !sprite->get_skeleton().is_valid()) { if (!sprite->get_animation_state().is_valid() || !sprite->get_skeleton().is_valid()) {
ERROR_MSG("The sprite is not loaded."); ERROR_MSG("The sprite is not loaded.");
} }
clear_tree(); clear_tree();
Vector<String> animations; Vector<String> animations;
sprite->get_skeleton()->get_data()->get_animation_names(animations); sprite->get_skeleton()->get_data()->get_animation_names(animations);
for (size_t i=0; i<animations.size(); ++i) { for (size_t i = 0; i < animations.size(); ++i) {
add_row(animations[i]); add_row(animations[i]);
} }
err = false; err = false;
} }
#define MIN_TRACK_LENGTH 0.15 #define MIN_TRACK_LENGTH 0.15
void SpineSpriteAnimateDialog::gen_new_animation_player(SpineSprite *sprite, bool &err) { void SpineSpriteAnimateDialog::gen_new_animation_player(SpineSprite *sprite, bool &err) {
if (sprite == nullptr) { if (sprite == nullptr) {
ERROR_MSG("The sprite player is null."); ERROR_MSG("The sprite player is null.");
} }
if (!sprite->get_animation_state().is_valid() || !sprite->get_skeleton().is_valid()) { if (!sprite->get_animation_state().is_valid() || !sprite->get_skeleton().is_valid()) {
ERROR_MSG("The sprite is not loaded."); ERROR_MSG("The sprite is not loaded.");
} }
auto p = sprite->get_parent(); auto p = sprite->get_parent();
if (p == nullptr) { if (p == nullptr) {
p = sprite; p = sprite;
} }
auto anim_player = memnew(AnimationPlayer); auto anim_player = memnew(AnimationPlayer);
anim_player->set_name("AnimationPlayer"); anim_player->set_name("AnimationPlayer");
p->add_child(anim_player); p->add_child(anim_player);
anim_player->set_owner(sprite->get_owner()); anim_player->set_owner(sprite->get_owner());
anim_player->set_root(anim_player->get_path_to(p)); anim_player->set_root(anim_player->get_path_to(p));
gen_animations(sprite, anim_player, get_data_from_tree(), MIN_TRACK_LENGTH, err); gen_animations(sprite, anim_player, get_data_from_tree(), MIN_TRACK_LENGTH, err);
} }
Dictionary SpineSpriteAnimateDialog::get_data_from_tree() { Dictionary SpineSpriteAnimateDialog::get_data_from_tree() {
Dictionary res; Dictionary res;
if (animate_dialog_tree->get_root() == nullptr) return res; if (animate_dialog_tree->get_root() == nullptr) return res;
auto item = animate_dialog_tree->get_root()->get_children(); auto item = animate_dialog_tree->get_root()->get_children();
while (item) { while (item) {
Dictionary row; Dictionary row;
row["loop"] = item->is_checked(1); row["loop"] = item->is_checked(1);
row["track_id"] = item->get_range(2); row["track_id"] = item->get_range(2);
res[item->get_text(0)] = row; res[item->get_text(0)] = row;
item = item->get_next(); item = item->get_next();
} }
return res; return res;
} }
void SpineSpriteAnimateDialog::gen_animations(SpineSprite *sprite, AnimationPlayer *anim_player, const Dictionary &config, float min_duration, bool &err) { void SpineSpriteAnimateDialog::gen_animations(SpineSprite *sprite, AnimationPlayer *anim_player, const Dictionary &config, float min_duration, bool &err) {
if (sprite == nullptr || anim_player == nullptr) { if (sprite == nullptr || anim_player == nullptr) {
ERROR_MSG("The sprite or animation player is null."); ERROR_MSG("The sprite or animation player is null.");
} }
if (!sprite->get_animation_state().is_valid() || !sprite->get_skeleton().is_valid()) { if (!sprite->get_animation_state().is_valid() || !sprite->get_skeleton().is_valid()) {
ERROR_MSG("The sprite is not loaded."); ERROR_MSG("The sprite is not loaded.");
} }
if (anim_player->get_node_or_null(anim_player->get_root()) == nullptr) { if (anim_player->get_node_or_null(anim_player->get_root()) == nullptr) {
ERROR_MSG("The root node of animation player is null."); ERROR_MSG("The root node of animation player is null.");
} }
auto path_to_sprite = anim_player->get_node(anim_player->get_root())->get_path_to(sprite); auto path_to_sprite = anim_player->get_node(anim_player->get_root())->get_path_to(sprite);
Array animations = sprite->get_skeleton()->get_data()->get_animations(); Array animations = sprite->get_skeleton()->get_data()->get_animations();
for (size_t i=0; i<animations.size(); ++i) { for (size_t i = 0; i < animations.size(); ++i) {
auto spine_anim = (Ref<SpineAnimation>) animations[i]; auto spine_anim = (Ref<SpineAnimation>) animations[i];
Dictionary ca; Dictionary ca;
if (config.has(spine_anim->get_anim_name())) { if (config.has(spine_anim->get_anim_name())) {
ca = config[spine_anim->get_anim_name()]; ca = config[spine_anim->get_anim_name()];
} }
if (!ca.has("loop")) ca["loop"] = true; if (!ca.has("loop")) ca["loop"] = true;
if (!ca.has("track_id")) ca["track_id"] = 0; if (!ca.has("track_id")) ca["track_id"] = 0;
Array key_frame_value; Array key_frame_value;
key_frame_value.push_back(gen_current_animation_data(spine_anim->get_anim_name(), ca["track_id"], ca["loop"], false, false, 0.3, 0)); key_frame_value.push_back(gen_current_animation_data(spine_anim->get_anim_name(), ca["track_id"], ca["loop"], false, false, 0.3, 0));
auto anim = Ref<Animation>(memnew(Animation)); auto anim = Ref<Animation>(memnew(Animation));
auto track_index = anim->add_track(Animation::TYPE_VALUE); auto track_index = anim->add_track(Animation::TYPE_VALUE);
anim->set_length(min_duration > spine_anim->get_duration() ? min_duration : spine_anim->get_duration()); anim->set_length(min_duration > spine_anim->get_duration() ? min_duration : spine_anim->get_duration());
anim->track_set_path(track_index, NodePath(vformat("%s:current_animations", path_to_sprite))); anim->track_set_path(track_index, NodePath(vformat("%s:current_animations", path_to_sprite)));
anim->track_insert_key(track_index, 0.0, key_frame_value); anim->track_insert_key(track_index, 0.0, key_frame_value);
anim->value_track_set_update_mode(track_index, Animation::UPDATE_DISCRETE); anim->value_track_set_update_mode(track_index, Animation::UPDATE_DISCRETE);
if (anim_player->has_animation(spine_anim->get_anim_name())) if (anim_player->has_animation(spine_anim->get_anim_name()))
anim_player->remove_animation(spine_anim->get_anim_name()); anim_player->remove_animation(spine_anim->get_anim_name());
anim_player->add_animation(spine_anim->get_anim_name(), anim); anim_player->add_animation(spine_anim->get_anim_name(), anim);
} }
err = false; err = false;
} }
Dictionary SpineSpriteAnimateDialog::gen_current_animation_data(const String &animation, int64_t track_id, bool loop, bool clear, bool empty, bool empty_duration, float delay) { Dictionary SpineSpriteAnimateDialog::gen_current_animation_data(const String &animation, int64_t track_id, bool loop, bool clear, bool empty, bool empty_duration, float delay) {
Dictionary res; Dictionary res;
res["animation"] = animation; res["animation"] = animation;
res["track_id"] = track_id; res["track_id"] = track_id;
res["loop"] = loop; res["loop"] = loop;
res["clear"] = clear; res["clear"] = clear;
res["empty"] = empty; res["empty"] = empty;
res["empty_animation_duration"] = empty_duration; res["empty_animation_duration"] = empty_duration;
res["delay"] = delay; res["delay"] = delay;
return res; return res;
} }
void SpineSpriteAnimateDialog::load_data_from_anim_player(AnimationPlayer *anim_player, bool &err) { void SpineSpriteAnimateDialog::load_data_from_anim_player(AnimationPlayer *anim_player, bool &err) {
if (anim_player == nullptr) { if (anim_player == nullptr) {
ERROR_MSG("The animation player is null."); ERROR_MSG("The animation player is null.");
} }
auto root = anim_player->get_node_or_null(anim_player->get_root()); auto root = anim_player->get_node_or_null(anim_player->get_root());
if (root == nullptr) return; if (root == nullptr) return;
auto sprite = get_node_or_null(spine_sprite_path); auto sprite = get_node_or_null(spine_sprite_path);
if (sprite == nullptr) return; if (sprite == nullptr) return;
auto item = animate_dialog_tree->get_root()->get_children(); auto item = animate_dialog_tree->get_root()->get_children();
while (item) { while (item) {
String animation = item->get_text(0); String animation = item->get_text(0);
auto anim = anim_player->get_animation(animation); auto anim = anim_player->get_animation(animation);
if (anim.is_valid() && anim->get_track_count() > 0) { if (anim.is_valid() && anim->get_track_count() > 0) {
if (anim->track_get_type(0) == Animation::TYPE_VALUE) { if (anim->track_get_type(0) == Animation::TYPE_VALUE) {
auto track_path = anim->track_get_path(0); auto track_path = anim->track_get_path(0);
if (root->get_node_or_null(track_path) == sprite) { if (root->get_node_or_null(track_path) == sprite) {
if (anim->track_get_key_count(0) > 0) { if (anim->track_get_key_count(0) > 0) {
Array key_frame_value = anim->track_get_key_value(0, 0); Array key_frame_value = anim->track_get_key_value(0, 0);
if (!key_frame_value.empty()) { if (!key_frame_value.empty()) {
Dictionary _ca = key_frame_value.front(); Dictionary _ca = key_frame_value.front();
if (_ca.has("loop")) item->set_checked(1, _ca["loop"]); if (_ca.has("loop")) item->set_checked(1, _ca["loop"]);
if (_ca.has("track_id")) item->set_range(2, _ca["track_id"]); if (_ca.has("track_id")) item->set_range(2, _ca["track_id"]);
} }
} }
} }
} }
}
} item = item->get_next();
}
item = item->get_next(); err = false;
}
err = false;
} }
//----- Signals ----- //----- Signals -----
void SpineSpriteAnimateDialog::_on_scene_tree_selected(NodePath path) { void SpineSpriteAnimateDialog::_on_scene_tree_selected(NodePath path) {
// print_line(vformat("anime: %s", path)); // print_line(vformat("anime: %s", path));
auto node = get_node_or_null(path); auto node = get_node_or_null(path);
if (node == nullptr) { if (node == nullptr) {
error("The node you chose is null."); error("The node you chose is null.");
return; return;
} }
if (!node->is_class("AnimationPlayer")) { if (!node->is_class("AnimationPlayer")) {
error("The node you chose is not AnimationPlayer."); error("The node you chose is not AnimationPlayer.");
return; return;
} }
anim_player_path = path; anim_player_path = path;
} }
void SpineSpriteAnimateDialog::_on_animate_button_pressed() { void SpineSpriteAnimateDialog::_on_animate_button_pressed() {
anim_player_path = String(""); anim_player_path = String("");
auto node = (Node*)the_plugin->get_editor_interface()->get_selection()->get_selected_nodes().back(); auto node = (Node *) the_plugin->get_editor_interface()->get_selection()->get_selected_nodes().back();
spine_sprite_path = node->get_path(); spine_sprite_path = node->get_path();
// print_line(vformat("sp: %s", spine_sprite_path)); // print_line(vformat("sp: %s", spine_sprite_path));
animate_dialog_override_button->set_visible(false); animate_dialog_override_button->set_visible(false);
scene_tree_dialog->popup_centered_ratio(); scene_tree_dialog->popup_centered_ratio();
} }
void SpineSpriteAnimateDialog::_on_scene_tree_hide() { void SpineSpriteAnimateDialog::_on_scene_tree_hide() {
animate_dialog->popup_centered(); animate_dialog->popup_centered();
bool err = false; bool err = false;
load_data_from_sprite((SpineSprite*)get_node_or_null(spine_sprite_path), err); load_data_from_sprite((SpineSprite *) get_node_or_null(spine_sprite_path), err);
if (err) animate_dialog->hide();
err = false;
auto node = get_node_or_null(anim_player_path);
if (node != nullptr) {
load_data_from_anim_player((AnimationPlayer*)node, err);
animate_dialog_override_button->set_visible(!err);
} else {
animate_dialog_override_button->set_visible(false);
}
if (err) animate_dialog->hide();
err = false;
auto node = get_node_or_null(anim_player_path);
if (node != nullptr) {
load_data_from_anim_player((AnimationPlayer *) node, err);
animate_dialog_override_button->set_visible(!err);
} else {
animate_dialog_override_button->set_visible(false);
}
} }
void SpineSpriteAnimateDialog::_on_animate_dialog_action(const String &act) { void SpineSpriteAnimateDialog::_on_animate_dialog_action(const String &act) {
bool err = false; bool err = false;
if (act == "confirmed") { if (act == "confirmed") {
gen_new_animation_player((SpineSprite*)get_node_or_null(spine_sprite_path), err); gen_new_animation_player((SpineSprite *) get_node_or_null(spine_sprite_path), err);
} else if (act == "override") { } else if (act == "override") {
gen_animations((SpineSprite*)get_node_or_null(spine_sprite_path), (AnimationPlayer*)get_node_or_null(anim_player_path), get_data_from_tree(), MIN_TRACK_LENGTH, err); gen_animations((SpineSprite *) get_node_or_null(spine_sprite_path), (AnimationPlayer *) get_node_or_null(anim_player_path), get_data_from_tree(), MIN_TRACK_LENGTH, err);
} }
if (!err) { if (!err) {
animate_dialog->hide(); animate_dialog->hide();
} }
} }

View File

@ -36,51 +36,52 @@
class SpineSprite; class SpineSprite;
class SpineSpriteAnimateDialog : public Control { class SpineSpriteAnimateDialog : public Control {
GDCLASS(SpineSpriteAnimateDialog, Control); GDCLASS(SpineSpriteAnimateDialog, Control);
protected: protected:
static void _bind_methods(); static void _bind_methods();
AcceptDialog *error_dialog; AcceptDialog *error_dialog;
ToolButton *animate_button; ToolButton *animate_button;
EditorPlugin *the_plugin; EditorPlugin *the_plugin;
ConfirmationDialog *animate_dialog; ConfirmationDialog *animate_dialog;
Button *animate_dialog_override_button; Button *animate_dialog_override_button;
Tree *animate_dialog_tree; Tree *animate_dialog_tree;
SceneTreeDialog *scene_tree_dialog; SceneTreeDialog *scene_tree_dialog;
NodePath spine_sprite_path; NodePath spine_sprite_path;
NodePath anim_player_path; NodePath anim_player_path;
void add_row(const String &animation, bool loop=true, int64_t track_id=0); void add_row(const String &animation, bool loop = true, int64_t track_id = 0);
void clear_tree(); void clear_tree();
void error(const String &text, const String &title="Error"); void error(const String &text, const String &title = "Error");
void load_data_from_sprite(SpineSprite *sprite, bool &err); void load_data_from_sprite(SpineSprite *sprite, bool &err);
void load_data_from_anim_player(AnimationPlayer *anim_player, bool &err); void load_data_from_anim_player(AnimationPlayer *anim_player, bool &err);
Dictionary get_data_from_tree(); Dictionary get_data_from_tree();
void gen_new_animation_player(SpineSprite *sprite, bool &err);
void gen_animations(SpineSprite *sprite, AnimationPlayer *anim_player, const Dictionary &config, float min_duration, bool &err);
Dictionary gen_current_animation_data(const String &animation, int64_t track_id, bool loop, bool clear, bool empty, bool empty_duration, float delay);
void gen_new_animation_player(SpineSprite *sprite, bool &err);
void gen_animations(SpineSprite *sprite, AnimationPlayer *anim_player, const Dictionary &config, float min_duration, bool &err);
Dictionary gen_current_animation_data(const String &animation, int64_t track_id, bool loop, bool clear, bool empty, bool empty_duration, float delay);
public: public:
SpineSpriteAnimateDialog(); SpineSpriteAnimateDialog();
~SpineSpriteAnimateDialog(); ~SpineSpriteAnimateDialog();
void set_animate_button(ToolButton *b); void set_animate_button(ToolButton *b);
inline ToolButton *get_animate_button() {return animate_button;} inline ToolButton *get_animate_button() { return animate_button; }
inline void set_plugin(EditorPlugin *p) {the_plugin = p;} inline void set_plugin(EditorPlugin *p) { the_plugin = p; }
void _on_animate_button_pressed(); void _on_animate_button_pressed();
void _on_scene_tree_selected(NodePath path); void _on_scene_tree_selected(NodePath path);
void _on_scene_tree_hide(); void _on_scene_tree_hide();
void _on_animate_dialog_action(const String &act); void _on_animate_dialog_action(const String &act);
}; };
#endif #endif
#endif //GODOT_SPINESPRITEANIMATEDIALOG_H #endif//GODOT_SPINESPRITEANIMATEDIALOG_H

View File

@ -43,6 +43,6 @@ Ref<SpineSlot> SpineSpriteMeshInstance2D::get_slot() {
return slot; return slot;
} }
void SpineSpriteMeshInstance2D::apply_transform_2d(Variant o){ void SpineSpriteMeshInstance2D::apply_transform_2d(Variant o) {
slot->get_bone()->apply_world_transform_2d(o); slot->get_bone()->apply_world_transform_2d(o);
} }

View File

@ -41,11 +41,12 @@ protected:
static void _bind_methods(); static void _bind_methods();
Ref<SpineSlot> slot; Ref<SpineSlot> slot;
public: public:
SpineSpriteMeshInstance2D(); SpineSpriteMeshInstance2D();
~SpineSpriteMeshInstance2D(); ~SpineSpriteMeshInstance2D();
inline void set_slot(Ref<SpineSlot> s){ inline void set_slot(Ref<SpineSlot> s) {
slot = s; slot = s;
} }
Ref<SpineSlot> get_slot(); Ref<SpineSlot> get_slot();
@ -53,4 +54,4 @@ public:
void apply_transform_2d(Variant o); void apply_transform_2d(Variant o);
}; };
#endif //GODOT_SPINESPRITEMESHINSTANCE2D_H #endif//GODOT_SPINESPRITEMESHINSTANCE2D_H

View File

@ -36,68 +36,64 @@
#include "core/method_bind_ext.gen.inc" #include "core/method_bind_ext.gen.inc"
void SpineTimeline::_bind_methods() { void SpineTimeline::_bind_methods() {
ClassDB::bind_method(D_METHOD("apply", "skeleton", "lastTime", "time", "pEvents", "alpha", "blend", "direction"), &SpineTimeline::apply); ClassDB::bind_method(D_METHOD("apply", "skeleton", "lastTime", "time", "pEvents", "alpha", "blend", "direction"), &SpineTimeline::apply);
ClassDB::bind_method(D_METHOD("get_frame_entries"), &SpineTimeline::get_frame_entries); ClassDB::bind_method(D_METHOD("get_frame_entries"), &SpineTimeline::get_frame_entries);
ClassDB::bind_method(D_METHOD("get_frame_count"), &SpineTimeline::get_frame_count); ClassDB::bind_method(D_METHOD("get_frame_count"), &SpineTimeline::get_frame_count);
ClassDB::bind_method(D_METHOD("get_frames"), &SpineTimeline::get_frames); ClassDB::bind_method(D_METHOD("get_frames"), &SpineTimeline::get_frames);
ClassDB::bind_method(D_METHOD("get_duration"), &SpineTimeline::get_duration); ClassDB::bind_method(D_METHOD("get_duration"), &SpineTimeline::get_duration);
ClassDB::bind_method(D_METHOD("getPropertyIds"), &SpineTimeline::getPropertyIds); ClassDB::bind_method(D_METHOD("getPropertyIds"), &SpineTimeline::getPropertyIds);
} }
SpineTimeline::SpineTimeline():timeline(nullptr) { SpineTimeline::SpineTimeline() : timeline(nullptr) {
} }
SpineTimeline::~SpineTimeline() { SpineTimeline::~SpineTimeline() {
} }
void SpineTimeline::apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, Array pEvents, float alpha, void SpineTimeline::apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, Array pEvents, float alpha,
SpineConstant::MixBlend blend, SpineConstant::MixDirection direction) { SpineConstant::MixBlend blend, SpineConstant::MixDirection direction) {
spine::Vector<spine::Event*> events; spine::Vector<spine::Event *> events;
events.setSize(pEvents.size(), nullptr); events.setSize(pEvents.size(), nullptr);
for (size_t i=0; i<events.size(); ++i) { for (size_t i = 0; i < events.size(); ++i) {
events[i] = ((Ref<SpineEvent>)pEvents[i])->get_spine_object(); events[i] = ((Ref<SpineEvent>) pEvents[i])->get_spine_object();
} }
timeline->apply(*(skeleton->get_spine_object()), lastTime, time, &events, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction); timeline->apply(*(skeleton->get_spine_object()), lastTime, time, &events, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction);
} }
int64_t SpineTimeline::get_frame_entries() { int64_t SpineTimeline::get_frame_entries() {
return timeline->getFrameEntries(); return timeline->getFrameEntries();
} }
int64_t SpineTimeline::get_frame_count() { int64_t SpineTimeline::get_frame_count() {
return timeline->getFrameCount(); return timeline->getFrameCount();
} }
Array SpineTimeline::get_frames() { Array SpineTimeline::get_frames() {
auto &frames = timeline->getFrames(); auto &frames = timeline->getFrames();
Array res; Array res;
res.resize(frames.size()); res.resize(frames.size());
for (size_t i=0; i<res.size(); ++i) { for (size_t i = 0; i < res.size(); ++i) {
res[i] = frames[i]; res[i] = frames[i];
} }
return res; return res;
} }
float SpineTimeline::get_duration() { float SpineTimeline::get_duration() {
return timeline->getDuration(); return timeline->getDuration();
} }
Array SpineTimeline::getPropertyIds() { Array SpineTimeline::getPropertyIds() {
auto &ids = timeline->getPropertyIds(); auto &ids = timeline->getPropertyIds();
Array res; Array res;
res.resize(ids.size()); res.resize(ids.size());
for (size_t i=0; i<res.size(); ++i) { for (size_t i = 0; i < res.size(); ++i) {
res[i] = ids[i]; res[i] = ids[i];
} }
return res; return res;
} }

View File

@ -39,34 +39,37 @@
class SpineSkeleton; class SpineSkeleton;
class SpineEvent; class SpineEvent;
class SpineTimeline : public Reference{ class SpineTimeline : public Reference {
GDCLASS(SpineTimeline, Reference); GDCLASS(SpineTimeline, Reference);
protected: protected:
static void _bind_methods(); static void _bind_methods();
private: private:
spine::Timeline *timeline; spine::Timeline *timeline;
public: public:
SpineTimeline(); SpineTimeline();
~SpineTimeline(); ~SpineTimeline();
inline void set_spine_object(spine::Timeline *v) {timeline = v;} inline void set_spine_object(spine::Timeline *v) { timeline = v; }
inline spine::Timeline *get_spine_object() {return timeline;} inline spine::Timeline *get_spine_object() { return timeline; }
// Vector<Event *> // Vector<Event *>
void apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction); void apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction);
int64_t get_frame_entries(); int64_t get_frame_entries();
int64_t get_frame_count(); int64_t get_frame_count();
// Vector<float> // Vector<float>
Array get_frames(); Array get_frames();
float get_duration(); float get_duration();
// Vector <PropertyId> // Vector <PropertyId>
Array getPropertyIds(); Array getPropertyIds();
}; };
#endif //GODOT_SPINETIMELINE_H #endif//GODOT_SPINETIMELINE_H

View File

@ -40,8 +40,8 @@ void SpineTrackEntry::_bind_methods() {
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_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);
@ -99,167 +99,167 @@ void SpineTrackEntry::_bind_methods() {
BIND_ENUM_CONSTANT(MIXBLEND_ADD); BIND_ENUM_CONSTANT(MIXBLEND_ADD);
} }
SpineTrackEntry::SpineTrackEntry():track_entry(NULL) {} SpineTrackEntry::SpineTrackEntry() : track_entry(NULL) {}
SpineTrackEntry::~SpineTrackEntry() {} SpineTrackEntry::~SpineTrackEntry() {}
int SpineTrackEntry::get_track_index(){ int SpineTrackEntry::get_track_index() {
return track_entry->getTrackIndex(); return track_entry->getTrackIndex();
} }
Ref<SpineAnimation> SpineTrackEntry::get_animation(){ Ref<SpineAnimation> SpineTrackEntry::get_animation() {
Ref<SpineAnimation> gd_anim(memnew(SpineAnimation)); Ref<SpineAnimation> gd_anim(memnew(SpineAnimation));
auto anim = track_entry->getAnimation(); auto anim = track_entry->getAnimation();
if(anim == NULL) return NULL; if (anim == NULL) return NULL;
gd_anim->set_spine_object(anim); gd_anim->set_spine_object(anim);
return gd_anim; return gd_anim;
} }
bool SpineTrackEntry::get_loop(){ bool SpineTrackEntry::get_loop() {
return track_entry->getLoop(); return track_entry->getLoop();
} }
void SpineTrackEntry::set_loop(bool v){ void SpineTrackEntry::set_loop(bool v) {
track_entry->setLoop(v); track_entry->setLoop(v);
} }
bool SpineTrackEntry::get_hold_previous(){ bool SpineTrackEntry::get_hold_previous() {
return track_entry->getHoldPrevious(); return track_entry->getHoldPrevious();
} }
void SpineTrackEntry::set_hold_previous(bool v){ void SpineTrackEntry::set_hold_previous(bool v) {
track_entry->setHoldPrevious(v); track_entry->setHoldPrevious(v);
} }
float SpineTrackEntry::get_delay(){ float SpineTrackEntry::get_delay() {
return track_entry->getDelay(); return track_entry->getDelay();
} }
void SpineTrackEntry::set_delay(float v){ void SpineTrackEntry::set_delay(float v) {
track_entry->setDelay(v); track_entry->setDelay(v);
} }
float SpineTrackEntry::get_track_time(){ float SpineTrackEntry::get_track_time() {
return track_entry->getTrackTime(); return track_entry->getTrackTime();
} }
void SpineTrackEntry::set_track_time(float v){ void SpineTrackEntry::set_track_time(float v) {
track_entry->setTrackTime(v); track_entry->setTrackTime(v);
} }
float SpineTrackEntry::get_track_end(){ float SpineTrackEntry::get_track_end() {
return track_entry->getTrackEnd(); return track_entry->getTrackEnd();
} }
void SpineTrackEntry::set_track_end(float v){ void SpineTrackEntry::set_track_end(float v) {
track_entry->setTrackEnd(v); track_entry->setTrackEnd(v);
} }
float SpineTrackEntry::get_animation_start(){ float SpineTrackEntry::get_animation_start() {
return track_entry->getAnimationStart(); return track_entry->getAnimationStart();
} }
void SpineTrackEntry::set_animation_start(float v){ void SpineTrackEntry::set_animation_start(float v) {
track_entry->setAnimationStart(v); track_entry->setAnimationStart(v);
} }
float SpineTrackEntry::get_animation_last(){ float SpineTrackEntry::get_animation_last() {
return track_entry->getAnimationLast(); return track_entry->getAnimationLast();
} }
void SpineTrackEntry::set_animation_last(float v){ void SpineTrackEntry::set_animation_last(float v) {
track_entry->setAnimationLast(v); track_entry->setAnimationLast(v);
} }
float SpineTrackEntry::get_animation_time(){ float SpineTrackEntry::get_animation_time() {
return track_entry->getAnimationTime(); return track_entry->getAnimationTime();
} }
float SpineTrackEntry::get_time_scale(){ float SpineTrackEntry::get_time_scale() {
return track_entry->getTimeScale(); return track_entry->getTimeScale();
} }
void SpineTrackEntry::set_time_scale(float v){ void SpineTrackEntry::set_time_scale(float v) {
track_entry->setTimeScale(v); track_entry->setTimeScale(v);
} }
float SpineTrackEntry::get_alpha(){ float SpineTrackEntry::get_alpha() {
return track_entry->getAlpha(); return track_entry->getAlpha();
} }
void SpineTrackEntry::set_alpha(float v){ void SpineTrackEntry::set_alpha(float v) {
track_entry->setAlpha(v); track_entry->setAlpha(v);
} }
float SpineTrackEntry::get_event_threshold(){ float SpineTrackEntry::get_event_threshold() {
return track_entry->getEventThreshold(); return track_entry->getEventThreshold();
} }
void SpineTrackEntry::set_event_threshold(float v){ void SpineTrackEntry::set_event_threshold(float v) {
track_entry->setEventThreshold(v); track_entry->setEventThreshold(v);
} }
float SpineTrackEntry::get_attachment_threshold(){ float SpineTrackEntry::get_attachment_threshold() {
return track_entry->getAttachmentThreshold(); return track_entry->getAttachmentThreshold();
} }
void SpineTrackEntry::set_attachment_threshold(float v){ void SpineTrackEntry::set_attachment_threshold(float v) {
track_entry->setAttachmentThreshold(v); track_entry->setAttachmentThreshold(v);
} }
float SpineTrackEntry::get_draw_order_threshold(){ float SpineTrackEntry::get_draw_order_threshold() {
return track_entry->getDrawOrderThreshold(); return track_entry->getDrawOrderThreshold();
} }
void SpineTrackEntry::set_draw_order_threshold(float v){ void SpineTrackEntry::set_draw_order_threshold(float v) {
track_entry->setDrawOrderThreshold(v); track_entry->setDrawOrderThreshold(v);
} }
Ref<SpineTrackEntry> SpineTrackEntry::get_next(){ Ref<SpineTrackEntry> SpineTrackEntry::get_next() {
Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry)); Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry));
auto entry = track_entry->getNext(); auto entry = track_entry->getNext();
if(entry == NULL) return NULL; if (entry == NULL) return NULL;
gd_entry->set_spine_object(entry); gd_entry->set_spine_object(entry);
return gd_entry; return gd_entry;
} }
bool SpineTrackEntry::is_complete(){ bool SpineTrackEntry::is_complete() {
return track_entry->isComplete(); return track_entry->isComplete();
} }
float SpineTrackEntry::get_mix_time(){ float SpineTrackEntry::get_mix_time() {
return track_entry->getMixTime(); return track_entry->getMixTime();
} }
void SpineTrackEntry::set_mix_time(float v){ void SpineTrackEntry::set_mix_time(float v) {
track_entry->setMixTime(v); track_entry->setMixTime(v);
} }
float SpineTrackEntry::get_mix_duration(){ float SpineTrackEntry::get_mix_duration() {
return track_entry->getMixDuration(); return track_entry->getMixDuration();
} }
void SpineTrackEntry::set_mix_duration(float v){ void SpineTrackEntry::set_mix_duration(float v) {
track_entry->setMixDuration(v); track_entry->setMixDuration(v);
} }
SpineTrackEntry::MixBlend SpineTrackEntry::get_mix_blend(){ SpineTrackEntry::MixBlend SpineTrackEntry::get_mix_blend() {
int mb = track_entry->getMixBlend(); int mb = track_entry->getMixBlend();
return (MixBlend) mb; return (MixBlend) mb;
} }
void SpineTrackEntry::set_mix_blend(SpineTrackEntry::MixBlend v){ void SpineTrackEntry::set_mix_blend(SpineTrackEntry::MixBlend v) {
int mb = (int) v; int mb = (int) v;
track_entry->setMixBlend((spine::MixBlend)mb); track_entry->setMixBlend((spine::MixBlend) mb);
} }
Ref<SpineTrackEntry> SpineTrackEntry::get_mixing_from(){ Ref<SpineTrackEntry> SpineTrackEntry::get_mixing_from() {
Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry)); Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry));
auto entry = track_entry->getMixingFrom(); auto entry = track_entry->getMixingFrom();
if(entry == NULL) return NULL; if (entry == NULL) return NULL;
gd_entry->set_spine_object(entry); gd_entry->set_spine_object(entry);
return gd_entry; return gd_entry;
} }
Ref<SpineTrackEntry> SpineTrackEntry::get_mixing_to(){ Ref<SpineTrackEntry> SpineTrackEntry::get_mixing_to() {
Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry)); Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry));
auto entry = track_entry->getMixingTo(); auto entry = track_entry->getMixingTo();
if(entry == NULL) return NULL; if (entry == NULL) return NULL;
gd_entry->set_spine_object(entry); gd_entry->set_spine_object(entry);
return gd_entry; return gd_entry;
} }
void SpineTrackEntry::reset_rotation_directions(){ void SpineTrackEntry::reset_rotation_directions() {
track_entry->resetRotationDirections(); track_entry->resetRotationDirections();
} }
bool SpineTrackEntry::get_reverse() { bool SpineTrackEntry::get_reverse() {
return track_entry->getReverse(); return track_entry->getReverse();
} }
void SpineTrackEntry::set_reverse(bool v) { void SpineTrackEntry::set_reverse(bool v) {
track_entry->setReverse(v); track_entry->setReverse(v);
} }

View File

@ -36,7 +36,7 @@
#include "SpineAnimation.h" #include "SpineAnimation.h"
class SpineTrackEntry : public Reference{ class SpineTrackEntry : public Reference {
GDCLASS(SpineTrackEntry, Reference); GDCLASS(SpineTrackEntry, Reference);
protected: protected:
@ -49,10 +49,10 @@ public:
SpineTrackEntry(); SpineTrackEntry();
~SpineTrackEntry(); ~SpineTrackEntry();
inline void set_spine_object(spine::TrackEntry *t){ inline void set_spine_object(spine::TrackEntry *t) {
track_entry = t; track_entry = t;
} }
inline spine::TrackEntry *get_spine_object(){ inline spine::TrackEntry *get_spine_object() {
return track_entry; return track_entry;
} }
@ -73,8 +73,8 @@ public:
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);
float get_delay(); float get_delay();
void set_delay(float v); void set_delay(float v);
@ -128,4 +128,4 @@ public:
}; };
VARIANT_ENUM_CAST(SpineTrackEntry::MixBlend); VARIANT_ENUM_CAST(SpineTrackEntry::MixBlend);
#endif //GODOT_SPINETRACKENTRY_H #endif//GODOT_SPINETRACKENTRY_H

View File

@ -51,31 +51,31 @@ 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(NULL) {}
SpineTransformConstraint::~SpineTransformConstraint() {} SpineTransformConstraint::~SpineTransformConstraint() {}
void SpineTransformConstraint::update(){ void SpineTransformConstraint::update() {
transform_constraint->update(); transform_constraint->update();
} }
int SpineTransformConstraint::get_order(){ int SpineTransformConstraint::get_order() {
return transform_constraint->getOrder(); return transform_constraint->getOrder();
} }
Ref<SpineTransformConstraintData> SpineTransformConstraint::get_data(){ Ref<SpineTransformConstraintData> SpineTransformConstraint::get_data() {
auto &d = transform_constraint->getData(); auto &d = transform_constraint->getData();
Ref<SpineTransformConstraintData> gd_d(memnew(SpineTransformConstraintData)); Ref<SpineTransformConstraintData> gd_d(memnew(SpineTransformConstraintData));
gd_d->set_spine_object(&d); gd_d->set_spine_object(&d);
return gd_d; return gd_d;
} }
Array SpineTransformConstraint::get_bones(){ Array SpineTransformConstraint::get_bones() {
auto &bs = transform_constraint->getBones(); auto &bs = transform_constraint->getBones();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i<bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
auto b = bs[i]; auto b = bs[i];
if(b == NULL) gd_bs[i] = Ref<SpineBone>(NULL); if (b == NULL) gd_bs[i] = Ref<SpineBone>(NULL);
Ref<SpineBone> gd_b(memnew(SpineBone)); Ref<SpineBone> gd_b(memnew(SpineBone));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
gd_bs[i] = gd_b; gd_bs[i] = gd_b;
@ -83,66 +83,66 @@ Array SpineTransformConstraint::get_bones(){
return gd_bs; return gd_bs;
} }
Ref<SpineBone> SpineTransformConstraint::get_target(){ Ref<SpineBone> SpineTransformConstraint::get_target() {
auto b = transform_constraint->getTarget(); auto b = transform_constraint->getTarget();
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineBone> gd_b(memnew(SpineBone)); Ref<SpineBone> gd_b(memnew(SpineBone));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
return gd_b; return gd_b;
} }
void SpineTransformConstraint::set_target(Ref<SpineBone> v){ void SpineTransformConstraint::set_target(Ref<SpineBone> v) {
if(v.is_valid()){ if (v.is_valid()) {
transform_constraint->setTarget(v->get_spine_object()); transform_constraint->setTarget(v->get_spine_object());
} else{ } else {
transform_constraint->setTarget(NULL); transform_constraint->setTarget(NULL);
} }
} }
float SpineTransformConstraint::get_mix_rotate(){ float SpineTransformConstraint::get_mix_rotate() {
return transform_constraint->getMixRotate(); return transform_constraint->getMixRotate();
} }
void SpineTransformConstraint::set_mix_rotate(float v){ void SpineTransformConstraint::set_mix_rotate(float v) {
transform_constraint->setMixRotate(v); transform_constraint->setMixRotate(v);
} }
float SpineTransformConstraint::get_mix_x(){ float SpineTransformConstraint::get_mix_x() {
return transform_constraint->getMixX(); return transform_constraint->getMixX();
} }
void SpineTransformConstraint::set_mix_x(float v){ void SpineTransformConstraint::set_mix_x(float v) {
transform_constraint->setMixX(v); transform_constraint->setMixX(v);
} }
float SpineTransformConstraint::get_mix_y(){ float SpineTransformConstraint::get_mix_y() {
return transform_constraint->getMixY(); return transform_constraint->getMixY();
} }
void SpineTransformConstraint::set_mix_y(float v){ void SpineTransformConstraint::set_mix_y(float v) {
transform_constraint->setMixY(v); transform_constraint->setMixY(v);
} }
float SpineTransformConstraint::get_mix_scale_x(){ float SpineTransformConstraint::get_mix_scale_x() {
return transform_constraint->getMixScaleX(); return transform_constraint->getMixScaleX();
} }
void SpineTransformConstraint::set_mix_scale_x(float v){ void SpineTransformConstraint::set_mix_scale_x(float v) {
transform_constraint->setMixScaleX(v); transform_constraint->setMixScaleX(v);
} }
float SpineTransformConstraint::get_mix_scale_y(){ float SpineTransformConstraint::get_mix_scale_y() {
return transform_constraint->getMixScaleY(); return transform_constraint->getMixScaleY();
} }
void SpineTransformConstraint::set_mix_scale_y(float v){ void SpineTransformConstraint::set_mix_scale_y(float v) {
transform_constraint->setMixScaleY(v); transform_constraint->setMixScaleY(v);
} }
float SpineTransformConstraint::get_mix_shear_y(){ float SpineTransformConstraint::get_mix_shear_y() {
return transform_constraint->getMixShearY(); return transform_constraint->getMixShearY();
} }
void SpineTransformConstraint::set_mix_shear_y(float v){ void SpineTransformConstraint::set_mix_shear_y(float v) {
transform_constraint->setMixShearY(v); transform_constraint->setMixShearY(v);
} }
bool SpineTransformConstraint::is_active(){ bool SpineTransformConstraint::is_active() {
return transform_constraint->isActive(); return transform_constraint->isActive();
} }
void SpineTransformConstraint::set_active(bool v){ void SpineTransformConstraint::set_active(bool v) {
transform_constraint->setActive(v); transform_constraint->setActive(v);
} }

View File

@ -37,7 +37,7 @@
#include "SpineTransformConstraintData.h" #include "SpineTransformConstraintData.h"
#include "SpineBone.h" #include "SpineBone.h"
class SpineTransformConstraint : public Reference{ class SpineTransformConstraint : public Reference {
GDCLASS(SpineTransformConstraint, Reference); GDCLASS(SpineTransformConstraint, Reference);
protected: protected:
@ -50,10 +50,10 @@ public:
SpineTransformConstraint(); SpineTransformConstraint();
~SpineTransformConstraint(); ~SpineTransformConstraint();
inline void set_spine_object(spine::TransformConstraint *tc){ inline void set_spine_object(spine::TransformConstraint *tc) {
transform_constraint = tc; transform_constraint = tc;
} }
inline spine::TransformConstraint *get_spine_object(){ inline spine::TransformConstraint *get_spine_object() {
return transform_constraint; return transform_constraint;
} }
@ -90,4 +90,4 @@ public:
void set_active(bool v); void set_active(bool v);
}; };
#endif //GODOT_SPINETRANSFORMCONSTRAINT_H #endif//GODOT_SPINETRANSFORMCONSTRAINT_H

View File

@ -51,12 +51,12 @@ void SpineTransformConstraintData::_bind_methods() {
SpineTransformConstraintData::SpineTransformConstraintData() {} SpineTransformConstraintData::SpineTransformConstraintData() {}
SpineTransformConstraintData::~SpineTransformConstraintData() {} SpineTransformConstraintData::~SpineTransformConstraintData() {}
Array SpineTransformConstraintData::get_bones(){ Array SpineTransformConstraintData::get_bones() {
auto bs = get_spine_data()->getBones(); auto bs = get_spine_data()->getBones();
Array gd_bs; Array gd_bs;
gd_bs.resize(bs.size()); gd_bs.resize(bs.size());
for(size_t i=0; i < bs.size(); ++i){ for (size_t i = 0; i < bs.size(); ++i) {
if(bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL); if (bs[i] == NULL) gd_bs[i] = Ref<SpineBoneData>(NULL);
else { else {
Ref<SpineBoneData> gd_b(memnew(SpineBoneData)); Ref<SpineBoneData> gd_b(memnew(SpineBoneData));
gd_b->set_spine_object(bs[i]); gd_b->set_spine_object(bs[i]);
@ -65,54 +65,54 @@ Array SpineTransformConstraintData::get_bones(){
} }
return gd_bs; return gd_bs;
} }
Ref<SpineBoneData> SpineTransformConstraintData::get_target(){ Ref<SpineBoneData> SpineTransformConstraintData::get_target() {
auto b = get_spine_data()->getTarget(); auto b = get_spine_data()->getTarget();
if(b == NULL) return NULL; if (b == NULL) return NULL;
Ref<SpineBoneData> gd_b(memnew(SpineBoneData)); Ref<SpineBoneData> gd_b(memnew(SpineBoneData));
gd_b->set_spine_object(b); gd_b->set_spine_object(b);
return gd_b; return gd_b;
} }
float SpineTransformConstraintData::get_mix_rotate(){ float SpineTransformConstraintData::get_mix_rotate() {
return get_spine_data()->getMixRotate(); return get_spine_data()->getMixRotate();
} }
float SpineTransformConstraintData::get_mix_x(){ float SpineTransformConstraintData::get_mix_x() {
return get_spine_data()->getMixX(); return get_spine_data()->getMixX();
} }
float SpineTransformConstraintData::get_mix_y(){ float SpineTransformConstraintData::get_mix_y() {
return get_spine_data()->getMixY(); return get_spine_data()->getMixY();
} }
float SpineTransformConstraintData::get_mix_scale_x(){ float SpineTransformConstraintData::get_mix_scale_x() {
return get_spine_data()->getMixScaleX(); return get_spine_data()->getMixScaleX();
} }
float SpineTransformConstraintData::get_mix_scale_y(){ float SpineTransformConstraintData::get_mix_scale_y() {
return get_spine_data()->getMixScaleY(); return get_spine_data()->getMixScaleY();
} }
float SpineTransformConstraintData::get_mix_shear_y(){ float SpineTransformConstraintData::get_mix_shear_y() {
return get_spine_data()->getMixShearY(); return get_spine_data()->getMixShearY();
} }
float SpineTransformConstraintData::get_offset_rotation(){ float SpineTransformConstraintData::get_offset_rotation() {
return get_spine_data()->getOffsetRotation(); return get_spine_data()->getOffsetRotation();
} }
float SpineTransformConstraintData::get_offset_x(){ float SpineTransformConstraintData::get_offset_x() {
return get_spine_data()->getOffsetX(); return get_spine_data()->getOffsetX();
} }
float SpineTransformConstraintData::get_offset_y(){ float SpineTransformConstraintData::get_offset_y() {
return get_spine_data()->getOffsetY(); return get_spine_data()->getOffsetY();
} }
float SpineTransformConstraintData::get_offset_scale_x(){ float SpineTransformConstraintData::get_offset_scale_x() {
return get_spine_data()->getOffsetScaleX(); return get_spine_data()->getOffsetScaleX();
} }
float SpineTransformConstraintData::get_offset_scale_y(){ float SpineTransformConstraintData::get_offset_scale_y() {
return get_spine_data()->getOffsetScaleY(); return get_spine_data()->getOffsetScaleY();
} }
float SpineTransformConstraintData::get_offset_shear_y(){ float SpineTransformConstraintData::get_offset_shear_y() {
return get_spine_data()->getOffsetShearY(); return get_spine_data()->getOffsetShearY();
} }
bool SpineTransformConstraintData::is_relative(){ bool SpineTransformConstraintData::is_relative() {
return get_spine_data()->isRelative(); return get_spine_data()->isRelative();
} }
bool SpineTransformConstraintData::is_local(){ bool SpineTransformConstraintData::is_local() {
return get_spine_data()->isLocal(); return get_spine_data()->isLocal();
} }

View File

@ -47,8 +47,8 @@ public:
SpineTransformConstraintData(); SpineTransformConstraintData();
~SpineTransformConstraintData(); ~SpineTransformConstraintData();
virtual inline spine::TransformConstraintData *get_spine_data(){ virtual inline spine::TransformConstraintData *get_spine_data() {
return (spine::TransformConstraintData*) SpineConstraintData::get_spine_object(); return (spine::TransformConstraintData *) SpineConstraintData::get_spine_object();
} }
Array get_bones(); Array get_bones();
@ -71,4 +71,4 @@ public:
bool is_local(); bool is_local();
}; };
#endif //GODOT_SPINETRANSFORMCONSTRAINTDATA_H #endif//GODOT_SPINETRANSFORMCONSTRAINTDATA_H

View File

@ -74,22 +74,22 @@ static Ref<ResourceFormatSaverSpineSkeletonJsonData> json_skeleton_saver;
#include "SpineRuntimeEditorPlugin.h" #include "SpineRuntimeEditorPlugin.h"
static void editor_init_callback() { static void editor_init_callback() {
EditorNode::get_singleton()->add_editor_plugin(memnew(SpineRuntimeEditorPlugin(EditorNode::get_singleton()))); EditorNode::get_singleton()->add_editor_plugin(memnew(SpineRuntimeEditorPlugin(EditorNode::get_singleton())));
} }
#endif #endif
void register_spine_godot_types(){ void register_spine_godot_types() {
#ifdef TOOLS_ENABLED #ifdef TOOLS_ENABLED
ClassDB::register_class<SpineSpriteAnimateDialog>(); ClassDB::register_class<SpineSpriteAnimateDialog>();
EditorNode::add_init_callback(editor_init_callback); EditorNode::add_init_callback(editor_init_callback);
#endif #endif
ClassDB::register_class<SpineAtlasResource>(); ClassDB::register_class<SpineAtlasResource>();
ClassDB::register_class<SpineSprite>(); ClassDB::register_class<SpineSprite>();
ClassDB::register_class<SpineSkeletonDataResource>(); ClassDB::register_class<SpineSkeletonDataResource>();
ClassDB::register_class<SpineAnimationStateDataResource>(); ClassDB::register_class<SpineAnimationStateDataResource>();
ClassDB::register_class<SpineSkeletonJsonDataResource>(); ClassDB::register_class<SpineSkeletonJsonDataResource>();
@ -120,26 +120,25 @@ void register_spine_godot_types(){
ClassDB::register_class<SpineConstant>(); ClassDB::register_class<SpineConstant>();
ClassDB::register_class<SpineCollisionShapeProxy>(); ClassDB::register_class<SpineCollisionShapeProxy>();
atlas_loader.instance(); atlas_loader.instance();
ResourceLoader::add_resource_format_loader(atlas_loader); ResourceLoader::add_resource_format_loader(atlas_loader);
atlas_saver.instance(); atlas_saver.instance();
ResourceSaver::add_resource_format_saver(atlas_saver); ResourceSaver::add_resource_format_saver(atlas_saver);
json_skeleton_loader.instance(); json_skeleton_loader.instance();
ResourceLoader::add_resource_format_loader(json_skeleton_loader); ResourceLoader::add_resource_format_loader(json_skeleton_loader);
json_skeleton_saver.instance(); json_skeleton_saver.instance();
ResourceSaver::add_resource_format_saver(json_skeleton_saver); ResourceSaver::add_resource_format_saver(json_skeleton_saver);
} }
void unregister_spine_godot_types(){ void unregister_spine_godot_types() {
ResourceLoader::remove_resource_format_loader(atlas_loader); ResourceLoader::remove_resource_format_loader(atlas_loader);
atlas_loader.unref(); atlas_loader.unref();
ResourceSaver::remove_resource_format_saver(atlas_saver); ResourceSaver::remove_resource_format_saver(atlas_saver);
atlas_saver.unref(); atlas_saver.unref();
ResourceLoader::remove_resource_format_loader(json_skeleton_loader); ResourceLoader::remove_resource_format_loader(json_skeleton_loader);
json_skeleton_loader.unref(); json_skeleton_loader.unref();

View File

@ -29,4 +29,3 @@
void register_spine_godot_types(); void register_spine_godot_types();
void unregister_spine_godot_types(); void unregister_spine_godot_types();

View File

@ -1095,24 +1095,24 @@ export enum EventType {
* {@link AnimationState#addListener()}. */ * {@link AnimationState#addListener()}. */
export interface AnimationStateListener { export interface AnimationStateListener {
/** Invoked when this entry has been set as the current entry. */ /** Invoked when this entry has been set as the current entry. */
start? (entry: TrackEntry): void; start?(entry: TrackEntry): void;
/** Invoked when another entry has replaced this entry as the current entry. This entry may continue being applied for /** Invoked when another entry has replaced this entry as the current entry. This entry may continue being applied for
* mixing. */ * mixing. */
interrupt? (entry: TrackEntry): void; interrupt?(entry: TrackEntry): void;
/** Invoked when this entry is no longer the current entry and will never be applied again. */ /** Invoked when this entry is no longer the current entry and will never be applied again. */
end? (entry: TrackEntry): void; end?(entry: TrackEntry): void;
/** Invoked when this entry will be disposed. This may occur without the entry ever being set as the current entry. /** Invoked when this entry will be disposed. This may occur without the entry ever being set as the current entry.
* References to the entry should not be kept after dispose is called, as it may be destroyed or reused. */ * References to the entry should not be kept after dispose is called, as it may be destroyed or reused. */
dispose? (entry: TrackEntry): void; dispose?(entry: TrackEntry): void;
/** Invoked every time this entry's animation completes a loop. */ /** Invoked every time this entry's animation completes a loop. */
complete? (entry: TrackEntry): void; complete?(entry: TrackEntry): void;
/** Invoked when this entry's animation triggers an event. */ /** Invoked when this entry's animation triggers an event. */
event? (entry: TrackEntry, event: Event): void; event?(entry: TrackEntry, event: Event): void;
} }
export abstract class AnimationStateAdapter implements AnimationStateListener { export abstract class AnimationStateAdapter implements AnimationStateListener {