From 5ec554413243ab7c3d4f52399525a4e6fe06bdb7 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Wed, 29 Sep 2021 12:43:40 +0200 Subject: [PATCH] [godot] Formatting --- formatters/build.gradle | 4 +- .../spine_godot/GodotSpineExtension.cpp | 50 +- spine-godot/spine_godot/GodotSpineExtension.h | 5 +- .../spine_godot/PackedSpineSkinResource.cpp | 14 +- .../spine_godot/PackedSpineSkinResource.h | 5 +- .../ResourceFormatLoaderSpineAtlas.cpp | 24 +- .../ResourceFormatLoaderSpineAtlas.h | 15 +- ...ourceFormatLoaderSpineSkeletonJsonData.cpp | 24 +- ...esourceFormatLoaderSpineSkeletonJsonData.h | 11 +- .../ResourceFormatSaverSpineAtlas.cpp | 14 +- .../ResourceFormatSaverSpineAtlas.h | 13 +- ...sourceFormatSaverSpineSkeletonJsonData.cpp | 14 +- ...ResourceFormatSaverSpineSkeletonJsonData.h | 13 +- spine-godot/spine_godot/SpineAnimation.cpp | 50 +- spine-godot/spine_godot/SpineAnimation.h | 14 +- .../spine_godot/SpineAnimationState.cpp | 41 +- spine-godot/spine_godot/SpineAnimationState.h | 13 +- .../SpineAnimationStateDataResource.cpp | 65 +- .../SpineAnimationStateDataResource.h | 8 +- .../spine_godot/SpineAtlasResource.cpp | 212 +++-- spine-godot/spine_godot/SpineAtlasResource.h | 38 +- spine-godot/spine_godot/SpineAttachment.cpp | 10 +- spine-godot/spine_godot/SpineAttachment.h | 8 +- spine-godot/spine_godot/SpineBone.cpp | 453 +++++----- spine-godot/spine_godot/SpineBone.h | 7 +- spine-godot/spine_godot/SpineBoneData.cpp | 54 +- spine-godot/spine_godot/SpineBoneData.h | 7 +- .../spine_godot/SpineCollisionShapeProxy.cpp | 200 ++--- .../spine_godot/SpineCollisionShapeProxy.h | 50 +- spine-godot/spine_godot/SpineConstant.cpp | 52 +- spine-godot/spine_godot/SpineConstant.h | 71 +- .../spine_godot/SpineConstraintData.cpp | 12 +- spine-godot/spine_godot/SpineConstraintData.h | 6 +- spine-godot/spine_godot/SpineEvent.cpp | 42 +- spine-godot/spine_godot/SpineEvent.h | 12 +- spine-godot/spine_godot/SpineEventData.cpp | 5 +- spine-godot/spine_godot/SpineEventData.h | 10 +- spine-godot/spine_godot/SpineIkConstraint.cpp | 48 +- spine-godot/spine_godot/SpineIkConstraint.h | 9 +- .../spine_godot/SpineIkConstraintData.cpp | 40 +- .../spine_godot/SpineIkConstraintData.h | 7 +- .../spine_godot/SpinePathConstraint.cpp | 50 +- spine-godot/spine_godot/SpinePathConstraint.h | 10 +- .../spine_godot/SpinePathConstraintData.cpp | 58 +- .../spine_godot/SpinePathConstraintData.h | 6 +- spine-godot/spine_godot/SpineRendererObject.h | 6 +- .../spine_godot/SpineRuntimeEditorPlugin.cpp | 71 +- .../spine_godot/SpineRuntimeEditorPlugin.h | 61 +- spine-godot/spine_godot/SpineSkeleton.cpp | 273 +++--- spine-godot/spine_godot/SpineSkeleton.h | 13 +- .../spine_godot/SpineSkeletonDataResource.cpp | 206 ++--- .../spine_godot/SpineSkeletonDataResource.h | 24 +- .../SpineSkeletonJsonDataResource.cpp | 24 +- .../SpineSkeletonJsonDataResource.h | 15 +- spine-godot/spine_godot/SpineSkin.cpp | 59 +- spine-godot/spine_godot/SpineSkin.h | 6 +- .../SpineSkinAttachmentMapEntries.cpp | 28 +- .../SpineSkinAttachmentMapEntries.h | 10 +- spine-godot/spine_godot/SpineSlot.cpp | 46 +- spine-godot/spine_godot/SpineSlot.h | 8 +- spine-godot/spine_godot/SpineSlotData.cpp | 28 +- spine-godot/spine_godot/SpineSlotData.h | 6 +- spine-godot/spine_godot/SpineSprite.cpp | 825 +++++++++--------- spine-godot/spine_godot/SpineSprite.h | 46 +- .../spine_godot/SpineSpriteAnimateDialog.cpp | 445 +++++----- .../spine_godot/SpineSpriteAnimateDialog.h | 61 +- .../spine_godot/SpineSpriteMeshInstance2D.cpp | 2 +- .../spine_godot/SpineSpriteMeshInstance2D.h | 5 +- spine-godot/spine_godot/SpineTimeline.cpp | 66 +- spine-godot/spine_godot/SpineTimeline.h | 39 +- spine-godot/spine_godot/SpineTrackEntry.cpp | 96 +- spine-godot/spine_godot/SpineTrackEntry.h | 12 +- .../spine_godot/SpineTransformConstraint.cpp | 52 +- .../spine_godot/SpineTransformConstraint.h | 8 +- .../SpineTransformConstraintData.cpp | 38 +- .../SpineTransformConstraintData.h | 6 +- spine-godot/spine_godot/register_types.cpp | 31 +- spine-godot/spine_godot/register_types.h | 1 - spine-ts/spine-core/src/AnimationState.ts | 12 +- 79 files changed, 2235 insertions(+), 2268 deletions(-) diff --git a/formatters/build.gradle b/formatters/build.gradle index 1d57bab85..102f44cc3 100644 --- a/formatters/build.gradle +++ b/formatters/build.gradle @@ -25,7 +25,9 @@ spotless { 'spine-sfml/**/*.cpp', 'spine-sfml/**/*.h', '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') } diff --git a/spine-godot/spine_godot/GodotSpineExtension.cpp b/spine-godot/spine_godot/GodotSpineExtension.cpp index 87ce758a1..6813a2cc2 100644 --- a/spine-godot/spine_godot/GodotSpineExtension.cpp +++ b/spine-godot/spine_godot/GodotSpineExtension.cpp @@ -35,42 +35,42 @@ #include 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){ - return memalloc(size); +void *GodotSpineExtension::_alloc(size_t size, const char *file, int line) { + return memalloc(size); } -void *GodotSpineExtension::_calloc(size_t size, const char *file, int line){ - auto p = memalloc(size); - memset(p, 0, size); - return p; +void *GodotSpineExtension::_calloc(size_t size, const char *file, int line) { + auto p = memalloc(size); + memset(p, 0, size); + return p; } -void *GodotSpineExtension::_realloc(void *ptr, size_t size, const char *file, int line){ - return memrealloc(ptr, size); +void *GodotSpineExtension::_realloc(void *ptr, size_t size, const char *file, int line) { + return memrealloc(ptr, size); } -void GodotSpineExtension::_free(void *mem, const char *file, int line){ - memfree(mem); +void GodotSpineExtension::_free(void *mem, const char *file, int line) { + memfree(mem); } -char *GodotSpineExtension::_readFile(const spine::String &path, int *length){ - Error error; - auto res = FileAccess::get_file_as_array(String(path.buffer()), &error); +char *GodotSpineExtension::_readFile(const spine::String &path, int *length) { + Error error; + auto res = FileAccess::get_file_as_array(String(path.buffer()), &error); - if (error != OK){ - if(length) *length = 0; - return NULL; - } + if (error != OK) { + if (length) *length = 0; + return NULL; + } - if(length) *length = res.size(); - auto r = alloc(res.size(), __FILE__, __LINE__); - for(size_t i=0;i(res.size(), __FILE__, __LINE__); + for (size_t i = 0; i < res.size(); ++i) + r[i] = res[i]; + return r; } \ No newline at end of file diff --git a/spine-godot/spine_godot/GodotSpineExtension.h b/spine-godot/spine_godot/GodotSpineExtension.h index 1d2bca6be..e00726051 100644 --- a/spine-godot/spine_godot/GodotSpineExtension.h +++ b/spine-godot/spine_godot/GodotSpineExtension.h @@ -51,7 +51,4 @@ protected: }; - - - -#endif //GODOT_SPINEEXTENSION_H +#endif//GODOT_SPINEEXTENSION_H diff --git a/spine-godot/spine_godot/PackedSpineSkinResource.cpp b/spine-godot/spine_godot/PackedSpineSkinResource.cpp index 34bababcb..1521f1770 100644 --- a/spine-godot/spine_godot/PackedSpineSkinResource.cpp +++ b/spine-godot/spine_godot/PackedSpineSkinResource.cpp @@ -29,7 +29,7 @@ #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("get_skin_name"), &PackedSpineSkinResource::get_skin_name); 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"); } -PackedSpineSkinResource::PackedSpineSkinResource():skin_name("custom_skin_name"){} -PackedSpineSkinResource::~PackedSpineSkinResource(){} +PackedSpineSkinResource::PackedSpineSkinResource() : skin_name("custom_skin_name") {} +PackedSpineSkinResource::~PackedSpineSkinResource() {} -void PackedSpineSkinResource::set_skin_name(const String &v){ +void PackedSpineSkinResource::set_skin_name(const String &v) { skin_name = v; emit_signal("property_changed"); } -String PackedSpineSkinResource::get_skin_name(){ +String PackedSpineSkinResource::get_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; emit_signal("property_changed"); } -Array PackedSpineSkinResource::get_sub_skin_names(){ +Array PackedSpineSkinResource::get_sub_skin_names() { return sub_skin_names; } diff --git a/spine-godot/spine_godot/PackedSpineSkinResource.h b/spine-godot/spine_godot/PackedSpineSkinResource.h index a4cc5ff3f..f3e979c2b 100644 --- a/spine-godot/spine_godot/PackedSpineSkinResource.h +++ b/spine-godot/spine_godot/PackedSpineSkinResource.h @@ -34,7 +34,7 @@ #include "SpineSkin.h" -class PackedSpineSkinResource : public Resource{ +class PackedSpineSkinResource : public Resource { GDCLASS(PackedSpineSkinResource, Resource); protected: @@ -53,7 +53,6 @@ public: void set_sub_skin_names(Array v); Array get_sub_skin_names(); - }; -#endif //GODOT_PACKEDSPINESKINRESOURCE_H +#endif//GODOT_PACKEDSPINESKINRESOURCE_H diff --git a/spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.cpp b/spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.cpp index 7524071d4..f3c5c8ada 100644 --- a/spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.cpp +++ b/spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.cpp @@ -31,26 +31,26 @@ #include "SpineAtlasResource.h" RES ResourceFormatLoaderSpineAtlas::load(const String &p_path, const String &p_original_path, Error *r_error) { - Ref atlas = memnew(SpineAtlasResource); - atlas->load_from_file(p_path); + Ref atlas = memnew(SpineAtlasResource); + atlas->load_from_file(p_path); - if(r_error){ - *r_error = OK; - } - return atlas; + if (r_error) { + *r_error = OK; + } + return atlas; } void ResourceFormatLoaderSpineAtlas::get_recognized_extensions(List *r_extensions) const { - const char atlas_ext[] = "spatlas"; - if(!r_extensions->find(atlas_ext)) { - r_extensions->push_back(atlas_ext); - } + const char atlas_ext[] = "spatlas"; + if (!r_extensions->find(atlas_ext)) { + r_extensions->push_back(atlas_ext); + } } String ResourceFormatLoaderSpineAtlas::get_resource_type(const String &p_path) const { - return "SpineAtlasResource"; + return "SpineAtlasResource"; } 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"); } \ No newline at end of file diff --git a/spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.h b/spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.h index e6d1610da..27133afca 100644 --- a/spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.h +++ b/spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.h @@ -32,14 +32,15 @@ #include "core/io/resource_loader.h" -class ResourceFormatLoaderSpineAtlas : public ResourceFormatLoader{ - GDCLASS(ResourceFormatLoaderSpineAtlas, ResourceFormatLoader); +class ResourceFormatLoaderSpineAtlas : public ResourceFormatLoader { + GDCLASS(ResourceFormatLoaderSpineAtlas, ResourceFormatLoader); + public: - virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL); - virtual void get_recognized_extensions(List *r_extensions) const; - virtual bool handles_type(const String &p_type) const; - virtual String get_resource_type(const String &p_path) const; + virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL); + virtual void get_recognized_extensions(List *r_extensions) const; + virtual bool handles_type(const String &p_type) const; + virtual String get_resource_type(const String &p_path) const; }; -#endif //GODOT_RESOURCEFORMATLOADERSPINEATLAS_H +#endif//GODOT_RESOURCEFORMATLOADERSPINEATLAS_H diff --git a/spine-godot/spine_godot/ResourceFormatLoaderSpineSkeletonJsonData.cpp b/spine-godot/spine_godot/ResourceFormatLoaderSpineSkeletonJsonData.cpp index 34a7a7ae2..9c1cc80e5 100644 --- a/spine-godot/spine_godot/ResourceFormatLoaderSpineSkeletonJsonData.cpp +++ b/spine-godot/spine_godot/ResourceFormatLoaderSpineSkeletonJsonData.cpp @@ -31,26 +31,26 @@ #include "SpineSkeletonJsonDataResource.h" RES ResourceFormatLoaderSpineSkeletonJsonData::load(const String &p_path, const String &p_original_path, Error *r_error) { - Ref skeleton = memnew(SpineSkeletonJsonDataResource); - skeleton->load_from_file(p_path); + Ref skeleton = memnew(SpineSkeletonJsonDataResource); + skeleton->load_from_file(p_path); - if(r_error){ - *r_error = OK; - } - return skeleton; + if (r_error) { + *r_error = OK; + } + return skeleton; } void ResourceFormatLoaderSpineSkeletonJsonData::get_recognized_extensions(List *r_extensions) const { - const char json_ext[] = "spjson"; - if(!r_extensions->find(json_ext)) { - r_extensions->push_back(json_ext); - } + const char json_ext[] = "spjson"; + if (!r_extensions->find(json_ext)) { + r_extensions->push_back(json_ext); + } } String ResourceFormatLoaderSpineSkeletonJsonData::get_resource_type(const String &p_path) const { - return "SpineSkeletonJsonDataResource"; + return "SpineSkeletonJsonDataResource"; } 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"); } \ No newline at end of file diff --git a/spine-godot/spine_godot/ResourceFormatLoaderSpineSkeletonJsonData.h b/spine-godot/spine_godot/ResourceFormatLoaderSpineSkeletonJsonData.h index 13509ba21..9736655f6 100644 --- a/spine-godot/spine_godot/ResourceFormatLoaderSpineSkeletonJsonData.h +++ b/spine-godot/spine_godot/ResourceFormatLoaderSpineSkeletonJsonData.h @@ -34,11 +34,12 @@ class ResourceFormatLoaderSpineSkeletonJsonData : public ResourceFormatLoader { GDCLASS(ResourceFormatLoaderSpineSkeletonJsonData, ResourceFormatLoader); + public: - virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL); - virtual void get_recognized_extensions(List *r_extensions) const; - virtual bool handles_type(const String &p_type) const; - virtual String get_resource_type(const String &p_path) const; + virtual RES load(const String &p_path, const String &p_original_path, Error *r_error = NULL); + virtual void get_recognized_extensions(List *r_extensions) const; + virtual bool handles_type(const String &p_type) const; + virtual String get_resource_type(const String &p_path) const; }; -#endif //GODOT_RESOURCEFORMATLOADERSPINESKELETONJSONDATA_H +#endif//GODOT_RESOURCEFORMATLOADERSPINESKELETONJSONDATA_H diff --git a/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.cpp b/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.cpp index d976133a1..ef051f31c 100644 --- a/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.cpp +++ b/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.cpp @@ -32,17 +32,17 @@ #include "SpineAtlasResource.h" Error ResourceFormatSaverSpineAtlas::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - Ref res = p_resource.get_ref_ptr(); - Error error = res->save_to_file(p_path); - return error; + Ref res = p_resource.get_ref_ptr(); + Error error = res->save_to_file(p_path); + return error; } void ResourceFormatSaverSpineAtlas::get_recognized_extensions(const RES &p_resource, List *p_extensions) const { - if (Object::cast_to(*p_resource)) { - p_extensions->push_back("spatlas"); - } + if (Object::cast_to(*p_resource)) { + p_extensions->push_back("spatlas"); + } } bool ResourceFormatSaverSpineAtlas::recognize(const RES &p_resource) const { - return Object::cast_to(*p_resource) != nullptr; + return Object::cast_to(*p_resource) != nullptr; } diff --git a/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.h b/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.h index 4feb076fc..b20420772 100644 --- a/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.h +++ b/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.h @@ -32,13 +32,14 @@ #include "core/io/resource_saver.h" -class ResourceFormatSaverSpineAtlas : public ResourceFormatSaver{ - GDCLASS(ResourceFormatSaverSpineAtlas, ResourceFormatSaver); +class ResourceFormatSaverSpineAtlas : public ResourceFormatSaver { + GDCLASS(ResourceFormatSaverSpineAtlas, ResourceFormatSaver); + public: - 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 *p_extensions) const override; - bool recognize(const RES &p_resource) const 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 *p_extensions) const override; + bool recognize(const RES &p_resource) const override; }; -#endif //GODOT_RESOURCEFORMATSAVERSPINEATLAS_H +#endif//GODOT_RESOURCEFORMATSAVERSPINEATLAS_H diff --git a/spine-godot/spine_godot/ResourceFormatSaverSpineSkeletonJsonData.cpp b/spine-godot/spine_godot/ResourceFormatSaverSpineSkeletonJsonData.cpp index 01c4b7e1c..5fa669c04 100644 --- a/spine-godot/spine_godot/ResourceFormatSaverSpineSkeletonJsonData.cpp +++ b/spine-godot/spine_godot/ResourceFormatSaverSpineSkeletonJsonData.cpp @@ -32,17 +32,17 @@ #include "SpineSkeletonJsonDataResource.h" Error ResourceFormatSaverSpineSkeletonJsonData::save(const String &p_path, const RES &p_resource, uint32_t p_flags) { - Ref res = p_resource.get_ref_ptr(); - Error error = res->save_to_file(p_path); - return error; + Ref res = p_resource.get_ref_ptr(); + Error error = res->save_to_file(p_path); + return error; } void ResourceFormatSaverSpineSkeletonJsonData::get_recognized_extensions(const RES &p_resource, List *p_extensions) const { - if (Object::cast_to(*p_resource)) { - p_extensions->push_back("spjson"); - } + if (Object::cast_to(*p_resource)) { + p_extensions->push_back("spjson"); + } } bool ResourceFormatSaverSpineSkeletonJsonData::recognize(const RES &p_resource) const { - return Object::cast_to(*p_resource) != nullptr; + return Object::cast_to(*p_resource) != nullptr; } diff --git a/spine-godot/spine_godot/ResourceFormatSaverSpineSkeletonJsonData.h b/spine-godot/spine_godot/ResourceFormatSaverSpineSkeletonJsonData.h index e63993125..2c42ee5d0 100644 --- a/spine-godot/spine_godot/ResourceFormatSaverSpineSkeletonJsonData.h +++ b/spine-godot/spine_godot/ResourceFormatSaverSpineSkeletonJsonData.h @@ -32,13 +32,14 @@ #include "core/io/resource_saver.h" -class ResourceFormatSaverSpineSkeletonJsonData : public ResourceFormatSaver{ - GDCLASS(ResourceFormatSaverSpineSkeletonJsonData, ResourceFormatSaver); +class ResourceFormatSaverSpineSkeletonJsonData : public ResourceFormatSaver { + GDCLASS(ResourceFormatSaverSpineSkeletonJsonData, ResourceFormatSaver); + public: - 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 *p_extensions) const override; - bool recognize(const RES &p_resource) const 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 *p_extensions) const override; + bool recognize(const RES &p_resource) const override; }; -#endif //GODOT_RESOURCEFORMATSAVERSPINESKELETONJSONDATA_H +#endif//GODOT_RESOURCEFORMATSAVERSPINESKELETONJSONDATA_H diff --git a/spine-godot/spine_godot/SpineAnimation.cpp b/spine-godot/spine_godot/SpineAnimation.cpp index d0e76d54e..a646460f1 100644 --- a/spine-godot/spine_godot/SpineAnimation.cpp +++ b/spine-godot/spine_godot/SpineAnimation.cpp @@ -46,8 +46,8 @@ void SpineAnimation::_bind_methods() { ClassDB::bind_method(D_METHOD("has_timeline", "ids"), &SpineAnimation::has_timeline); } -SpineAnimation::SpineAnimation():animation(NULL) {} -SpineAnimation::~SpineAnimation(){} +SpineAnimation::SpineAnimation() : animation(NULL) {} +SpineAnimation::~SpineAnimation() {} String SpineAnimation::get_anim_name() { return animation->getName().buffer(); @@ -61,36 +61,36 @@ void SpineAnimation::set_duration(float v) { } void SpineAnimation::apply(Ref skeleton, float lastTime, float time, bool loop, - Array pEvents, float alpha, SpineConstant::MixBlend blend, - SpineConstant::MixDirection direction) { - spine::Vector events; - events.setSize(pEvents.size(), nullptr); - for (size_t i=0; i)(pEvents[i]))->get_spine_object(); - } - animation->apply(*(skeleton->get_spine_object()), lastTime, time, loop, &events, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction); + Array pEvents, float alpha, SpineConstant::MixBlend blend, + SpineConstant::MixDirection direction) { + spine::Vector events; + events.setSize(pEvents.size(), nullptr); + for (size_t i = 0; i < events.size(); ++i) { + events[i] = ((Ref) (pEvents[i]))->get_spine_object(); + } + animation->apply(*(skeleton->get_spine_object()), lastTime, time, loop, &events, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction); } Array SpineAnimation::get_timelines() { - auto &timelines = animation->getTimelines(); - Array res; - res.resize(timelines.size()); + auto &timelines = animation->getTimelines(); + Array res; + res.resize(timelines.size()); - for (size_t i=0; i(memnew(SpineTimeline)); - a->set_spine_object(timelines[i]); - res.set(i, a); - } + for (size_t i = 0; i < res.size(); ++i) { + auto a = Ref(memnew(SpineTimeline)); + a->set_spine_object(timelines[i]); + res.set(i, a); + } - return res; + return res; } bool SpineAnimation::has_timeline(Array ids) { - spine::Vector list; - list.setSize(ids.size(), 0); + spine::Vector list; + list.setSize(ids.size(), 0); - for (size_t i=0; ihasTimeline(list); + for (size_t i = 0; i < list.size(); ++i) { + list[i] = ids[i]; + } + return animation->hasTimeline(list); } diff --git a/spine-godot/spine_godot/SpineAnimation.h b/spine-godot/spine_godot/SpineAnimation.h index 22b330f8b..98dbed587 100644 --- a/spine-godot/spine_godot/SpineAnimation.h +++ b/spine-godot/spine_godot/SpineAnimation.h @@ -40,7 +40,7 @@ class SpineEvent; class SpineSkeleton; class SpineTimeline; -class SpineAnimation : public Reference{ +class SpineAnimation : public Reference { GDCLASS(SpineAnimation, Reference); private: @@ -53,22 +53,22 @@ public: SpineAnimation(); ~SpineAnimation(); - inline void set_spine_object(spine::Animation *a){ + inline void set_spine_object(spine::Animation *a) { animation = a; } - inline spine::Animation *get_spine_object(){ + inline spine::Animation *get_spine_object() { return animation; } // Vector> pEvents - void apply(Ref skeleton, float lastTime, float time, bool loop, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction); + void apply(Ref skeleton, float lastTime, float time, bool loop, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction); - Array get_timelines(); // Vector> - bool has_timeline(Array ids); // Vector + Array get_timelines(); // Vector> + bool has_timeline(Array ids);// Vector String get_anim_name(); float get_duration(); void set_duration(float v); }; -#endif //GODOT_SPINEANIMATION_H +#endif//GODOT_SPINEANIMATION_H diff --git a/spine-godot/spine_godot/SpineAnimationState.cpp b/spine-godot/spine_godot/SpineAnimationState.cpp index 0dcbaa107..2d9f6c8f6 100644 --- a/spine-godot/spine_godot/SpineAnimationState.cpp +++ b/spine-godot/spine_godot/SpineAnimationState.cpp @@ -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("disable_queue"), &SpineAnimationState::disable_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); } -SpineAnimationState::SpineAnimationState():animation_state(NULL) { - +SpineAnimationState::SpineAnimationState() : animation_state(NULL) { } SpineAnimationState::~SpineAnimationState() { - if(animation_state) - { + if (animation_state) { delete animation_state; animation_state = NULL; } } void SpineAnimationState::load_animation_state(Ref ad) { - if(animation_state) - { + if (animation_state) { delete animation_state; animation_state = NULL; } @@ -71,28 +68,33 @@ void SpineAnimationState::load_animation_state(Refget_animation_state_data()); } -#define CHECK_V 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 CHECK_V \ + 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())) Ref SpineAnimationState::set_animation(const String &anim_name, bool loop, uint64_t track) { CHECK_X(NULL); auto skeleton_data = anim_state_data_res->get_skeleton(); 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) return NULL; } @@ -105,8 +107,7 @@ Ref SpineAnimationState::add_animation(const String &anim_name, CHECK_X(NULL); auto skeleton_data = anim_state_data_res->get_skeleton(); 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) return NULL; } @@ -135,11 +136,11 @@ void SpineAnimationState::set_empty_animations(float mix_duration) { animation_state->setEmptyAnimations(mix_duration); } -void SpineAnimationState::update(float delta){ +void SpineAnimationState::update(float delta) { CHECK_V; animation_state->update(delta); } -bool SpineAnimationState::apply(Ref skeleton){ +bool SpineAnimationState::apply(Ref skeleton) { CHECK_X(false); return animation_state->apply(*(skeleton->get_spine_object())); } @@ -181,7 +182,7 @@ Ref SpineAnimationState::get_current(uint64_t track_index) { CHECK_X(NULL); Ref gd_entry(memnew(SpineTrackEntry)); auto entry = animation_state->getCurrent(track_index); - if(entry == NULL) return NULL; + if (entry == NULL) return NULL; gd_entry->set_spine_object(entry); return gd_entry; } diff --git a/spine-godot/spine_godot/SpineAnimationState.h b/spine-godot/spine_godot/SpineAnimationState.h index 531a63472..097be72ac 100644 --- a/spine-godot/spine_godot/SpineAnimationState.h +++ b/spine-godot/spine_godot/SpineAnimationState.h @@ -36,7 +36,7 @@ #include "SpineSkeleton.h" #include "SpineTrackEntry.h" -class SpineAnimationState : public Reference{ +class SpineAnimationState : public Reference { GDCLASS(SpineAnimationState, Reference); protected: @@ -46,21 +46,22 @@ private: spine::AnimationState *animation_state; Ref anim_state_data_res; + public: void load_animation_state(Ref ad); - inline void set_animation_state(spine::AnimationState *a){ + inline void set_animation_state(spine::AnimationState *a) { animation_state = a; } - inline spine::AnimationState *get_animation_state(){ + inline spine::AnimationState *get_animation_state() { return animation_state; } void reload_animation_state(); Ref set_animation(const String &anim_name, bool loop, uint64_t track_id); - inline void set_animation_by_ref(Ref anim, bool loop, uint64_t track_id){ - if(anim.is_valid()){ + inline void set_animation_by_ref(Ref anim, bool loop, uint64_t track_id) { + if (anim.is_valid()) { animation_state->setAnimation(track_id, anim->get_spine_object(), loop); } } @@ -90,4 +91,4 @@ public: ~SpineAnimationState(); }; -#endif //GODOT_SPINEANIMATIONSTATE_H +#endif//GODOT_SPINEANIMATIONSTATE_H diff --git a/spine-godot/spine_godot/SpineAnimationStateDataResource.cpp b/spine-godot/spine_godot/SpineAnimationStateDataResource.cpp index c17a1d585..de4041ec2 100644 --- a/spine-godot/spine_godot/SpineAnimationStateDataResource.cpp +++ b/spine-godot/spine_godot/SpineAnimationStateDataResource.cpp @@ -29,12 +29,10 @@ #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() { - if(animation_state_data) - { + if (animation_state_data) { delete animation_state_data; animation_state_data = NULL; } @@ -63,27 +61,22 @@ void SpineAnimationStateDataResource::set_skeleton(const Refconnect("skeleton_data_loaded", this, "_on_skeleton_data_loaded"); skeleton->connect("atlas_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(); } - }else{ - if(animation_state_data) - { + } else { + if (animation_state_data) { delete animation_state_data; animation_state_data = NULL; animation_state_data_created = false; -// print_line("Animation state data deleted."); + // print_line("Animation state data deleted."); } } - - } Ref SpineAnimationStateDataResource::get_skeleton() { return skeleton; @@ -91,18 +84,17 @@ Ref SpineAnimationStateDataResource::get_skeleton() { void SpineAnimationStateDataResource::set_default_mix(float m) { default_mix = m; - if(!is_animation_state_data_created()) - { -// ERR_PRINT("'set_default_mix' fail. Animation state data is not created!"); + if (!is_animation_state_data_created()) { + // ERR_PRINT("'set_default_mix' fail. Animation state data is not created!"); return; } - animation_state_data->setDefaultMix(((m >= 0 && m <= 1) ? m : m <= 0 ? 0 : 1)); -// emit_signal("animation_state_data_changed"); + animation_state_data->setDefaultMix(((m >= 0 && m <= 1) ? m : m <= 0 ? 0 + : 1)); + // emit_signal("animation_state_data_changed"); } float SpineAnimationStateDataResource::get_default_mix() { - if(!is_animation_state_data_created()) - { -// ERR_PRINT("'get_default_mix' fail. Animation state data is not created!"); + if (!is_animation_state_data_created()) { + // ERR_PRINT("'get_default_mix' fail. Animation state data is not created!"); return default_mix; } 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) { - if(!is_animation_state_data_created()) - { + if (!is_animation_state_data_created()) { ERR_PRINT("'set_mix' fail. Animation state data is not created!"); return; } auto anim_from = get_skeleton()->find_animation(from); 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!"); return; } - if(!anim_to.is_valid()) - { + if (!anim_to.is_valid()) { ERR_PRINT("'set_mix' fail. To animation animation not found!"); return; } 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) { - if(!is_animation_state_data_created()) - { + if (!is_animation_state_data_created()) { ERR_PRINT("'set_mix' fail. Animation state data is not created!"); return 0; } auto anim_from = get_skeleton()->find_animation(from); 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!"); return 0; } - if(!anim_to.is_valid()) - { + if (!anim_to.is_valid()) { ERR_PRINT("'set_mix' fail. To animation animation not found!"); return 0; } @@ -152,7 +138,7 @@ float SpineAnimationStateDataResource::get_mix(const String &from, const String void SpineAnimationStateDataResource::_on_skeleton_data_loaded() { 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"); @@ -162,17 +148,16 @@ void SpineAnimationStateDataResource::_on_skeleton_data_loaded() { void SpineAnimationStateDataResource::_on_skeleton_data_changed() { animation_state_data_created = false; - if(animation_state_data) - { + if (animation_state_data) { delete animation_state_data; 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"); } -bool SpineAnimationStateDataResource::is_animation_state_data_created(){ +bool SpineAnimationStateDataResource::is_animation_state_data_created() { return animation_state_data_created; } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpineAnimationStateDataResource.h b/spine-godot/spine_godot/SpineAnimationStateDataResource.h index 9da9f8fe2..58f0cd536 100644 --- a/spine-godot/spine_godot/SpineAnimationStateDataResource.h +++ b/spine-godot/spine_godot/SpineAnimationStateDataResource.h @@ -34,7 +34,7 @@ #include "SpineSkeletonDataResource.h" -class SpineAnimationStateDataResource : public Resource{ +class SpineAnimationStateDataResource : public Resource { GDCLASS(SpineAnimationStateDataResource, Resource); protected: @@ -48,12 +48,12 @@ private: bool animation_state_data_created; float default_mix; -public: +public: void set_skeleton(const Ref &s); Ref get_skeleton(); - inline spine::AnimationStateData *get_animation_state_data(){ + inline spine::AnimationStateData *get_animation_state_data() { return animation_state_data; } @@ -73,4 +73,4 @@ public: ~SpineAnimationStateDataResource(); }; -#endif //GODOT_SPINEANIMATIONSTATEDATARESOURCE_H +#endif//GODOT_SPINEANIMATIONSTATEDATARESOURCE_H diff --git a/spine-godot/spine_godot/SpineAtlasResource.cpp b/spine-godot/spine_godot/SpineAtlasResource.cpp index 08177ac2c..91eb5828f 100644 --- a/spine-godot/spine_godot/SpineAtlasResource.cpp +++ b/spine-godot/spine_godot/SpineAtlasResource.cpp @@ -34,97 +34,93 @@ class GodotSpineTextureLoader : public spine::TextureLoader { private: - Array *tex_list, *ntex_list; - String normal_tex_prefix; + Array *textures, *normal_maps; + String normal_maps_prefix; + 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){ - if (tex_list) tex_list->clear(); - if (ntex_list) ntex_list->clear(); - } + String fixPathIssue(const String &path) { + if (path.size() > 5 && path[4] == '/' && path[5] == '/') return path; + 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(path.size() > 5 && path[4] == '/' && path[5] == '/') return path; - const String prefix = "res:/"; - auto i = path.find(prefix); -// print_line(String("Found i at ") + String(Variant(i))); - auto sub_str_pos = i+prefix.size()-1; - if(sub_str_pos < 0) return path; - auto res = path.substr(sub_str_pos); -// print_line(String("rest of it: ") + res); - if(res.size() > 0) - { - if(res[0] != '/') - { - return prefix + "/" + res; - } else - { - return prefix + res; - } - } - return path; - } + 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){ - Error err = OK; + virtual void load(spine::AtlasPage &page, const spine::String &path) { + Error err = OK; -// print_line(String("Spine is loading texture: ") + String(path.buffer())); - auto fixed_path = fixPathIssue(String(path.buffer())); -// print_line("Fixed path: " + fixed_path); + // print_line(String("Spine is loading texture: ") + String(path.buffer())); + auto fixed_path = fixPathIssue(String(path.buffer())); + // print_line("Fixed path: " + fixed_path); // Load texture (e.g. tex.png) Ref tex = ResourceLoader::load(fixed_path, "", false, &err); if (err != OK) { - print_error(vformat("Can't load texture: \"%s\"", String(path.buffer()))); - page.setRendererObject((void*)memnew(SpineRendererObject {nullptr})); - return; + print_error(vformat("Can't load texture: \"%s\"", String(path.buffer()))); + page.setRendererObject((void *) memnew(SpineRendererObject{nullptr})); + return; } - if (tex_list) tex_list->append(tex); + if (textures) textures->append(tex); auto p_spine_renderer_object = memnew(SpineRendererObject); p_spine_renderer_object->tex = tex; // Load normal texture (e.g. n_tex.png) String temppath = fixed_path; - String newpath = vformat("%s/%s_%s", temppath.get_base_dir(), normal_tex_prefix, temppath.get_file()); -// print_line(vformat("try n tex: %s", newpath)); - if (ResourceLoader::exists(newpath)){ + String newpath = vformat("%s/%s_%s", temppath.get_base_dir(), normal_maps_prefix, temppath.get_file()); + // print_line(vformat("try n tex: %s", newpath)); + if (ResourceLoader::exists(newpath)) { Ref 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; // 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))); } - page.setRendererObject((void*)p_spine_renderer_object); + page.setRendererObject((void *) p_spine_renderer_object); page.width = tex->get_width(); page.height = tex->get_height(); - } + } - virtual void unload(void *p){ + virtual void unload(void *p) { // print_line("I'm out."); - auto p_spine_renderer_object = (SpineRendererObject*) p; - Ref &tex = p_spine_renderer_object->tex; + auto p_spine_renderer_object = (SpineRendererObject *) p; + Ref &tex = p_spine_renderer_object->tex; Ref &normal_tex = p_spine_renderer_object->normal_tex; if (tex.is_valid()) tex.unref(); if (normal_tex.is_valid()) normal_tex.unref(); memdelete(p_spine_renderer_object); - } + } }; -SpineAtlasResource::SpineAtlasResource():atlas(nullptr), normal_texture_prefix("n"){} -SpineAtlasResource::~SpineAtlasResource(){ - if (atlas) delete atlas; +SpineAtlasResource::SpineAtlasResource() : atlas(nullptr), normal_texture_prefix("n") {} +SpineAtlasResource::~SpineAtlasResource() { + if (atlas) delete atlas; } -void SpineAtlasResource::_bind_methods(){ - ClassDB::bind_method(D_METHOD("load_from_atlas_file", "path"), &SpineAtlasResource::load_from_atlas_file); +void SpineAtlasResource::_bind_methods() { + 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_normal_textures"), &SpineAtlasResource::get_normal_textures); @@ -140,90 +136,90 @@ Array SpineAtlasResource::get_textures() { } Array SpineAtlasResource::get_normal_textures() { - return ntex_list; + return ntex_list; } String SpineAtlasResource::get_source_path() { - return source_path; + return source_path; } Error SpineAtlasResource::load_from_atlas_file(const String &p_path) { -// print_line(vformat("Importing atlas file: %s", p_path)); - source_path = p_path; + // print_line(vformat("Importing atlas file: %s", p_path)); + source_path = p_path; - Error err; + Error err; - atlas_data = FileAccess::get_file_as_string(p_path, &err); - if (err != OK) return err; + atlas_data = FileAccess::get_file_as_string(p_path, &err); + if (err != OK) return err; - if (atlas) delete atlas; - tex_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)); + if (atlas) delete atlas; + tex_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)); -// print_line(vformat("atlas loaded!")); + // print_line(vformat("atlas loaded!")); - if (atlas) - return OK; + if (atlas) + return OK; - tex_list.clear(); - ntex_list.clear(); + tex_list.clear(); + ntex_list.clear(); - return ERR_FILE_UNRECOGNIZED; + return ERR_FILE_UNRECOGNIZED; } Error SpineAtlasResource::load_from_file(const String &p_path) { - Error err; + Error err; - String json_string = FileAccess::get_file_as_string(p_path, &err); - if (err != OK) return err; + String json_string = FileAccess::get_file_as_string(p_path, &err); + if (err != OK) return err; - String error_string; - int error_line; - JSON json; - Variant result; - err = json.parse(json_string, result, error_string, error_line); - if (err != OK) { - return err; - } + String error_string; + int error_line; + JSON json; + Variant result; + err = json.parse(json_string, result, error_string, error_line); + if (err != OK) { + return err; + } - Dictionary content = Dictionary(result); + Dictionary content = Dictionary(result); - source_path = content["source_path"]; - atlas_data = content["atlas_data"]; - normal_texture_prefix = content["normal_texture_prefix"]; + source_path = content["source_path"]; + atlas_data = content["atlas_data"]; + normal_texture_prefix = content["normal_texture_prefix"]; - if (atlas) delete atlas; - tex_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)); + if (atlas) delete atlas; + tex_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)); - if (atlas) - return OK; + if (atlas) + return OK; - tex_list.clear(); - ntex_list.clear(); - return ERR_FILE_UNRECOGNIZED; + tex_list.clear(); + ntex_list.clear(); + return ERR_FILE_UNRECOGNIZED; } Error SpineAtlasResource::save_to_file(const String &p_path) { - Error err; - FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); - if (err != OK) { -// print_line(vformat("save file err: %d", err)); - if (file) file->close(); - return err; - } + Error err; + FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); + if (err != OK) { + // print_line(vformat("save file err: %d", err)); + if (file) file->close(); + return err; + } - Dictionary content; - content["source_path"] = source_path; - content["atlas_data"] = atlas_data; - content["normal_texture_prefix"] = normal_texture_prefix; + Dictionary content; + content["source_path"] = source_path; + content["atlas_data"] = atlas_data; + 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->close(); + file->store_string(JSON::print(content)); + file->close(); - return OK; + return OK; } diff --git a/spine-godot/spine_godot/SpineAtlasResource.h b/spine-godot/spine_godot/SpineAtlasResource.h index 862f554ef..881d17664 100644 --- a/spine-godot/spine_godot/SpineAtlasResource.h +++ b/spine-godot/spine_godot/SpineAtlasResource.h @@ -31,7 +31,6 @@ #define GODOT_SPINEATLASRESOURCE_H - #include "core/variant_parser.h" #include @@ -41,39 +40,40 @@ #include #include "SpineRendererObject.h" -class SpineAtlasResource : public Resource{ - GDCLASS(SpineAtlasResource, Resource); +class SpineAtlasResource : public Resource { + GDCLASS(SpineAtlasResource, Resource); protected: - static void _bind_methods(); + static void _bind_methods(); - spine::Atlas *atlas; + spine::Atlas *atlas; - String source_path; - String atlas_data; - String normal_texture_prefix; + String source_path; + String atlas_data; + String normal_texture_prefix; + + Array tex_list; + Array ntex_list; - Array tex_list; - Array ntex_list; 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 save_to_file(const String &p_path); // .spatlas + Error load_from_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_normal_textures(); SpineAtlasResource(); - virtual ~SpineAtlasResource(); + virtual ~SpineAtlasResource(); }; -#endif //GODOT_SPINEATLASRESOURCE_H +#endif//GODOT_SPINEATLASRESOURCE_H diff --git a/spine-godot/spine_godot/SpineAttachment.cpp b/spine-godot/spine_godot/SpineAttachment.cpp index 319cae442..e25f54c5e 100644 --- a/spine-godot/spine_godot/SpineAttachment.cpp +++ b/spine-godot/spine_godot/SpineAttachment.cpp @@ -34,21 +34,21 @@ void SpineAttachment::_bind_methods() { ClassDB::bind_method(D_METHOD("copy"), &SpineAttachment::copy); } -SpineAttachment::SpineAttachment():attachment(NULL) {} +SpineAttachment::SpineAttachment() : attachment(NULL) {} SpineAttachment::~SpineAttachment() { - if(attachment){ + if (attachment) { attachment->dereference(); attachment = NULL; } } -String SpineAttachment::get_attachment_name(){ +String SpineAttachment::get_attachment_name() { return attachment->getName().buffer(); } -Ref SpineAttachment::copy(){ +Ref SpineAttachment::copy() { auto a = attachment->copy(); - if(a == NULL) return NULL; + if (a == NULL) return NULL; Ref gd_attachment(memnew(SpineAttachment)); gd_attachment->set_spine_object(a); return gd_attachment; diff --git a/spine-godot/spine_godot/SpineAttachment.h b/spine-godot/spine_godot/SpineAttachment.h index 4575a50d1..81ec52c9d 100644 --- a/spine-godot/spine_godot/SpineAttachment.h +++ b/spine-godot/spine_godot/SpineAttachment.h @@ -47,12 +47,12 @@ public: SpineAttachment(); ~SpineAttachment(); - inline void set_spine_object(spine::Attachment *a){ + inline void set_spine_object(spine::Attachment *a) { attachment = a; - if(attachment) + if (attachment) attachment->reference(); } - inline spine::Attachment *get_spine_object(){ + inline spine::Attachment *get_spine_object() { return attachment; } @@ -61,4 +61,4 @@ public: Ref copy(); }; -#endif //GODOT_SPINEATTACHMENT_H +#endif//GODOT_SPINEATTACHMENT_H diff --git a/spine-godot/spine_godot/SpineBone.cpp b/spine-godot/spine_godot/SpineBone.cpp index 59f495aa3..afde7a781 100644 --- a/spine-godot/spine_godot/SpineBone.cpp +++ b/spine-godot/spine_godot/SpineBone.cpp @@ -34,52 +34,52 @@ void SpineBone::_bind_methods() { ClassDB::bind_method(D_METHOD("update_world_transform"), &SpineBone::update_world_transform); -// void set_to_setup_pose(); -// -// Vector2 world_to_local(Vector2 world_position); -// -// Vector2 local_to_world(Vector2 local_position); -// -// float world_to_local_rotation(float world_rotation); -// -// float local_to_world_rotation(float local_rotation); -// -// void rotate_world(float degrees); + // void set_to_setup_pose(); + // + // Vector2 world_to_local(Vector2 world_position); + // + // Vector2 local_to_world(Vector2 local_position); + // + // float world_to_local_rotation(float world_rotation); + // + // float local_to_world_rotation(float local_rotation); + // + // void rotate_world(float degrees); 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("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("local_to_world_rotation", "local_rotation"), &SpineBone::local_to_world_rotation); ClassDB::bind_method(D_METHOD("rotate_world"), &SpineBone::rotate_world); -// -// float get_world_to_local_rotation_x(); -// float get_world_to_local_rotation_y(); -// -// Ref get_data(); -// -// Ref get_skeleton(); -// -// Ref get_parent(); -// -// Array get_children(); + // + // float get_world_to_local_rotation_x(); + // float get_world_to_local_rotation_y(); + // + // Ref get_data(); + // + // Ref get_skeleton(); + // + // Ref get_parent(); + // + // 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_y"), &SpineBone::get_world_to_local_rotation_y); 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_parent"), &SpineBone::get_parent); ClassDB::bind_method(D_METHOD("get_children"), &SpineBone::get_children); -// -// float get_x(); -// void set_x(float v); -// -// float get_y(); -// void set_y(float v); -// -// float get_rotation(); -// void set_rotation(float v); -// -// float get_scale_x(); -// void set_scale_x(float v); + // + // float get_x(); + // void set_x(float v); + // + // float get_y(); + // void set_y(float v); + // + // float get_rotation(); + // void set_rotation(float v); + // + // float get_scale_x(); + // void set_scale_x(float v); 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("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("get_scale_x"), &SpineBone::get_scale_x); ClassDB::bind_method(D_METHOD("set_scale_x", "v"), &SpineBone::set_scale_x); -// -// float get_scale_y(); -// void set_scale_y(float v); -// -// float get_shear_x(); -// void set_shear_x(float v); -// -// float get_shear_y(); -// void set_shear_y(float v); -// -// float get_applied_rotation(); -// void set_applied_rotation(float v); + // + // float get_scale_y(); + // void set_scale_y(float v); + // + // float get_shear_x(); + // void set_shear_x(float v); + // + // float get_shear_y(); + // void set_shear_y(float v); + // + // float get_applied_rotation(); + // void set_applied_rotation(float v); 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("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("get_applied_rotation"), &SpineBone::get_applied_rotation); ClassDB::bind_method(D_METHOD("set_applied_rotation", "v"), &SpineBone::set_applied_rotation); -// -// float get_a_x(); -// void set_a_x(float v); -// -// float get_a_y(); -// void set_a_y(float v); -// -// float get_a_scale_x(); -// void set_a_scale_x(float v); -// -// float get_a_scale_y(); -// void set_a_scale_y(float v); + // + // float get_a_x(); + // void set_a_x(float v); + // + // float get_a_y(); + // void set_a_y(float v); + // + // float get_a_scale_x(); + // void set_a_scale_x(float v); + // + // float get_a_scale_y(); + // void set_a_scale_y(float v); 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("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("get_a_scale_y"), &SpineBone::get_a_scale_y); ClassDB::bind_method(D_METHOD("set_a_scale_y", "v"), &SpineBone::set_a_scale_y); -// -// float get_a_shear_x(); -// void set_a_shear_x(float v); -// -// float get_a_shear_y(); -// void set_a_shear_y(float v); -// -// float get_a(); -// void set_a(float v); -// -// float get_b(); -// void set_b(float v); + // + // float get_a_shear_x(); + // void set_a_shear_x(float v); + // + // float get_a_shear_y(); + // void set_a_shear_y(float v); + // + // float get_a(); + // void set_a(float v); + // + // float get_b(); + // void set_b(float v); 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("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("get_b"), &SpineBone::get_b); ClassDB::bind_method(D_METHOD("set_b", "v"), &SpineBone::set_b); -// -// float get_c(); -// void set_c(float v); -// -// float get_d(); -// void set_d(float v); -// -// float get_world_x(); -// void set_world_x(float v); -// -// float get_world_y(); -// void set_world_y(float v); + // + // float get_c(); + // void set_c(float v); + // + // float get_d(); + // void set_d(float v); + // + // float get_world_x(); + // void set_world_x(float v); + // + // float get_world_y(); + // void set_world_y(float v); 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("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("get_world_y"), &SpineBone::get_world_y); ClassDB::bind_method(D_METHOD("set_world_y", "v"), &SpineBone::set_world_y); -// -// float get_world_rotation_x(); -// float get_world_rotation_y(); -// -// float get_world_scale_x(); -// float get_world_scale_y(); -// -// bool is_applied_valid(); -// void set_applied_valid(bool v); -// -// bool is_active(); -// void set_active(bool v); + // + // float get_world_rotation_x(); + // float get_world_rotation_y(); + // + // float get_world_scale_x(); + // float get_world_scale_y(); + // + // bool is_applied_valid(); + // void set_applied_valid(bool v); + // + // bool is_active(); + // 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_y"), &SpineBone::get_world_rotation_y); 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("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("set_godot_global_transform", "global_transform"), &SpineBone::set_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("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() {} -void SpineBone::update_world_transform(){ +void SpineBone::update_world_transform() { bone->updateWorldTransform(); } -void SpineBone::set_to_setup_pose(){ +void SpineBone::set_to_setup_pose() { bone->setToSetupPose(); } -Vector2 SpineBone::world_to_local(Vector2 world_position){ +Vector2 SpineBone::world_to_local(Vector2 world_position) { float x, y; bone->worldToLocal(world_position.x, world_position.y, 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; bone->localToWorld(local_position.x, local_position.y, 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); } -float SpineBone::local_to_world_rotation(float local_rotation){ +float SpineBone::local_to_world_rotation(float local_rotation) { return bone->localToWorldRotation(local_rotation); } -void SpineBone::rotate_world(float degrees){ +void SpineBone::rotate_world(float degrees) { bone->rotateWorld(degrees); } -float SpineBone::get_world_to_local_rotation_x(){ +float SpineBone::get_world_to_local_rotation_x() { return bone->getWorldToLocalRotationX(); } -float SpineBone::get_world_to_local_rotation_y(){ +float SpineBone::get_world_to_local_rotation_y() { return bone->getWorldToLocalRotationY(); } -Ref SpineBone::get_data(){ +Ref SpineBone::get_data() { auto &bd = bone->getData(); Ref gd_bd(memnew(SpineBoneData)); gd_bd->set_spine_object(&bd); return gd_bd; } -Ref SpineBone::get_skeleton(){ +Ref SpineBone::get_skeleton() { auto &s = bone->getSkeleton(); Ref gd_s(memnew(SpineSkeleton)); gd_s->set_spine_object(&s); @@ -252,22 +252,22 @@ Ref SpineBone::get_skeleton(){ return gd_s; } -Ref SpineBone::get_parent(){ +Ref SpineBone::get_parent() { auto b = bone->getParent(); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineBone)); gd_b->set_spine_object(b); gd_b->set_spine_sprite(the_sprite); return gd_b; } -Array SpineBone::get_children(){ +Array SpineBone::get_children() { auto bs = bone->getChildren(); Array gd_bs; 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]; - if(b == NULL) gd_bs[i] = Ref(NULL); + if (b == NULL) gd_bs[i] = Ref(NULL); Ref gd_b(memnew(SpineBone)); gd_b->set_spine_object(b); gd_b->set_spine_sprite(the_sprite); @@ -276,179 +276,178 @@ Array SpineBone::get_children(){ return gd_bs; } -float SpineBone::get_x(){ +float SpineBone::get_x() { return bone->getX(); } -void SpineBone::set_x(float v){ +void SpineBone::set_x(float v) { bone->setX(v); } -float SpineBone::get_y(){ +float SpineBone::get_y() { return bone->getY(); } -void SpineBone::set_y(float v){ +void SpineBone::set_y(float v) { bone->setY(v); } -float SpineBone::get_rotation(){ +float SpineBone::get_rotation() { return bone->getRotation(); } -void SpineBone::set_rotation(float v){ +void SpineBone::set_rotation(float v) { bone->setRotation(v); } -float SpineBone::get_scale_x(){ +float SpineBone::get_scale_x() { return bone->getScaleX(); } -void SpineBone::set_scale_x(float v){ +void SpineBone::set_scale_x(float v) { bone->setScaleX(v); } -float SpineBone::get_scale_y(){ +float SpineBone::get_scale_y() { return bone->getScaleY(); } -void SpineBone::set_scale_y(float v){ +void SpineBone::set_scale_y(float v) { bone->setScaleY(v); } -float SpineBone::get_shear_x(){ +float SpineBone::get_shear_x() { return bone->getShearX(); } -void SpineBone::set_shear_x(float v){ +void SpineBone::set_shear_x(float v) { bone->setShearX(v); } -float SpineBone::get_shear_y(){ +float SpineBone::get_shear_y() { return bone->getShearY(); } -void SpineBone::set_shear_y(float v){ +void SpineBone::set_shear_y(float v) { bone->setShearY(v); } -float SpineBone::get_applied_rotation(){ +float SpineBone::get_applied_rotation() { return bone->getAppliedRotation(); } -void SpineBone::set_applied_rotation(float v){ +void SpineBone::set_applied_rotation(float v) { bone->setAppliedRotation(v); } -float SpineBone::get_a_x(){ +float SpineBone::get_a_x() { return bone->getAX(); } -void SpineBone::set_a_x(float v){ +void SpineBone::set_a_x(float v) { bone->setAX(v); } -float SpineBone::get_a_y(){ +float SpineBone::get_a_y() { return bone->getAY(); } -void SpineBone::set_a_y(float v){ +void SpineBone::set_a_y(float v) { bone->setAY(v); } -float SpineBone::get_a_scale_x(){ +float SpineBone::get_a_scale_x() { return bone->getAScaleX(); } -void SpineBone::set_a_scale_x(float v){ +void SpineBone::set_a_scale_x(float v) { bone->setAScaleX(v); } -float SpineBone::get_a_scale_y(){ +float SpineBone::get_a_scale_y() { return bone->getAScaleY(); } -void SpineBone::set_a_scale_y(float v){ +void SpineBone::set_a_scale_y(float v) { bone->setAScaleY(v); } -float SpineBone::get_a_shear_x(){ +float SpineBone::get_a_shear_x() { return bone->getAShearX(); } -void SpineBone::set_a_shear_x(float v){ +void SpineBone::set_a_shear_x(float v) { bone->setAShearX(v); } -float SpineBone::get_a_shear_y(){ +float SpineBone::get_a_shear_y() { return bone->getAShearY(); } -void SpineBone::set_a_shear_y(float v){ +void SpineBone::set_a_shear_y(float v) { bone->setAShearY(v); } -float SpineBone::get_a(){ +float SpineBone::get_a() { return bone->getA(); } -void SpineBone::set_a(float v){ +void SpineBone::set_a(float v) { bone->setA(v); } -float SpineBone::get_b(){ +float SpineBone::get_b() { return bone->getB(); } -void SpineBone::set_b(float v){ +void SpineBone::set_b(float v) { bone->setB(v); } -float SpineBone::get_c(){ +float SpineBone::get_c() { return bone->getC(); } -void SpineBone::set_c(float v){ +void SpineBone::set_c(float v) { bone->setC(v); } -float SpineBone::get_d(){ +float SpineBone::get_d() { return bone->getD(); } -void SpineBone::set_d(float v){ +void SpineBone::set_d(float v) { bone->setD(v); } -float SpineBone::get_world_x(){ +float SpineBone::get_world_x() { return bone->getWorldX(); } -void SpineBone::set_world_x(float v){ +void SpineBone::set_world_x(float v) { bone->setWorldX(v); } -float SpineBone::get_world_y(){ +float SpineBone::get_world_y() { return bone->getWorldY(); } -void SpineBone::set_world_y(float v){ +void SpineBone::set_world_y(float v) { bone->setWorldY(v); } -float SpineBone::get_world_rotation_x(){ +float SpineBone::get_world_rotation_x() { return bone->getWorldRotationX(); } -float SpineBone::get_world_rotation_y(){ +float SpineBone::get_world_rotation_y() { return bone->getWorldRotationY(); } -float SpineBone::get_world_scale_x(){ +float SpineBone::get_world_scale_x() { return bone->getWorldScaleX(); } -float SpineBone::get_world_scale_y(){ +float SpineBone::get_world_scale_y() { return bone->getWorldScaleY(); } -bool SpineBone::is_active(){ +bool SpineBone::is_active() { return bone->isActive(); } -void SpineBone::set_active(bool v){ +void SpineBone::set_active(bool v) { bone->setActive(v); } // External feature functions -void SpineBone::apply_world_transform_2d(Variant o){ - if(o.get_type() == Variant::OBJECT){ - auto node = (Node*) o; - if(node->is_class("Node2D")){ - auto node2d = (Node2D*) node; +void SpineBone::apply_world_transform_2d(Variant o) { + if (o.get_type() == Variant::OBJECT) { + auto node = (Node *) o; + if (node->is_class("Node2D")) { + auto node2d = (Node2D *) node; // In godot the y-axis is nag to spine node2d->set_transform(Transform2D( get_a(), get_c(), get_b(), get_d(), - get_world_x(), -get_world_y()) - ); + get_world_x(), -get_world_y())); // Fix the rotation auto pos = node2d->get_position(); node2d->translate(-pos); @@ -459,79 +458,79 @@ void SpineBone::apply_world_transform_2d(Variant o){ } Transform2D SpineBone::get_godot_transform() { - if (get_spine_object() == nullptr) - return Transform2D(); - Transform2D trans; - trans.translate(get_x(), -get_y()); - // It seems that spine uses degree for rotation - trans.rotate(Math::deg2rad(-get_rotation())); - trans.scale(Size2(get_scale_x(), get_scale_y())); - return trans; + if (get_spine_object() == nullptr) + return Transform2D(); + Transform2D trans; + trans.translate(get_x(), -get_y()); + // It seems that spine uses degree for rotation + trans.rotate(Math::deg2rad(-get_rotation())); + trans.scale(Size2(get_scale_x(), get_scale_y())); + return trans; } void SpineBone::set_godot_transform(Transform2D trans) { - if (get_spine_object() == nullptr) - return; - Vector2 position = trans.get_origin(); - position.y *= -1; - real_t rotation = trans.get_rotation(); - rotation = Math::rad2deg(-rotation); - Vector2 scale = trans.get_scale(); + if (get_spine_object() == nullptr) + return; + Vector2 position = trans.get_origin(); + position.y *= -1; + real_t rotation = trans.get_rotation(); + rotation = Math::rad2deg(-rotation); + Vector2 scale = trans.get_scale(); - set_x(position.x); - set_y(position.y); - set_rotation(rotation); - set_scale_x(scale.x); - set_scale_y(scale.y); + set_x(position.x); + set_y(position.y); + set_rotation(rotation); + set_scale_x(scale.x); + set_scale_y(scale.y); } Transform2D SpineBone::get_godot_global_transform() { - if (get_spine_object() == nullptr) - return Transform2D(); - if (the_sprite == nullptr) - return get_godot_transform(); - Transform2D res = the_sprite->get_transform(); - res.translate(get_world_x(), -get_world_y()); - res.rotate(Math::deg2rad(-get_world_rotation_x())); - res.scale(Vector2(get_world_scale_x(), get_world_scale_y())); - auto p = the_sprite->get_parent() ? Object::cast_to(the_sprite->get_parent()) : nullptr; - if (p) { - return p->get_global_transform() * res; - } - return res; + if (get_spine_object() == nullptr) + return Transform2D(); + if (the_sprite == nullptr) + return get_godot_transform(); + Transform2D res = the_sprite->get_transform(); + res.translate(get_world_x(), -get_world_y()); + res.rotate(Math::deg2rad(-get_world_rotation_x())); + res.scale(Vector2(get_world_scale_x(), get_world_scale_y())); + auto p = the_sprite->get_parent() ? Object::cast_to(the_sprite->get_parent()) : nullptr; + if (p) { + return p->get_global_transform() * res; + } + return res; } void SpineBone::set_godot_global_transform(Transform2D transform) { - if (get_spine_object() == nullptr) - return; - if (the_sprite == nullptr) - set_godot_transform(transform); - transform = the_sprite->get_global_transform().affine_inverse() * transform; - Vector2 position = transform.get_origin(); - real_t rotation = transform.get_rotation(); - Vector2 scale = transform.get_scale(); - position.y *= -1; - auto parent = get_parent(); - if (parent.is_valid()) { - position = parent->world_to_local(position); - if (parent->get_world_scale_x() != 0) - scale.x /= parent->get_world_scale_x(); - else - print_error("The parent scale.x is zero."); - if (parent->get_world_scale_y() != 0) - scale.y /= parent->get_world_scale_y(); - else - print_error("The parent scale.y is zero."); - } - rotation = world_to_local_rotation(Math::rad2deg(-rotation)); + if (get_spine_object() == nullptr) + return; + if (the_sprite == nullptr) + set_godot_transform(transform); + transform = the_sprite->get_global_transform().affine_inverse() * transform; + Vector2 position = transform.get_origin(); + real_t rotation = transform.get_rotation(); + Vector2 scale = transform.get_scale(); + position.y *= -1; + auto parent = get_parent(); + if (parent.is_valid()) { + position = parent->world_to_local(position); + if (parent->get_world_scale_x() != 0) + scale.x /= parent->get_world_scale_x(); + else + print_error("The parent scale.x is zero."); + if (parent->get_world_scale_y() != 0) + scale.y /= parent->get_world_scale_y(); + else + print_error("The parent scale.y is zero."); + } + rotation = world_to_local_rotation(Math::rad2deg(-rotation)); - set_x(position.x); - set_y(position.y); - set_rotation(rotation); - set_scale_x(scale.x); - set_scale_y(scale.y); + set_x(position.x); + set_y(position.y); + set_rotation(rotation); + set_scale_x(scale.x); + set_scale_y(scale.y); } void SpineBone::set_spine_sprite(SpineSprite *s) { - the_sprite = s; + the_sprite = s; } diff --git a/spine-godot/spine_godot/SpineBone.h b/spine-godot/spine_godot/SpineBone.h index 1661d751b..b7efd1381 100644 --- a/spine-godot/spine_godot/SpineBone.h +++ b/spine-godot/spine_godot/SpineBone.h @@ -54,14 +54,15 @@ private: spine::Bone *bone; SpineSprite *the_sprite; + public: SpineBone(); ~SpineBone(); - inline void set_spine_object(spine::Bone *b){ + inline void set_spine_object(spine::Bone *b) { bone = b; } - inline spine::Bone *get_spine_object(){ + inline spine::Bone *get_spine_object() { return bone; } @@ -171,4 +172,4 @@ public: void set_godot_global_transform(Transform2D trans); }; -#endif //GODOT_SPINEBONE_H +#endif//GODOT_SPINEBONE_H diff --git a/spine-godot/spine_godot/SpineBoneData.cpp b/spine-godot/spine_godot/SpineBoneData.cpp index e46ade5a2..b870527dc 100644 --- a/spine-godot/spine_godot/SpineBoneData.cpp +++ b/spine-godot/spine_godot/SpineBoneData.cpp @@ -71,93 +71,93 @@ void SpineBoneData::_bind_methods() { BIND_ENUM_CONSTANT(TRANSFORMMODE_NOSCALEORREFLECTION); } -SpineBoneData::SpineBoneData():bone_data(NULL) {} +SpineBoneData::SpineBoneData() : bone_data(NULL) {} SpineBoneData::~SpineBoneData() {} -int SpineBoneData::get_index(){ +int SpineBoneData::get_index() { return bone_data->getIndex(); } -String SpineBoneData::get_bone_name(){ +String SpineBoneData::get_bone_name() { return bone_data->getName().buffer(); } -Ref SpineBoneData::get_parent(){ +Ref SpineBoneData::get_parent() { auto p = bone_data->getParent(); - if(p == NULL) return NULL; + if (p == NULL) return NULL; Ref gd_bone_data(memnew(SpineBoneData)); gd_bone_data->set_spine_object(p); return gd_bone_data; } -float SpineBoneData::get_length(){ +float SpineBoneData::get_length() { return bone_data->getLength(); } -void SpineBoneData::set_length(float v){ +void SpineBoneData::set_length(float v) { bone_data->setLength(v); } -float SpineBoneData::get_x(){ +float SpineBoneData::get_x() { return bone_data->getX(); } -void SpineBoneData::set_x(float v){ +void SpineBoneData::set_x(float v) { bone_data->setX(v); } -float SpineBoneData::get_y(){ +float SpineBoneData::get_y() { return bone_data->getY(); } -void SpineBoneData::set_y(float v){ +void SpineBoneData::set_y(float v) { bone_data->setY(v); } -float SpineBoneData::get_rotation(){ +float SpineBoneData::get_rotation() { return bone_data->getRotation(); } -void SpineBoneData::set_rotation(float v){ +void SpineBoneData::set_rotation(float v) { bone_data->setRotation(v); } -float SpineBoneData::get_scale_x(){ +float SpineBoneData::get_scale_x() { return bone_data->getScaleX(); } -void SpineBoneData::set_scale_x(float v){ +void SpineBoneData::set_scale_x(float v) { bone_data->setScaleX(v); } -float SpineBoneData::get_scale_y(){ +float SpineBoneData::get_scale_y() { return bone_data->getScaleY(); } -void SpineBoneData::set_scale_y(float v){ +void SpineBoneData::set_scale_y(float v) { bone_data->setScaleY(v); } -float SpineBoneData::get_shear_x(){ +float SpineBoneData::get_shear_x() { return bone_data->getShearX(); } -void SpineBoneData::set_shear_x(float v){ +void SpineBoneData::set_shear_x(float v) { bone_data->setShearX(v); } -float SpineBoneData::get_shear_y(){ +float SpineBoneData::get_shear_y() { return bone_data->getShearY(); } -void SpineBoneData::set_shear_y(float v){ +void SpineBoneData::set_shear_y(float v) { bone_data->setShearY(v); } -SpineBoneData::TransformMode SpineBoneData::get_transform_mode(){ - auto tm = (int)bone_data->getTransformMode(); +SpineBoneData::TransformMode SpineBoneData::get_transform_mode() { + auto tm = (int) bone_data->getTransformMode(); return (TransformMode) tm; } -void SpineBoneData::set_transform_mode(TransformMode v){ +void SpineBoneData::set_transform_mode(TransformMode 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(); } -void SpineBoneData::set_skin_required(bool v){ +void SpineBoneData::set_skin_required(bool v) { bone_data->setSkinRequired(v); } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpineBoneData.h b/spine-godot/spine_godot/SpineBoneData.h index 3bef4c023..dc3e3feb6 100644 --- a/spine-godot/spine_godot/SpineBoneData.h +++ b/spine-godot/spine_godot/SpineBoneData.h @@ -47,10 +47,10 @@ public: SpineBoneData(); ~SpineBoneData(); - inline void set_spine_object(spine::BoneData *b){ + inline void set_spine_object(spine::BoneData *b) { bone_data = b; } - inline spine::BoneData *get_spine_object(){ + inline spine::BoneData *get_spine_object() { return bone_data; } @@ -97,8 +97,7 @@ public: bool is_skin_required(); void set_skin_required(bool v); - }; VARIANT_ENUM_CAST(SpineBoneData::TransformMode); -#endif //GODOT_SPINEBONEDATA_H +#endif//GODOT_SPINEBONEDATA_H diff --git a/spine-godot/spine_godot/SpineCollisionShapeProxy.cpp b/spine-godot/spine_godot/SpineCollisionShapeProxy.cpp index e41b28faf..9015db60d 100644 --- a/spine-godot/spine_godot/SpineCollisionShapeProxy.cpp +++ b/spine-godot/spine_godot/SpineCollisionShapeProxy.cpp @@ -32,173 +32,165 @@ #include "SpineSprite.h" void SpineCollisionShapeProxy::_bind_methods() { - 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("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("get_slot"), &SpineCollisionShapeProxy::get_slot); - ClassDB::bind_method(D_METHOD("set_slot", "v"), &SpineCollisionShapeProxy::set_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("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("get_sync_transform"), &SpineCollisionShapeProxy::get_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::BOOL, "sync_transform"), "set_sync_transform", "get_sync_transform"); + 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"); } -SpineCollisionShapeProxy::SpineCollisionShapeProxy():sync_transform(true) { - +SpineCollisionShapeProxy::SpineCollisionShapeProxy() : sync_transform(true) { } SpineCollisionShapeProxy::~SpineCollisionShapeProxy() { - } void SpineCollisionShapeProxy::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_READY: { - set_process_internal(true); - } break; - case NOTIFICATION_INTERNAL_PROCESS: { - if (!disabled) { - if (sync_transform) _sync_transform(get_spine_sprite()); - _update_polygon_from_spine_sprite(get_spine_sprite()); - if (is_visible()) update(); - } - } break; - } + switch (p_what) { + case NOTIFICATION_READY: { + set_process_internal(true); + } break; + case NOTIFICATION_INTERNAL_PROCESS: { + if (!disabled) { + if (sync_transform) _sync_transform(get_spine_sprite()); + _update_polygon_from_spine_sprite(get_spine_sprite()); + if (is_visible()) update(); + } + } break; + } } 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() { - return spine_sprite_path; + return spine_sprite_path; } 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 { - return slot; + return slot; } void SpineCollisionShapeProxy::set_slot(const String &v) { - slot = v; - _update_polygon_from_spine_sprite(get_spine_sprite()); + slot = v; + _update_polygon_from_spine_sprite(get_spine_sprite()); } void SpineCollisionShapeProxy::_update_polygon_from_spine_sprite(SpineSprite *sprite) { - _clear_polygon(); - if (sprite == nullptr || slot.empty()) { - return; - } + _clear_polygon(); + if (sprite == nullptr || slot.empty()) { + return; + } - if (!sprite->get_skeleton().is_valid()) { - return; - } + if (!sprite->get_skeleton().is_valid()) { + return; + } - auto sk = sprite->get_skeleton()->get_spine_object(); + auto sk = sprite->get_skeleton()->get_spine_object(); - spine::Vector vertices; + spine::Vector vertices; - spine::Slot *s = sk->findSlot(spine::String(slot.utf8())); - if (!s) { - return; - } - spine::Attachment *attachment = s->getAttachment(); - if(!attachment){ - return; - } + spine::Slot *s = sk->findSlot(spine::String(slot.utf8())); + if (!s) { + return; + } + spine::Attachment *attachment = s->getAttachment(); + if (!attachment) { + return; + } - if (attachment->getRTTI().isExactly(spine::BoundingBoxAttachment::rtti)) { - auto *box = (spine::BoundingBoxAttachment*) attachment; + if (attachment->getRTTI().isExactly(spine::BoundingBoxAttachment::rtti)) { + auto *box = (spine::BoundingBoxAttachment *) attachment; - vertices.setSize(box->getWorldVerticesLength(), 0); - box->computeWorldVertices(*s, vertices); - } else { - return; - } + vertices.setSize(box->getWorldVerticesLength(), 0); + box->computeWorldVertices(*s, vertices); + } else { + return; + } - polygon.resize(vertices.size()/2); - for (size_t j=0; j < vertices.size(); j+=2) { - polygon.set(j/2, Vector2(vertices[j], -vertices[j + 1])); - } + polygon.resize(vertices.size() / 2); + for (size_t j = 0; j < vertices.size(); j += 2) { + polygon.set(j / 2, Vector2(vertices[j], -vertices[j + 1])); + } - set_polygon(polygon); + set_polygon(polygon); } void SpineCollisionShapeProxy::_clear_polygon() { - polygon.clear(); - set_polygon(polygon); + polygon.clear(); + set_polygon(polygon); } void SpineCollisionShapeProxy::_sync_transform(SpineSprite *sprite) { - if (sprite == nullptr) return; - set_global_transform(sprite->get_global_transform()); + if (sprite == nullptr) return; + set_global_transform(sprite->get_global_transform()); } bool SpineCollisionShapeProxy::get_sync_transform() { - return sync_transform; + return sync_transform; } void SpineCollisionShapeProxy::set_sync_transform(bool v) { - sync_transform = v; + sync_transform = v; } void SpineCollisionShapeProxy::_get_property_list(List *p_list) const { - PropertyInfo p; - Vector res; + PropertyInfo p; + Vector res; - p.name = "slot"; - p.type = Variant::STRING; - _get_slot_list(res); - if (res.empty()) res.push_back("No Slot"); - p.hint_string = String(",").join(res); - p.hint = PROPERTY_HINT_ENUM; - p_list->push_back(p); + p.name = "slot"; + p.type = Variant::STRING; + _get_slot_list(res); + if (res.empty()) res.push_back("No Slot"); + p.hint_string = String(",").join(res); + p.hint = PROPERTY_HINT_ENUM; + p_list->push_back(p); } bool SpineCollisionShapeProxy::_get(const StringName &p_property, Variant &r_value) const { - if (p_property == "slot") { - r_value = get_slot(); - return true; - } - return false; + if (p_property == "slot") { + r_value = get_slot(); + return true; + } + return false; } bool SpineCollisionShapeProxy::_set(const StringName &p_property, const Variant &p_value) { - if (p_property == "slot") { - set_slot(p_value); - return true; - } - return false; + if (p_property == "slot") { + set_slot(p_value); + return true; + } + return false; } void SpineCollisionShapeProxy::_get_slot_list(Vector &res) const { - if (get_spine_sprite() == nullptr) { - return; - } + if (get_spine_sprite() == nullptr) { + return; + } - auto sprite = get_spine_sprite(); - if (!sprite->get_skeleton().is_valid()) { - return; - } + auto sprite = get_spine_sprite(); + if (!sprite->get_skeleton().is_valid()) { + return; + } - auto slots = sprite->get_skeleton()->get_slots(); - res.resize(slots.size()); - for (size_t i=0; i < res.size(); ++i) { - auto slot = (Ref)slots[i]; - if (slot.is_valid()) - res.set(i, slot->get_data()->get_slot_name()); - } + auto slots = sprite->get_skeleton()->get_slots(); + res.resize(slots.size()); + for (size_t i = 0; i < res.size(); ++i) { + auto slot = (Ref) slots[i]; + if (slot.is_valid()) + res.set(i, slot->get_data()->get_slot_name()); + } } - - - - - - diff --git a/spine-godot/spine_godot/SpineCollisionShapeProxy.h b/spine-godot/spine_godot/SpineCollisionShapeProxy.h index 5dd2dd683..c29eaa591 100644 --- a/spine-godot/spine_godot/SpineCollisionShapeProxy.h +++ b/spine-godot/spine_godot/SpineCollisionShapeProxy.h @@ -36,43 +36,45 @@ class SpineSprite; class SpineAnimationState; class SpineSkeleton; -class SpineCollisionShapeProxy : public CollisionPolygon2D{ - GDCLASS(SpineCollisionShapeProxy, CollisionPolygon2D) +class SpineCollisionShapeProxy : public CollisionPolygon2D { + GDCLASS(SpineCollisionShapeProxy, CollisionPolygon2D) 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: - void _notification(int p_what); - void _get_property_list(List *p_list) const; - bool _get(const StringName &p_property, Variant &r_value) const; - bool _set(const StringName &p_property, const Variant &p_value); + void _notification(int p_what); + void _get_property_list(List *p_list) const; + bool _get(const StringName &p_property, Variant &r_value) const; + 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 _clear_polygon(); - void _sync_transform(SpineSprite *sprite); + void _update_polygon_from_spine_sprite(SpineSprite *sprite); + void _clear_polygon(); + void _sync_transform(SpineSprite *sprite); + + void _get_slot_list(Vector &res) const; - void _get_slot_list(Vector &res) const; public: - SpineCollisionShapeProxy(); - ~SpineCollisionShapeProxy(); + SpineCollisionShapeProxy(); + ~SpineCollisionShapeProxy(); - NodePath get_spine_sprite_path(); - void set_spine_sprite_path(NodePath v); + NodePath get_spine_sprite_path(); + void set_spine_sprite_path(NodePath v); - String get_slot() const; - void set_slot(const String &v); + String get_slot() const; + void set_slot(const String &v); - bool get_sync_transform(); - void set_sync_transform(bool v); + bool get_sync_transform(); + void set_sync_transform(bool v); }; -#endif //GODOT_SPINECOLLISIONSHAPEPROXY_H +#endif//GODOT_SPINECOLLISIONSHAPEPROXY_H diff --git a/spine-godot/spine_godot/SpineConstant.cpp b/spine-godot/spine_godot/SpineConstant.cpp index 9e0406103..760ff668a 100644 --- a/spine-godot/spine_godot/SpineConstant.cpp +++ b/spine-godot/spine_godot/SpineConstant.cpp @@ -30,33 +30,31 @@ #include "SpineConstant.h" void SpineConstant::_bind_methods() { - BIND_ENUM_CONSTANT(MixBlend_Setup); - BIND_ENUM_CONSTANT(MixBlend_First); - BIND_ENUM_CONSTANT(MixBlend_Replace); - 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(MixBlend_Setup); + BIND_ENUM_CONSTANT(MixBlend_First); + BIND_ENUM_CONSTANT(MixBlend_Replace); + 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); } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpineConstant.h b/spine-godot/spine_godot/SpineConstant.h index fb2d01ece..c7f86d8b9 100644 --- a/spine-godot/spine_godot/SpineConstant.h +++ b/spine-godot/spine_godot/SpineConstant.h @@ -32,49 +32,50 @@ #include "core/variant_parser.h" -class SpineConstant : public Object{ - GDCLASS(SpineConstant, Object); +class SpineConstant : public Object { + GDCLASS(SpineConstant, Object); protected: - static void _bind_methods(); + static void _bind_methods(); + public: - enum MixBlend { - MixBlend_Setup = 0, - MixBlend_First, - MixBlend_Replace, - MixBlend_Add - }; + enum MixBlend { + MixBlend_Setup = 0, + MixBlend_First, + MixBlend_Replace, + MixBlend_Add + }; - enum MixDirection { - MixDirection_In = 0, - MixDirection_Out - }; + enum MixDirection { + MixDirection_In = 0, + MixDirection_Out + }; - enum PropertyId { - Property_Rotate = 1 << 0, - Property_X = 1 << 1, - Property_Y = 1 << 2, - Property_ScaleX = 1 << 3, - Property_ScaleY = 1 << 4, - Property_ShearX = 1 << 5, - Property_ShearY = 1 << 6, - Property_Rgb = 1 << 7, - Property_Alpha = 1 << 8, - Property_Rgb2 = 1 << 9, - Property_Attachment = 1 << 10, - Property_Deform = 1 << 11, - Property_Event = 1 << 12, - Property_DrawOrder = 1 << 13, - Property_IkConstraint = 1 << 14, - Property_TransformConstraint = 1 << 15, - Property_PathConstraintPosition = 1 << 16, - Property_PathConstraintSpacing = 1 << 17, - Property_PathConstraintMix = 1 << 18 - }; + enum PropertyId { + Property_Rotate = 1 << 0, + Property_X = 1 << 1, + Property_Y = 1 << 2, + Property_ScaleX = 1 << 3, + Property_ScaleY = 1 << 4, + Property_ShearX = 1 << 5, + Property_ShearY = 1 << 6, + Property_Rgb = 1 << 7, + Property_Alpha = 1 << 8, + Property_Rgb2 = 1 << 9, + Property_Attachment = 1 << 10, + Property_Deform = 1 << 11, + Property_Event = 1 << 12, + Property_DrawOrder = 1 << 13, + Property_IkConstraint = 1 << 14, + Property_TransformConstraint = 1 << 15, + Property_PathConstraintPosition = 1 << 16, + Property_PathConstraintSpacing = 1 << 17, + Property_PathConstraintMix = 1 << 18 + }; }; VARIANT_ENUM_CAST(SpineConstant::MixBlend); VARIANT_ENUM_CAST(SpineConstant::MixDirection); VARIANT_ENUM_CAST(SpineConstant::PropertyId); -#endif //GODOT_SPINECONSTANT_H +#endif//GODOT_SPINECONSTANT_H diff --git a/spine-godot/spine_godot/SpineConstraintData.cpp b/spine-godot/spine_godot/SpineConstraintData.cpp index 52d054efe..16bbac435 100644 --- a/spine-godot/spine_godot/SpineConstraintData.cpp +++ b/spine-godot/spine_godot/SpineConstraintData.cpp @@ -37,23 +37,23 @@ void SpineConstraintData::_bind_methods() { 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() {} -String SpineConstraintData::get_constraint_data_name(){ +String SpineConstraintData::get_constraint_data_name() { return constraint_data->getName().buffer(); } -uint64_t SpineConstraintData::get_order(){ +uint64_t SpineConstraintData::get_order() { return constraint_data->getOrder(); } -void SpineConstraintData::set_order(uint64_t v){ +void SpineConstraintData::set_order(uint64_t v) { constraint_data->setOrder(v); } -bool SpineConstraintData::is_skin_required(){ +bool SpineConstraintData::is_skin_required() { return constraint_data->isSkinRequired(); } -void SpineConstraintData::set_skin_required(bool v){ +void SpineConstraintData::set_skin_required(bool v) { constraint_data->setSkinRequired(v); } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpineConstraintData.h b/spine-godot/spine_godot/SpineConstraintData.h index ff0517a46..35b9dd52a 100644 --- a/spine-godot/spine_godot/SpineConstraintData.h +++ b/spine-godot/spine_godot/SpineConstraintData.h @@ -47,10 +47,10 @@ public: SpineConstraintData(); ~SpineConstraintData(); - inline void set_spine_object(spine::ConstraintData *c){ + inline void set_spine_object(spine::ConstraintData *c) { constraint_data = c; } - virtual inline spine::ConstraintData *get_spine_object(){ + virtual inline spine::ConstraintData *get_spine_object() { return constraint_data; } @@ -63,4 +63,4 @@ public: void set_skin_required(bool v); }; -#endif //GODOT_SPINECONSTRAINTDATA_H +#endif//GODOT_SPINECONSTRAINTDATA_H diff --git a/spine-godot/spine_godot/SpineEvent.cpp b/spine-godot/spine_godot/SpineEvent.cpp index f33582045..9d753db33 100644 --- a/spine-godot/spine_godot/SpineEvent.cpp +++ b/spine-godot/spine_godot/SpineEvent.cpp @@ -43,19 +43,19 @@ void SpineEvent::_bind_methods() { 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("set_balance", "v"), &SpineEvent::set_balance); -// -// BIND_ENUM_CONSTANT(EVENTTYPE_START); -// BIND_ENUM_CONSTANT(EVENTTYPE_INTERRUPT); -// BIND_ENUM_CONSTANT(EVENTTYPE_END); -// BIND_ENUM_CONSTANT(EVENTTYPE_COMPLETE); -// BIND_ENUM_CONSTANT(EVENTTYPE_DISPOSE); -// BIND_ENUM_CONSTANT(EVENTTYPE_EVENT); + // + // BIND_ENUM_CONSTANT(EVENTTYPE_START); + // BIND_ENUM_CONSTANT(EVENTTYPE_INTERRUPT); + // BIND_ENUM_CONSTANT(EVENTTYPE_END); + // BIND_ENUM_CONSTANT(EVENTTYPE_COMPLETE); + // BIND_ENUM_CONSTANT(EVENTTYPE_DISPOSE); + // BIND_ENUM_CONSTANT(EVENTTYPE_EVENT); } -SpineEvent::SpineEvent():event(NULL) {} -SpineEvent::~SpineEvent(){} +SpineEvent::SpineEvent() : event(NULL) {} +SpineEvent::~SpineEvent() {} -Ref SpineEvent::get_data(){ +Ref SpineEvent::get_data() { Ref event_data(memnew(SpineEventData)); event_data->set_spine_object(&(event->getData())); return event_data; @@ -65,46 +65,46 @@ String SpineEvent::get_event_name() { return event->getData().getName().buffer(); } -float SpineEvent::get_time(){ +float SpineEvent::get_time() { return event->getTime(); } -int SpineEvent::get_int_value(){ +int SpineEvent::get_int_value() { return event->getIntValue(); } -void SpineEvent::set_int_value(int v){ +void SpineEvent::set_int_value(int v) { event->setIntValue(v); } -float SpineEvent::get_float_value(){ +float SpineEvent::get_float_value() { return event->getFloatValue(); } -void SpineEvent::set_float_value(float v){ +void SpineEvent::set_float_value(float v) { event->setFloatValue(v); } -String SpineEvent::get_string_value(){ +String SpineEvent::get_string_value() { 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())); } -float SpineEvent::get_volume(){ +float SpineEvent::get_volume() { return event->getVolume(); } -void SpineEvent::set_volume(float v){ +void SpineEvent::set_volume(float v) { event->setVolume(v); } -float SpineEvent::get_balance(){ +float SpineEvent::get_balance() { return event->getBalance(); } -void SpineEvent::set_balance(float v){ +void SpineEvent::set_balance(float v) { event->setBalance(v); } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpineEvent.h b/spine-godot/spine_godot/SpineEvent.h index 4824eeaff..bbbf0b986 100644 --- a/spine-godot/spine_godot/SpineEvent.h +++ b/spine-godot/spine_godot/SpineEvent.h @@ -36,25 +36,27 @@ #include "SpineEventData.h" -class SpineEvent : public Reference{ +class SpineEvent : public Reference { GDCLASS(SpineEvent, Reference); protected: static void _bind_methods(); + private: spine::Event *event; + public: SpineEvent(); ~SpineEvent(); - inline void set_spine_object(spine::Event *e){ + inline void set_spine_object(spine::Event *e) { event = e; } - inline spine::Event *get_spine_object() const{ + inline spine::Event *get_spine_object() const { return event; } - enum EventType{ + enum EventType { EVENTTYPE_START = spine::EventType_Start, EVENTTYPE_INTERRUPT = spine::EventType_Interrupt, EVENTTYPE_END = spine::EventType_End, @@ -86,4 +88,4 @@ public: void set_balance(float inValue); }; -#endif //GODOT_SPINEEVENT_H +#endif//GODOT_SPINEEVENT_H diff --git a/spine-godot/spine_godot/SpineEventData.cpp b/spine-godot/spine_godot/SpineEventData.cpp index a1367ce96..bca195e79 100644 --- a/spine-godot/spine_godot/SpineEventData.cpp +++ b/spine-godot/spine_godot/SpineEventData.cpp @@ -30,8 +30,7 @@ #include "SpineEventData.h" void SpineEventData::_bind_methods() { - } -SpineEventData::SpineEventData():event_data(NULL) {} -SpineEventData::~SpineEventData(){} +SpineEventData::SpineEventData() : event_data(NULL) {} +SpineEventData::~SpineEventData() {} diff --git a/spine-godot/spine_godot/SpineEventData.h b/spine-godot/spine_godot/SpineEventData.h index eb6279717..1cf669f26 100644 --- a/spine-godot/spine_godot/SpineEventData.h +++ b/spine-godot/spine_godot/SpineEventData.h @@ -34,23 +34,25 @@ #include -class SpineEventData : public Reference{ +class SpineEventData : public Reference { GDCLASS(SpineEventData, Reference); protected: static void _bind_methods(); + private: const spine::EventData *event_data; + public: SpineEventData(); ~SpineEventData(); - inline void set_spine_object(const spine::EventData *e){ + inline void set_spine_object(const spine::EventData *e) { event_data = e; } - inline const spine::EventData *get_spine_object(){ + inline const spine::EventData *get_spine_object() { return event_data; } }; -#endif //GODOT_SPINEEVENTDATA_H +#endif//GODOT_SPINEEVENTDATA_H diff --git a/spine-godot/spine_godot/SpineIkConstraint.cpp b/spine-godot/spine_godot/SpineIkConstraint.cpp index 2c613ee90..d88492b48 100644 --- a/spine-godot/spine_godot/SpineIkConstraint.cpp +++ b/spine-godot/spine_godot/SpineIkConstraint.cpp @@ -52,35 +52,35 @@ void SpineIkConstraint::_bind_methods() { ClassDB::bind_method(D_METHOD("set_active", "v"), &SpineIkConstraint::set_active); } -SpineIkConstraint::SpineIkConstraint():ik_constraint(NULL) {} +SpineIkConstraint::SpineIkConstraint() : ik_constraint(NULL) {} SpineIkConstraint::~SpineIkConstraint() {} // void SpineIkConstraint::apply(){ // ik_constraint->apply(); // } -void SpineIkConstraint::update(){ +void SpineIkConstraint::update() { ik_constraint->update(); } -int SpineIkConstraint::get_order(){ +int SpineIkConstraint::get_order() { return ik_constraint->getOrder(); } -Ref SpineIkConstraint::get_data(){ +Ref SpineIkConstraint::get_data() { auto &ikc = ik_constraint->getData(); Ref gd_ikc(memnew(SpineIkConstraintData)); gd_ikc->set_spine_object(&ikc); return gd_ikc; } -Array SpineIkConstraint::get_bones(){ +Array SpineIkConstraint::get_bones() { auto &bs = ik_constraint->getBones(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i(NULL); + if (b == NULL) gd_bs[i] = Ref(NULL); Ref gd_b(memnew(SpineBone)); gd_b->set_spine_object(b); gd_bs[i] = gd_b; @@ -88,59 +88,59 @@ Array SpineIkConstraint::get_bones(){ return gd_bs; } -Ref SpineIkConstraint::get_target(){ +Ref SpineIkConstraint::get_target() { auto b = ik_constraint->getTarget(); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineBone)); gd_b->set_spine_object(b); return gd_b; } -void SpineIkConstraint::set_target(Ref v){ - if(v.is_valid()){ +void SpineIkConstraint::set_target(Ref v) { + if (v.is_valid()) { ik_constraint->setTarget(v->get_spine_object()); - } else{ + } else { ik_constraint->setTarget(NULL); } } -int SpineIkConstraint::get_bend_direction(){ +int SpineIkConstraint::get_bend_direction() { return ik_constraint->getBendDirection(); } -void SpineIkConstraint::set_bend_direction(int v){ +void SpineIkConstraint::set_bend_direction(int v) { ik_constraint->setBendDirection(v); } -bool SpineIkConstraint::get_compress(){ +bool SpineIkConstraint::get_compress() { return ik_constraint->getCompress(); } -void SpineIkConstraint::set_compress(bool v){ +void SpineIkConstraint::set_compress(bool v) { ik_constraint->setCompress(v); } -bool SpineIkConstraint::get_stretch(){ +bool SpineIkConstraint::get_stretch() { return ik_constraint->getStretch(); } -void SpineIkConstraint::set_stretch(bool v){ +void SpineIkConstraint::set_stretch(bool v) { ik_constraint->setStretch(v); } -float SpineIkConstraint::get_mix(){ +float SpineIkConstraint::get_mix() { return ik_constraint->getMix(); } -void SpineIkConstraint::set_mix(float v){ +void SpineIkConstraint::set_mix(float v) { ik_constraint->setMix(v); } -float SpineIkConstraint::get_softness(){ +float SpineIkConstraint::get_softness() { return ik_constraint->getSoftness(); } -void SpineIkConstraint::set_softness(float v){ +void SpineIkConstraint::set_softness(float v) { ik_constraint->setSoftness(v); } -bool SpineIkConstraint::is_active(){ +bool SpineIkConstraint::is_active() { return ik_constraint->isActive(); } -void SpineIkConstraint::set_active(bool v){ +void SpineIkConstraint::set_active(bool v) { ik_constraint->setActive(v); } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpineIkConstraint.h b/spine-godot/spine_godot/SpineIkConstraint.h index 2be633115..c7c4aeefe 100644 --- a/spine-godot/spine_godot/SpineIkConstraint.h +++ b/spine-godot/spine_godot/SpineIkConstraint.h @@ -51,15 +51,15 @@ public: SpineIkConstraint(); ~SpineIkConstraint(); - inline void set_spine_object(spine::IkConstraint * ic){ + inline void set_spine_object(spine::IkConstraint *ic) { ik_constraint = ic; } - inline spine::IkConstraint *get_spine_object(){ + inline spine::IkConstraint *get_spine_object() { return ik_constraint; } // The spine-runtime-cpp 4.0 seems to not have a apply function implementation. - // void apply(); + // void apply(); void update(); @@ -89,7 +89,6 @@ public: bool is_active(); void set_active(bool v); - }; -#endif //GODOT_SPINEIKCONSTRAINT_H +#endif//GODOT_SPINEIKCONSTRAINT_H diff --git a/spine-godot/spine_godot/SpineIkConstraintData.cpp b/spine-godot/spine_godot/SpineIkConstraintData.cpp index be9dfe080..62731aecf 100644 --- a/spine-godot/spine_godot/SpineIkConstraintData.cpp +++ b/spine-godot/spine_godot/SpineIkConstraintData.cpp @@ -50,12 +50,12 @@ void SpineIkConstraintData::_bind_methods() { SpineIkConstraintData::SpineIkConstraintData() {} SpineIkConstraintData::~SpineIkConstraintData() {} -Array SpineIkConstraintData::get_bones(){ +Array SpineIkConstraintData::get_bones() { auto bs = get_spine_data()->getBones(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i < bs.size(); ++i){ - if(bs[i] == NULL) gd_bs[i] = Ref(NULL); + for (size_t i = 0; i < bs.size(); ++i) { + if (bs[i] == NULL) gd_bs[i] = Ref(NULL); else { Ref gd_b(memnew(SpineBoneData)); gd_b->set_spine_object(bs[i]); @@ -65,59 +65,59 @@ Array SpineIkConstraintData::get_bones(){ return gd_bs; } -Ref SpineIkConstraintData::get_target(){ +Ref SpineIkConstraintData::get_target() { auto b = get_spine_data()->getTarget(); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineBoneData)); gd_b->set_spine_object(b); return gd_b; } -void SpineIkConstraintData::set_target(Ref v){ - if(v.is_valid()){ +void SpineIkConstraintData::set_target(Ref v) { + if (v.is_valid()) { get_spine_data()->setTarget(v->get_spine_object()); - }else{ + } else { get_spine_data()->setTarget(NULL); } } -int SpineIkConstraintData::get_bend_direction(){ +int SpineIkConstraintData::get_bend_direction() { return get_spine_data()->getBendDirection(); } -void SpineIkConstraintData::set_bend_direction(int v){ +void SpineIkConstraintData::set_bend_direction(int v) { get_spine_data()->setBendDirection(v); } -bool SpineIkConstraintData::get_compress(){ +bool SpineIkConstraintData::get_compress() { return get_spine_data()->getCompress(); } -void SpineIkConstraintData::set_compress(bool v){ +void SpineIkConstraintData::set_compress(bool v) { get_spine_data()->setCompress(v); } -bool SpineIkConstraintData::get_stretch(){ +bool SpineIkConstraintData::get_stretch() { return get_spine_data()->getStretch(); } -void SpineIkConstraintData::set_stretch(bool v){ +void SpineIkConstraintData::set_stretch(bool v) { get_spine_data()->setStretch(v); } -bool SpineIkConstraintData::get_uniform(){ +bool SpineIkConstraintData::get_uniform() { return get_spine_data()->getUniform(); } -void SpineIkConstraintData::set_uniform(bool v){ +void SpineIkConstraintData::set_uniform(bool v) { get_spine_data()->setUniform(v); } -float SpineIkConstraintData::get_mix(){ +float SpineIkConstraintData::get_mix() { return get_spine_data()->getMix(); } -void SpineIkConstraintData::set_mix(float v){ +void SpineIkConstraintData::set_mix(float v) { get_spine_data()->setMix(v); } -float SpineIkConstraintData::get_softness(){ +float SpineIkConstraintData::get_softness() { return get_spine_data()->getSoftness(); } -void SpineIkConstraintData::set_softness(float v){ +void SpineIkConstraintData::set_softness(float v) { get_spine_data()->setSoftness(v); } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpineIkConstraintData.h b/spine-godot/spine_godot/SpineIkConstraintData.h index 97ecac686..da0434d0b 100644 --- a/spine-godot/spine_godot/SpineIkConstraintData.h +++ b/spine-godot/spine_godot/SpineIkConstraintData.h @@ -47,8 +47,8 @@ public: SpineIkConstraintData(); ~SpineIkConstraintData(); - virtual inline spine::IkConstraintData *get_spine_data(){ - return (spine::IkConstraintData*) SpineConstraintData::get_spine_object(); + virtual inline spine::IkConstraintData *get_spine_data() { + return (spine::IkConstraintData *) SpineConstraintData::get_spine_object(); } Array get_bones(); @@ -73,7 +73,6 @@ public: float get_softness(); void set_softness(float v); - }; -#endif //GODOT_SPINEIKCONSTRAINTDATA_H +#endif//GODOT_SPINEIKCONSTRAINTDATA_H diff --git a/spine-godot/spine_godot/SpinePathConstraint.cpp b/spine-godot/spine_godot/SpinePathConstraint.cpp index 4db07fb45..3df032a22 100644 --- a/spine-godot/spine_godot/SpinePathConstraint.cpp +++ b/spine-godot/spine_godot/SpinePathConstraint.cpp @@ -29,7 +29,7 @@ #include "SpinePathConstraint.h" -void SpinePathConstraint::_bind_methods(){ +void SpinePathConstraint::_bind_methods() { // ClassDB::bind_method(D_METHOD("apply"), &SpinePathConstraint::apply); ClassDB::bind_method(D_METHOD("update"), &SpinePathConstraint::update); ClassDB::bind_method(D_METHOD("get_order"), &SpinePathConstraint::get_order); @@ -51,63 +51,63 @@ void SpinePathConstraint::_bind_methods(){ ClassDB::bind_method(D_METHOD("set_active", "v"), &SpinePathConstraint::set_active); } -SpinePathConstraint::SpinePathConstraint():path_constraint(NULL) {} +SpinePathConstraint::SpinePathConstraint() : path_constraint(NULL) {} SpinePathConstraint::~SpinePathConstraint() {} // void SpinePathConstraint::apply(){ // path_constraint->apply(); // } -void SpinePathConstraint::update(){ +void SpinePathConstraint::update() { path_constraint->update(); } -int SpinePathConstraint::get_order(){ +int SpinePathConstraint::get_order() { return path_constraint->getOrder(); } -float SpinePathConstraint::get_position(){ +float SpinePathConstraint::get_position() { return path_constraint->getPosition(); } -void SpinePathConstraint::set_position(float v){ +void SpinePathConstraint::set_position(float v) { path_constraint->setPosition(v); } -float SpinePathConstraint::get_spacing(){ +float SpinePathConstraint::get_spacing() { return path_constraint->getSpacing(); } -void SpinePathConstraint::set_spacing(float v){ +void SpinePathConstraint::set_spacing(float v) { path_constraint->setSpacing(v); } -float SpinePathConstraint::get_mix_rotate(){ +float SpinePathConstraint::get_mix_rotate() { return path_constraint->getMixRotate(); } -void SpinePathConstraint::set_mix_rotate(float v){ +void SpinePathConstraint::set_mix_rotate(float v) { path_constraint->setMixRotate(v); } -float SpinePathConstraint::get_mix_x(){ +float SpinePathConstraint::get_mix_x() { return path_constraint->getMixX(); } -void SpinePathConstraint::set_mix_x(float v){ +void SpinePathConstraint::set_mix_x(float v) { path_constraint->setMixX(v); } -float SpinePathConstraint::get_mix_y(){ +float SpinePathConstraint::get_mix_y() { return path_constraint->getMixY(); } -void SpinePathConstraint::set_mix_y(float v){ +void SpinePathConstraint::set_mix_y(float v) { path_constraint->setMixY(v); } -Array SpinePathConstraint::get_bones(){ +Array SpinePathConstraint::get_bones() { auto &bs = path_constraint->getBones(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i(NULL); + if (b == NULL) gd_bs[i] = Ref(NULL); Ref gd_b(memnew(SpineBone)); gd_b->set_spine_object(b); gd_bs[i] = gd_b; @@ -115,31 +115,31 @@ Array SpinePathConstraint::get_bones(){ return gd_bs; } -Ref SpinePathConstraint::get_target(){ +Ref SpinePathConstraint::get_target() { auto s = path_constraint->getTarget(); - if(s == NULL) return NULL; + if (s == NULL) return NULL; Ref gd_s(memnew(SpineSlot)); gd_s->set_spine_object(s); return gd_s; } -void SpinePathConstraint::set_target(Ref v){ - if(v.is_valid()){ +void SpinePathConstraint::set_target(Ref v) { + if (v.is_valid()) { path_constraint->setTarget(v->get_spine_object()); - }else{ + } else { path_constraint->setTarget(NULL); } } -Ref SpinePathConstraint::get_data(){ +Ref SpinePathConstraint::get_data() { auto &sd = path_constraint->getData(); Ref gd_sd(memnew(SpinePathConstraintData)); gd_sd->set_spine_object(&sd); return gd_sd; } -bool SpinePathConstraint::is_active(){ +bool SpinePathConstraint::is_active() { return path_constraint->isActive(); } -void SpinePathConstraint::set_active(bool v){ +void SpinePathConstraint::set_active(bool v) { path_constraint->setActive(v); } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpinePathConstraint.h b/spine-godot/spine_godot/SpinePathConstraint.h index 8ab822f12..dcd41d09e 100644 --- a/spine-godot/spine_godot/SpinePathConstraint.h +++ b/spine-godot/spine_godot/SpinePathConstraint.h @@ -38,7 +38,7 @@ #include "SpineSlot.h" #include "SpinePathConstraintData.h" -class SpinePathConstraint : public Reference{ +class SpinePathConstraint : public Reference { GDCLASS(SpinePathConstraint, Reference); protected: @@ -51,15 +51,15 @@ public: SpinePathConstraint(); ~SpinePathConstraint(); - inline void set_spine_object(spine::PathConstraint *pc){ + inline void set_spine_object(spine::PathConstraint *pc) { path_constraint = pc; } - inline spine::PathConstraint *get_spine_object(){ + inline spine::PathConstraint *get_spine_object() { return path_constraint; } // The spine-runtime-cpp 4.0 seems to not have a apply function implementation. - // void apply(); + // void apply(); void update(); @@ -91,4 +91,4 @@ public: void set_active(bool v); }; -#endif //GODOT_SPINEPATHCONSTRAINT_H +#endif//GODOT_SPINEPATHCONSTRAINT_H diff --git a/spine-godot/spine_godot/SpinePathConstraintData.cpp b/spine-godot/spine_godot/SpinePathConstraintData.cpp index 24541eeed..5d0f34b64 100644 --- a/spine-godot/spine_godot/SpinePathConstraintData.cpp +++ b/spine-godot/spine_godot/SpinePathConstraintData.cpp @@ -68,12 +68,12 @@ void SpinePathConstraintData::_bind_methods() { SpinePathConstraintData::SpinePathConstraintData() {} SpinePathConstraintData::~SpinePathConstraintData() {} -Array SpinePathConstraintData::get_bones(){ +Array SpinePathConstraintData::get_bones() { auto bs = get_spine_data()->getBones(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i < bs.size(); ++i){ - if(bs[i] == NULL) gd_bs[i] = Ref(NULL); + for (size_t i = 0; i < bs.size(); ++i) { + if (bs[i] == NULL) gd_bs[i] = Ref(NULL); else { Ref gd_b(memnew(SpineBoneData)); gd_b->set_spine_object(bs[i]); @@ -83,86 +83,86 @@ Array SpinePathConstraintData::get_bones(){ return gd_bs; } -Ref SpinePathConstraintData::get_target(){ +Ref SpinePathConstraintData::get_target() { auto s = get_spine_data()->getTarget(); - if(s == NULL) return NULL; + if (s == NULL) return NULL; Ref gd_s(memnew(SpineSlotData)); gd_s->set_spine_object(s); return gd_s; } -void SpinePathConstraintData::set_target(Ref v){ - if(v.is_valid()){ +void SpinePathConstraintData::set_target(Ref v) { + if (v.is_valid()) { get_spine_data()->setTarget(v->get_spine_object()); - }else{ + } else { get_spine_data()->setTarget(NULL); } } -SpinePathConstraintData::PositionMode SpinePathConstraintData::get_position_mode(){ +SpinePathConstraintData::PositionMode SpinePathConstraintData::get_position_mode() { auto m = (int) get_spine_data()->getPositionMode(); return (PositionMode) m; } -void SpinePathConstraintData::set_position_mode(PositionMode v){ +void SpinePathConstraintData::set_position_mode(PositionMode 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(); return (SpacingMode) m; } -void SpinePathConstraintData::set_spacing_mode(SpacingMode v){ +void SpinePathConstraintData::set_spacing_mode(SpacingMode 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(); return (RotateMode) m; } -void SpinePathConstraintData::set_rotate_mode(RotateMode v){ +void SpinePathConstraintData::set_rotate_mode(RotateMode 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(); } -void SpinePathConstraintData::set_offset_rotation(float v){ +void SpinePathConstraintData::set_offset_rotation(float v) { get_spine_data()->setOffsetRotation(v); } -float SpinePathConstraintData::get_position(){ +float SpinePathConstraintData::get_position() { return get_spine_data()->getPosition(); } -void SpinePathConstraintData::set_position(float v){ +void SpinePathConstraintData::set_position(float v) { get_spine_data()->setPosition(v); } -float SpinePathConstraintData::get_spacing(){ +float SpinePathConstraintData::get_spacing() { return get_spine_data()->getSpacing(); } -void SpinePathConstraintData::set_spacing(float v){ +void SpinePathConstraintData::set_spacing(float v) { get_spine_data()->setSpacing(v); } -float SpinePathConstraintData::get_mix_rotate(){ +float SpinePathConstraintData::get_mix_rotate() { return get_spine_data()->getMixRotate(); } -void SpinePathConstraintData::set_mix_rotate(float v){ +void SpinePathConstraintData::set_mix_rotate(float v) { get_spine_data()->setMixRotate(v); } -float SpinePathConstraintData::get_mix_x(){ +float SpinePathConstraintData::get_mix_x() { return get_spine_data()->getMixX(); } -void SpinePathConstraintData::set_mix_x(float v){ +void SpinePathConstraintData::set_mix_x(float v) { get_spine_data()->setMixX(v); } -float SpinePathConstraintData::get_mix_y(){ +float SpinePathConstraintData::get_mix_y() { return get_spine_data()->getMixY(); } -void SpinePathConstraintData::set_mix_y(float v){ +void SpinePathConstraintData::set_mix_y(float v) { get_spine_data()->setMixY(v); } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpinePathConstraintData.h b/spine-godot/spine_godot/SpinePathConstraintData.h index 1152998a4..068a68ec0 100644 --- a/spine-godot/spine_godot/SpinePathConstraintData.h +++ b/spine-godot/spine_godot/SpinePathConstraintData.h @@ -48,8 +48,8 @@ public: SpinePathConstraintData(); ~SpinePathConstraintData(); - virtual inline spine::PathConstraintData *get_spine_data(){ - return (spine::PathConstraintData*) SpineConstraintData::get_spine_object(); + virtual inline spine::PathConstraintData *get_spine_data() { + return (spine::PathConstraintData *) SpineConstraintData::get_spine_object(); } enum PositionMode { @@ -105,4 +105,4 @@ public: VARIANT_ENUM_CAST(SpinePathConstraintData::PositionMode); VARIANT_ENUM_CAST(SpinePathConstraintData::SpacingMode); VARIANT_ENUM_CAST(SpinePathConstraintData::RotateMode); -#endif //GODOT_SPINEPATHCONSTRAINTDATA_H +#endif//GODOT_SPINEPATHCONSTRAINTDATA_H diff --git a/spine-godot/spine_godot/SpineRendererObject.h b/spine-godot/spine_godot/SpineRendererObject.h index e8cb3b333..1076d52bd 100644 --- a/spine-godot/spine_godot/SpineRendererObject.h +++ b/spine-godot/spine_godot/SpineRendererObject.h @@ -34,9 +34,9 @@ struct SpineRendererObject { - Ref tex; - Ref normal_tex; + Ref tex; + Ref normal_tex; }; -#endif +#endif diff --git a/spine-godot/spine_godot/SpineRuntimeEditorPlugin.cpp b/spine-godot/spine_godot/SpineRuntimeEditorPlugin.cpp index 773e199c7..80de73af7 100644 --- a/spine-godot/spine_godot/SpineRuntimeEditorPlugin.cpp +++ b/spine-godot/spine_godot/SpineRuntimeEditorPlugin.cpp @@ -36,64 +36,63 @@ #include "SpineSprite.h" -Error SpineAtlasResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata){ - Ref res(memnew(SpineAtlasResource)); - res->set_normal_texture_prefix(p_options["normal_texture_prefix"]); - res->load_from_atlas_file(p_source_file); +Error SpineAtlasResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { + Ref res(memnew(SpineAtlasResource)); + res->set_normal_texture_prefix(p_options["normal_texture_prefix"]); + res->load_from_atlas_file(p_source_file); - String file_name = vformat("%s.%s", p_save_path, get_save_extension()); - auto err = ResourceSaver::save(file_name, res); - return err; + String file_name = vformat("%s.%s", p_save_path, get_save_extension()); + auto err = ResourceSaver::save(file_name, res); + return err; } void SpineAtlasResourceImportPlugin::get_import_options(List *r_options, int p_preset) const { - if (p_preset == 0) { - ImportOption op; - op.option.name = "normal_texture_prefix"; - op.option.type = Variant::STRING; - op.option.hint_string = "String"; - op.default_value = String("n"); - r_options->push_back(op); - } + if (p_preset == 0) { + ImportOption op; + op.option.name = "normal_texture_prefix"; + op.option.type = Variant::STRING; + op.option.hint_string = "String"; + op.default_value = String("n"); + r_options->push_back(op); + } } -Error SpineJsonResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata){ - Ref res(memnew(SpineSkeletonJsonDataResource)); - res->load_from_file(p_source_file); +Error SpineJsonResourceImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) { + Ref res(memnew(SpineSkeletonJsonDataResource)); + res->load_from_file(p_source_file); - String file_name = vformat("%s.%s", p_save_path, get_save_extension()); - auto err = ResourceSaver::save(file_name, res); - return err; + String file_name = vformat("%s.%s", p_save_path, get_save_extension()); + auto err = ResourceSaver::save(file_name, res); + return err; } //=======================| SpineRuntimeEditorPlugin |============================ SpineRuntimeEditorPlugin::SpineRuntimeEditorPlugin(EditorNode *p_node) { - add_import_plugin(memnew(SpineAtlasResourceImportPlugin)); - add_import_plugin(memnew(SpineJsonResourceImportPlugin)); + add_import_plugin(memnew(SpineAtlasResourceImportPlugin)); + add_import_plugin(memnew(SpineJsonResourceImportPlugin)); - auto animate_button = memnew(ToolButton); - animate_button->set_text("Animate"); - add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU, animate_button); + auto animate_button = memnew(ToolButton); + animate_button->set_text("Animate"); + add_control_to_container(CONTAINER_CANVAS_EDITOR_MENU, animate_button); - animate_dialog = memnew(SpineSpriteAnimateDialog); - get_editor_interface()->get_base_control()->add_child(animate_dialog); - animate_dialog->set_animate_button(animate_button); - animate_dialog->set_plugin(this); + animate_dialog = memnew(SpineSpriteAnimateDialog); + get_editor_interface()->get_base_control()->add_child(animate_dialog); + animate_dialog->set_animate_button(animate_button); + animate_dialog->set_plugin(this); } SpineRuntimeEditorPlugin::~SpineRuntimeEditorPlugin() { - } 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) { - if (get_editor_interface()->get_selection()->get_selected_node_list().size() != 1) { - p_visible = false; - } - animate_dialog->get_animate_button()->set_visible(p_visible); + if (get_editor_interface()->get_selection()->get_selected_node_list().size() != 1) { + p_visible = false; + } + animate_dialog->get_animate_button()->set_visible(p_visible); } diff --git a/spine-godot/spine_godot/SpineRuntimeEditorPlugin.h b/spine-godot/spine_godot/SpineRuntimeEditorPlugin.h index e5233a00c..cf95ec696 100644 --- a/spine-godot/spine_godot/SpineRuntimeEditorPlugin.h +++ b/spine-godot/spine_godot/SpineRuntimeEditorPlugin.h @@ -34,35 +34,43 @@ #include "editor/editor_node.h" class SpineAtlasResourceImportPlugin : public EditorImportPlugin { - GDCLASS(SpineAtlasResourceImportPlugin, EditorImportPlugin); + GDCLASS(SpineAtlasResourceImportPlugin, EditorImportPlugin); public: - String get_importer_name() const override {return "spine.atlas";} - String get_visible_name() const override {return "Spine Runtime Atlas";} - void get_recognized_extensions(List *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";} - int get_preset_count() const override {return 1;} - String get_save_extension() const override {return "spatlas";} - String get_resource_type() const override {return "SpineAtlasResource";} - void get_import_options(List *r_options, int p_preset) const override; - bool get_option_visibility(const String &p_option, const Map &p_options) const override {return true;} - Error import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) override; + String get_importer_name() const override { return "spine.atlas"; } + String get_visible_name() const override { return "Spine Runtime Atlas"; } + void get_recognized_extensions(List *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"; + } + int get_preset_count() const override { return 1; } + String get_save_extension() const override { return "spatlas"; } + String get_resource_type() const override { return "SpineAtlasResource"; } + void get_import_options(List *r_options, int p_preset) const override; + bool get_option_visibility(const String &p_option, const Map &p_options) const override { return true; } + Error import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) override; }; class SpineJsonResourceImportPlugin : public EditorImportPlugin { -GDCLASS(SpineJsonResourceImportPlugin, EditorImportPlugin); + GDCLASS(SpineJsonResourceImportPlugin, EditorImportPlugin); public: - String get_importer_name() const override {return "spine.json";} - String get_visible_name() const override {return "Spine Runtime Json";} - void get_recognized_extensions(List *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";} - int get_preset_count() const override {return 1;} - String get_save_extension() const override {return "spjson";} - String get_resource_type() const override {return "SpineSkeletonJsonDataResource";} - void get_import_options(List *r_options, int p_preset) const override {} - bool get_option_visibility(const String &p_option, const Map &p_options) const override {return true;} - Error import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) override; + String get_importer_name() const override { return "spine.json"; } + String get_visible_name() const override { return "Spine Runtime Json"; } + void get_recognized_extensions(List *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"; + } + int get_preset_count() const override { return 1; } + String get_save_extension() const override { return "spjson"; } + String get_resource_type() const override { return "SpineSkeletonJsonDataResource"; } + void get_import_options(List *r_options, int p_preset) const override {} + bool get_option_visibility(const String &p_option, const Map &p_options) const override { return true; } + Error import(const String &p_source_file, const String &p_save_path, const Map &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) override; }; class SpineSpriteAnimateDialog; @@ -71,10 +79,11 @@ class SpineRuntimeEditorPlugin : public EditorPlugin { GDCLASS(SpineRuntimeEditorPlugin, EditorPlugin); protected: - SpineSpriteAnimateDialog *animate_dialog; + SpineSpriteAnimateDialog *animate_dialog; + public: - SpineRuntimeEditorPlugin(EditorNode *p_node); - ~SpineRuntimeEditorPlugin(); + SpineRuntimeEditorPlugin(EditorNode *p_node); + ~SpineRuntimeEditorPlugin(); String get_name() const override { return "SpineRuntimeEditorPlugin"; } bool has_main_screen() const { return false; } @@ -86,4 +95,4 @@ public: }; #endif -#endif //GODOT_SPINERUNTIMEEDITORPLUGIN_H +#endif//GODOT_SPINERUNTIMEEDITORPLUGIN_H diff --git a/spine-godot/spine_godot/SpineSkeleton.cpp b/spine-godot/spine_godot/SpineSkeleton.cpp index c8d207ea1..b8cedf0d5 100644 --- a/spine-godot/spine_godot/SpineSkeleton.cpp +++ b/spine-godot/spine_godot/SpineSkeleton.cpp @@ -30,49 +30,49 @@ #include "SpineSkeleton.h" void SpineSkeleton::_bind_methods() { -//void update_world_transform(); -// -// void set_to_setup_pose(); -// -// void set_bones_to_setup_pose(); -// -// void set_slots_to_setup_pose(); + //void update_world_transform(); + // + // void set_to_setup_pose(); + // + // void set_bones_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("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_slots_to_setup_pose"), &SpineSkeleton::set_slots_to_setup_pose); -// -// Ref find_bone(const String &name); -// int find_bone_index(const String &name); -// -// Ref find_slot(const String &name); -// int find_slot_index(const String &name); -// -// void set_skin_by_name(const String &skin_name); -// void set_skin(Ref new_skin); -// -// Ref get_attachment_by_slot_name(const String &slot_name, const String &attachment_name); -// Ref 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_slot", "slot_name"), &SpineSkeleton::find_slot); + // + // Ref find_bone(const String &name); + // int find_bone_index(const String &name); + // + // Ref find_slot(const String &name); + // int find_slot_index(const String &name); + // + // void set_skin_by_name(const String &skin_name); + // void set_skin(Ref new_skin); + // + // Ref get_attachment_by_slot_name(const String &slot_name, const String &attachment_name); + // Ref 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_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", "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_index", "slot_index", "attachment_name"), &SpineSkeleton::get_attachment_by_slot_index); -// -// void set_attachment(const String &slot_name, const String &attachment_name); -// -// Ref find_ik_constraint(const String &constraint_name); -// Ref find_transform_constraint(const String &constraint_name); -// Ref find_path_constraint(const String &constraint_name); -// -// void update(float delta); -// -// Dictionary get_bounds(); -// -// Ref get_root_bone(); -// -// Ref get_data(); + // + // void set_attachment(const String &slot_name, const String &attachment_name); + // + // Ref find_ik_constraint(const String &constraint_name); + // Ref find_transform_constraint(const String &constraint_name); + // Ref find_path_constraint(const String &constraint_name); + // + // void update(float delta); + // + // Dictionary get_bounds(); + // + // Ref get_root_bone(); + // + // Ref get_data(); 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_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_root_bone"), &SpineSkeleton::get_root_bone); ClassDB::bind_method(D_METHOD("get_data"), &SpineSkeleton::get_data); -// -// Array get_bones(); -// Array get_slots(); -// Array get_draw_orders(); -// Array get_ik_constraints(); -// Array get_path_constraints(); -// Array get_transform_constraints(); -// -// Ref get_skin(); + // + // Array get_bones(); + // Array get_slots(); + // Array get_draw_orders(); + // Array get_ik_constraints(); + // Array get_path_constraints(); + // Array get_transform_constraints(); + // + // Ref get_skin(); 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_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_transform_constraints"), &SpineSkeleton::get_transform_constraints); ClassDB::bind_method(D_METHOD("get_skin"), &SpineSkeleton::get_skin); -// -// Color get_color(); -// void set_color(Color v); -// -// float get_time(); -// void set_time(float v); -// -// void set_position(Vector2 pos); + // + // Color get_color(); + // void set_color(Color v); + // + // float get_time(); + // void set_time(float v); + // + // void set_position(Vector2 pos); 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("get_time"), &SpineSkeleton::get_time); ClassDB::bind_method(D_METHOD("set_time", "v"), &SpineSkeleton::set_time); ClassDB::bind_method(D_METHOD("set_position", "pos"), &SpineSkeleton::set_position); -// -// float get_x(); -// void set_x(float v); -// -// float get_y(); -// void set_y(float v); -// -// float get_scale_x(); -// void set_scale_x(float v); -// -// float get_scale_y(); -// void set_scale_y(float v); + // + // float get_x(); + // void set_x(float v); + // + // float get_y(); + // void set_y(float v); + // + // float get_scale_x(); + // void set_scale_x(float v); + // + // float get_scale_y(); + // void set_scale_y(float v); 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("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); } -SpineSkeleton::SpineSkeleton():skeleton(NULL),spine_object(false),the_sprite(nullptr) { - +SpineSkeleton::SpineSkeleton() : skeleton(NULL), spine_object(false), the_sprite(nullptr) { } SpineSkeleton::~SpineSkeleton() { - if(skeleton && !spine_object) - { + if (skeleton && !spine_object) { delete skeleton; skeleton = NULL; } } void SpineSkeleton::load_skeleton(Ref sd) { - if(skeleton && !spine_object) - { + if (skeleton && !spine_object) { delete skeleton; skeleton = NULL; } @@ -155,103 +152,103 @@ void SpineSkeleton::load_skeleton(Ref sd) { } #define S_T(x) (spine::String(x.utf8())) -void SpineSkeleton::update_world_transform(){ +void SpineSkeleton::update_world_transform() { skeleton->updateWorldTransform(); } -void SpineSkeleton::set_to_setup_pose(){ +void SpineSkeleton::set_to_setup_pose() { skeleton->setToSetupPose(); } -void SpineSkeleton::set_bones_to_setup_pose(){ +void SpineSkeleton::set_bones_to_setup_pose() { skeleton->setBonesToSetupPose(); } -void SpineSkeleton::set_slots_to_setup_pose(){ +void SpineSkeleton::set_slots_to_setup_pose() { skeleton->setSlotsToSetupPose(); } -Ref SpineSkeleton::find_bone(const String &name){ - if(name.empty()) return NULL; +Ref SpineSkeleton::find_bone(const String &name) { + if (name.empty()) return NULL; auto b = skeleton->findBone(S_T(name)); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineBone)); gd_b->set_spine_object(b); gd_b->set_spine_sprite(the_sprite); return gd_b; } -Ref SpineSkeleton::find_slot(const String &name){ - if(name.empty()) return NULL; +Ref SpineSkeleton::find_slot(const String &name) { + if (name.empty()) return NULL; auto s = skeleton->findSlot(S_T(name)); - if(s == NULL) return NULL; + if (s == NULL) return NULL; Ref gd_s(memnew(SpineSlot)); gd_s->set_spine_object(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)); } -void SpineSkeleton::set_skin(Ref new_skin){ - if(new_skin.is_valid()){ +void SpineSkeleton::set_skin(Ref new_skin) { + if (new_skin.is_valid()) { skeleton->setSkin(new_skin->get_spine_object()); - }else{ + } else { skeleton->setSkin(NULL); } } -Ref SpineSkeleton::get_attachment_by_slot_name(const String &slot_name, const String &attachment_name){ +Ref 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)); - if(a == NULL) return NULL; + if (a == NULL) return NULL; Ref gd_a(memnew(SpineAttachment)); gd_a->set_spine_object(a); return gd_a; } -Ref SpineSkeleton::get_attachment_by_slot_index(int slot_index, const String &attachment_name){ +Ref SpineSkeleton::get_attachment_by_slot_index(int slot_index, const String &attachment_name) { auto a = skeleton->getAttachment(slot_index, S_T(attachment_name)); - if(a == NULL) return NULL; + if (a == NULL) return NULL; Ref gd_a(memnew(SpineAttachment)); gd_a->set_spine_object(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(get_attachment_by_slot_name(slot_name, attachment_name) == NULL); skeleton->setAttachment(S_T(slot_name), S_T(attachment_name)); } -Ref SpineSkeleton::find_ik_constraint(const String &constraint_name){ - if(constraint_name.empty()) return NULL; +Ref SpineSkeleton::find_ik_constraint(const String &constraint_name) { + if (constraint_name.empty()) return NULL; auto c = skeleton->findIkConstraint(S_T(constraint_name)); - if(c == NULL) return NULL; + if (c == NULL) return NULL; Ref gd_c(memnew(SpineIkConstraint)); gd_c->set_spine_object(c); return gd_c; } -Ref SpineSkeleton::find_transform_constraint(const String &constraint_name){ - if(constraint_name.empty()) return NULL; +Ref SpineSkeleton::find_transform_constraint(const String &constraint_name) { + if (constraint_name.empty()) return NULL; auto c = skeleton->findTransformConstraint(S_T(constraint_name)); - if(c == NULL) return NULL; + if (c == NULL) return NULL; Ref gd_c(memnew(SpineTransformConstraint)); gd_c->set_spine_object(c); return gd_c; } -Ref SpineSkeleton::find_path_constraint(const String &constraint_name){ - if(constraint_name.empty()) return NULL; +Ref SpineSkeleton::find_path_constraint(const String &constraint_name) { + if (constraint_name.empty()) return NULL; auto c = skeleton->findPathConstraint(S_T(constraint_name)); - if(c == NULL) return NULL; + if (c == NULL) return NULL; Ref gd_c(memnew(SpinePathConstraint)); gd_c->set_spine_object(c); return gd_c; } -void SpineSkeleton::update(float delta){ +void SpineSkeleton::update(float delta) { skeleton->update(delta); } -Dictionary SpineSkeleton::get_bounds(){ +Dictionary SpineSkeleton::get_bounds() { float x, y, w, h; spine::Vector vertex_buffer; skeleton->getBounds(x, y, w, h, vertex_buffer); @@ -264,7 +261,7 @@ Dictionary SpineSkeleton::get_bounds(){ Array gd_a; gd_a.resize(vertex_buffer.size()); - for(size_t i=0; i SpineSkeleton::get_root_bone(){ +Ref SpineSkeleton::get_root_bone() { auto b = skeleton->getRootBone(); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineBone)); gd_b->set_spine_object(b); gd_b->set_spine_sprite(the_sprite); @@ -283,19 +280,19 @@ Ref SpineSkeleton::get_root_bone(){ Ref SpineSkeleton::get_data() const { auto sd = skeleton->getData(); - if(sd == NULL) return NULL; + if (sd == NULL) return NULL; Ref gd_sd(memnew(SpineSkeletonDataResource)); gd_sd->set_spine_object(sd); return gd_sd; } -Array SpineSkeleton::get_bones(){ +Array SpineSkeleton::get_bones() { auto &as = skeleton->getBones(); Array gd_as; gd_as.resize(as.size()); - for(size_t i=0; i(NULL); + if (b == NULL) gd_as[i] = Ref(NULL); Ref gd_a(memnew(SpineBone)); gd_a->set_spine_object(b); gd_a->set_spine_sprite(the_sprite); @@ -303,65 +300,65 @@ Array SpineSkeleton::get_bones(){ } return gd_as; } -Array SpineSkeleton::get_slots(){ +Array SpineSkeleton::get_slots() { auto &as = skeleton->getSlots(); Array gd_as; gd_as.resize(as.size()); - for(size_t i=0; i(NULL); + if (b == NULL) gd_as[i] = Ref(NULL); Ref gd_a(memnew(SpineSlot)); gd_a->set_spine_object(b); gd_as[i] = gd_a; } return gd_as; } -Array SpineSkeleton::get_draw_orders(){ +Array SpineSkeleton::get_draw_orders() { auto &as = skeleton->getDrawOrder(); Array gd_as; gd_as.resize(as.size()); - for(size_t i=0; i(NULL); + if (b == NULL) gd_as[i] = Ref(NULL); Ref gd_a(memnew(SpineSlot)); gd_a->set_spine_object(b); gd_as[i] = gd_a; } return gd_as; } -Array SpineSkeleton::get_ik_constraints(){ +Array SpineSkeleton::get_ik_constraints() { auto &as = skeleton->getIkConstraints(); Array gd_as; gd_as.resize(as.size()); - for(size_t i=0; i(NULL); + if (b == NULL) gd_as[i] = Ref(NULL); Ref gd_a(memnew(SpineIkConstraint)); gd_a->set_spine_object(b); gd_as[i] = gd_a; } return gd_as; } -Array SpineSkeleton::get_path_constraints(){ +Array SpineSkeleton::get_path_constraints() { auto &as = skeleton->getPathConstraints(); Array gd_as; gd_as.resize(as.size()); - for(size_t i=0; i(NULL); + if (b == NULL) gd_as[i] = Ref(NULL); Ref gd_a(memnew(SpinePathConstraint)); gd_a->set_spine_object(b); gd_as[i] = gd_a; } return gd_as; } -Array SpineSkeleton::get_transform_constraints(){ +Array SpineSkeleton::get_transform_constraints() { auto &as = skeleton->getTransformConstraints(); Array gd_as; gd_as.resize(as.size()); - for(size_t i=0; i(NULL); + if (b == NULL) gd_as[i] = Ref(NULL); Ref gd_a(memnew(SpineTransformConstraint)); gd_a->set_spine_object(b); gd_as[i] = gd_a; @@ -369,62 +366,62 @@ Array SpineSkeleton::get_transform_constraints(){ return gd_as; } -Ref SpineSkeleton::get_skin(){ +Ref SpineSkeleton::get_skin() { auto s = skeleton->getSkin(); - if(s == NULL) return NULL; + if (s == NULL) return NULL; Ref gd_s(memnew(SpineSkin)); gd_s->set_spine_object(s); return gd_s; } -Color SpineSkeleton::get_color(){ +Color SpineSkeleton::get_color() { auto &c = skeleton->getColor(); 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(); c.set(v.r, v.g, v.b, v.a); } -float SpineSkeleton::get_time(){ +float SpineSkeleton::get_time() { return skeleton->getTime(); } -void SpineSkeleton::set_time(float v){ +void SpineSkeleton::set_time(float v) { skeleton->setTime(v); } -void SpineSkeleton::set_position(Vector2 pos){ +void SpineSkeleton::set_position(Vector2 pos) { skeleton->setPosition(pos.x, pos.y); } -float SpineSkeleton::get_x(){ +float SpineSkeleton::get_x() { return skeleton->getX(); } -void SpineSkeleton::set_x(float v){ +void SpineSkeleton::set_x(float v) { skeleton->setX(v); } -float SpineSkeleton::get_y(){ +float SpineSkeleton::get_y() { return skeleton->getY(); } -void SpineSkeleton::set_y(float v){ +void SpineSkeleton::set_y(float v) { skeleton->setY(v); } -float SpineSkeleton::get_scale_x(){ +float SpineSkeleton::get_scale_x() { return skeleton->getScaleX(); } -void SpineSkeleton::set_scale_x(float v){ +void SpineSkeleton::set_scale_x(float v) { skeleton->setScaleX(v); } -float SpineSkeleton::get_scale_y(){ +float SpineSkeleton::get_scale_y() { return skeleton->getScaleY(); } -void SpineSkeleton::set_scale_y(float v){ +void SpineSkeleton::set_scale_y(float v) { skeleton->setScaleY(v); } void SpineSkeleton::set_spine_sprite(SpineSprite *s) { - the_sprite = s; + the_sprite = s; } diff --git a/spine-godot/spine_godot/SpineSkeleton.h b/spine-godot/spine_godot/SpineSkeleton.h index fa488bfa4..14e5bc3bb 100644 --- a/spine-godot/spine_godot/SpineSkeleton.h +++ b/spine-godot/spine_godot/SpineSkeleton.h @@ -40,7 +40,7 @@ class SpineSprite; -class SpineSkeleton : public Reference{ +class SpineSkeleton : public Reference { GDCLASS(SpineSkeleton, Reference); protected: @@ -51,18 +51,18 @@ private: bool spine_object; SpineSprite *the_sprite; -public: +public: SpineSkeleton(); ~SpineSkeleton(); void load_skeleton(Ref sd); - inline void set_spine_object(spine::Skeleton *s){ + inline void set_spine_object(spine::Skeleton *s) { skeleton = s; spine_object = true; } - inline spine::Skeleton *get_spine_object(){ + inline spine::Skeleton *get_spine_object() { return skeleton; } @@ -79,7 +79,7 @@ public: Ref find_bone(const String &name); - Ref find_slot(const String &name); + Ref find_slot(const String &name); void set_skin_by_name(const String &skin_name); void set_skin(Ref new_skin); @@ -129,7 +129,6 @@ public: float get_scale_y(); void set_scale_y(float v); - }; -#endif //GODOT_SPINESKELETON_H +#endif//GODOT_SPINESKELETON_H diff --git a/spine-godot/spine_godot/SpineSkeletonDataResource.cpp b/spine-godot/spine_godot/SpineSkeletonDataResource.cpp index d6f5c87a6..f360433f3 100644 --- a/spine-godot/spine_godot/SpineSkeletonDataResource.cpp +++ b/spine-godot/spine_godot/SpineSkeletonDataResource.cpp @@ -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("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("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("get_sk_name"), &SpineSkeletonDataResource::get_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"); } -SpineSkeletonDataResource::SpineSkeletonDataResource():valid(false),spine_object(false),skeleton_data(NULL) { - +SpineSkeletonDataResource::SpineSkeletonDataResource() : valid(false), spine_object(false), skeleton_data(NULL) { } SpineSkeletonDataResource::~SpineSkeletonDataResource() { - if(skeleton_data && !spine_object) - { + if (skeleton_data && !spine_object) { delete skeleton_data; skeleton_data = NULL; } } -bool SpineSkeletonDataResource::is_skeleton_data_loaded() const{ +bool SpineSkeletonDataResource::is_skeleton_data_loaded() const { return valid || spine_object; } @@ -94,29 +92,25 @@ void SpineSkeletonDataResource::load_res(spine::Atlas *a, const String &json_str auto path = get_path(); spine::SkeletonJson json(a); 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 msg: ") + json.getError().buffer()); return; } - if(skeleton_data) - { + if (skeleton_data) { delete skeleton_data; skeleton_data = NULL; } skeleton_data = temp_skeleton_data; valid = true; -// print_line("Skeleton json data loaded!"); + // print_line("Skeleton json data loaded!"); } 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()); - if(valid) - { + if (valid) { emit_signal("skeleton_data_loaded"); } } @@ -125,12 +119,12 @@ void SpineSkeletonDataResource::update_skeleton_data() { void SpineSkeletonDataResource::set_atlas_res(const Ref &a) { atlas_res = a; valid = false; -// print_line("atlas_res_changed emitted"); + // print_line("atlas_res_changed emitted"); emit_signal("atlas_res_changed"); update_skeleton_data(); } Ref 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!"); } return atlas_res; @@ -139,27 +133,35 @@ Ref SpineSkeletonDataResource::get_atlas_res() { void SpineSkeletonDataResource::set_skeleton_json_res(const Ref &s) { skeleton_json_res = s; valid = false; -// print_line("skeleton_json_res_changed emitted"); + // print_line("skeleton_json_res_changed emitted"); emit_signal("skeleton_json_res_changed"); update_skeleton_data(); } Ref 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!"); } return skeleton_json_res; } -#define CHECK_V 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 CHECK_V \ + 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())) Ref SpineSkeletonDataResource::find_animation(const String &animation_name) { CHECK_X(NULL); - if(animation_name.empty()){ + if (animation_name.empty()) { return NULL; } auto a = skeleton_data->findAnimation(S_T(animation_name)); - if(!a) return NULL; + if (!a) return NULL; Ref sa(memnew(SpineAnimation)); sa->set_spine_object(a); return sa; @@ -209,73 +211,73 @@ void SpineSkeletonDataResource::set_fps(float v) { skeleton_data->setFps(v); } -Ref SpineSkeletonDataResource::find_bone(const String &bone_name){ - if(bone_name.empty()) return NULL; +Ref SpineSkeletonDataResource::find_bone(const String &bone_name) { + if (bone_name.empty()) return NULL; auto b = skeleton_data->findBone(S_T(bone_name)); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineBoneData)); gd_b->set_spine_object(b); return gd_b; } -Ref SpineSkeletonDataResource::find_slot(const String &slot_name){ - if(slot_name.empty()) return NULL; +Ref SpineSkeletonDataResource::find_slot(const String &slot_name) { + if (slot_name.empty()) return NULL; auto b = skeleton_data->findSlot(S_T(slot_name)); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineSlotData)); gd_b->set_spine_object(b); return gd_b; } -Ref SpineSkeletonDataResource::find_skin(const String &skin_name){ - if(skin_name.empty()) return NULL; +Ref SpineSkeletonDataResource::find_skin(const String &skin_name) { + if (skin_name.empty()) return NULL; auto b = skeleton_data->findSkin(S_T(skin_name)); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineSkin)); gd_b->set_spine_object(b); return gd_b; } -Ref SpineSkeletonDataResource::find_event(const String &event_data_name){ - if(event_data_name.empty()) return NULL; +Ref SpineSkeletonDataResource::find_event(const String &event_data_name) { + if (event_data_name.empty()) return NULL; auto b = skeleton_data->findEvent(S_T(event_data_name)); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineEventData)); gd_b->set_spine_object(b); return gd_b; } -Ref SpineSkeletonDataResource::find_ik_constraint(const String &constraint_name){ - if(constraint_name.empty()) return NULL; +Ref SpineSkeletonDataResource::find_ik_constraint(const String &constraint_name) { + if (constraint_name.empty()) return NULL; auto b = skeleton_data->findIkConstraint(S_T(constraint_name)); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineIkConstraintData)); gd_b->set_spine_object(b); return gd_b; } -Ref SpineSkeletonDataResource::find_transform_constraint(const String &constraint_name){ - if(constraint_name.empty()) return NULL; +Ref SpineSkeletonDataResource::find_transform_constraint(const String &constraint_name) { + if (constraint_name.empty()) return NULL; auto b = skeleton_data->findTransformConstraint(S_T(constraint_name)); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineTransformConstraintData)); gd_b->set_spine_object(b); return gd_b; } -Ref SpineSkeletonDataResource::find_path_constraint(const String &constraint_name){ - if(constraint_name.empty()) return NULL; +Ref SpineSkeletonDataResource::find_path_constraint(const String &constraint_name) { + if (constraint_name.empty()) return NULL; auto b = skeleton_data->findPathConstraint(S_T(constraint_name)); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpinePathConstraintData)); gd_b->set_spine_object(b); return gd_b; } -Array SpineSkeletonDataResource::get_bones(){ +Array SpineSkeletonDataResource::get_bones() { auto bs = skeleton_data->getBones(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i < bs.size(); ++i){ - if(bs[i] == NULL) gd_bs[i] = Ref(NULL); + for (size_t i = 0; i < bs.size(); ++i) { + if (bs[i] == NULL) gd_bs[i] = Ref(NULL); else { Ref gd_b(memnew(SpineBoneData)); gd_b->set_spine_object(bs[i]); @@ -284,12 +286,12 @@ Array SpineSkeletonDataResource::get_bones(){ } return gd_bs; } -Array SpineSkeletonDataResource::get_slots(){ +Array SpineSkeletonDataResource::get_slots() { auto bs = skeleton_data->getSlots(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i < bs.size(); ++i){ - if(bs[i] == NULL) gd_bs[i] = Ref(NULL); + for (size_t i = 0; i < bs.size(); ++i) { + if (bs[i] == NULL) gd_bs[i] = Ref(NULL); else { Ref gd_b(memnew(SpineSlotData)); gd_b->set_spine_object(bs[i]); @@ -298,12 +300,12 @@ Array SpineSkeletonDataResource::get_slots(){ } return gd_bs; } -Array SpineSkeletonDataResource::get_skins() const{ +Array SpineSkeletonDataResource::get_skins() const { auto bs = skeleton_data->getSkins(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i < bs.size(); ++i){ - if(bs[i] == NULL) gd_bs[i] = Ref(NULL); + for (size_t i = 0; i < bs.size(); ++i) { + if (bs[i] == NULL) gd_bs[i] = Ref(NULL); else { Ref gd_b(memnew(SpineSkin)); gd_b->set_spine_object(bs[i]); @@ -313,26 +315,26 @@ Array SpineSkeletonDataResource::get_skins() const{ return gd_bs; } -Ref SpineSkeletonDataResource::get_default_skin(){ +Ref SpineSkeletonDataResource::get_default_skin() { auto b = skeleton_data->getDefaultSkin(); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineSkin)); gd_b->set_spine_object(b); return gd_b; } -void SpineSkeletonDataResource::set_default_skin(Ref v){ - if(v.is_valid()){ +void SpineSkeletonDataResource::set_default_skin(Ref v) { + if (v.is_valid()) { skeleton_data->setDefaultSkin(v->get_spine_object()); } else skeleton_data->setDefaultSkin(NULL); } -Array SpineSkeletonDataResource::get_events(){ +Array SpineSkeletonDataResource::get_events() { auto bs = skeleton_data->getEvents(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i < bs.size(); ++i){ - if(bs[i] == NULL) gd_bs[i] = Ref(NULL); + for (size_t i = 0; i < bs.size(); ++i) { + if (bs[i] == NULL) gd_bs[i] = Ref(NULL); else { Ref gd_b(memnew(SpineEventData)); gd_b->set_spine_object(bs[i]); @@ -341,12 +343,12 @@ Array SpineSkeletonDataResource::get_events(){ } return gd_bs; } -Array SpineSkeletonDataResource::get_animations(){ +Array SpineSkeletonDataResource::get_animations() { auto bs = skeleton_data->getAnimations(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i < bs.size(); ++i){ - if(bs[i] == NULL) gd_bs[i] = Ref(NULL); + for (size_t i = 0; i < bs.size(); ++i) { + if (bs[i] == NULL) gd_bs[i] = Ref(NULL); else { Ref gd_b(memnew(SpineAnimation)); gd_b->set_spine_object(bs[i]); @@ -355,12 +357,12 @@ Array SpineSkeletonDataResource::get_animations(){ } return gd_bs; } -Array SpineSkeletonDataResource::get_ik_constraints(){ +Array SpineSkeletonDataResource::get_ik_constraints() { auto bs = skeleton_data->getIkConstraints(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i < bs.size(); ++i){ - if(bs[i] == NULL) gd_bs[i] = Ref(NULL); + for (size_t i = 0; i < bs.size(); ++i) { + if (bs[i] == NULL) gd_bs[i] = Ref(NULL); else { Ref gd_b(memnew(SpineIkConstraintData)); gd_b->set_spine_object(bs[i]); @@ -369,12 +371,12 @@ Array SpineSkeletonDataResource::get_ik_constraints(){ } return gd_bs; } -Array SpineSkeletonDataResource::get_transform_constraints(){ +Array SpineSkeletonDataResource::get_transform_constraints() { auto bs = skeleton_data->getTransformConstraints(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i < bs.size(); ++i){ - if(bs[i] == NULL) gd_bs[i] = Ref(NULL); + for (size_t i = 0; i < bs.size(); ++i) { + if (bs[i] == NULL) gd_bs[i] = Ref(NULL); else { Ref gd_b(memnew(SpineTransformConstraintData)); gd_b->set_spine_object(bs[i]); @@ -383,12 +385,12 @@ Array SpineSkeletonDataResource::get_transform_constraints(){ } return gd_bs; } -Array SpineSkeletonDataResource::get_path_constraints(){ +Array SpineSkeletonDataResource::get_path_constraints() { auto bs = skeleton_data->getPathConstraints(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i < bs.size(); ++i){ - if(bs[i] == NULL) gd_bs[i] = Ref(NULL); + for (size_t i = 0; i < bs.size(); ++i) { + if (bs[i] == NULL) gd_bs[i] = Ref(NULL); else { Ref gd_b(memnew(SpinePathConstraintData)); gd_b->set_spine_object(bs[i]); @@ -402,53 +404,53 @@ Array SpineSkeletonDataResource::get_path_constraints(){ #undef CHECK_X //External feature functions -void SpineSkeletonDataResource::get_animation_names(Vector &res) const{ - res.clear(); - if(!is_skeleton_data_loaded()){ +void SpineSkeletonDataResource::get_animation_names(Vector &res) const { + res.clear(); + if (!is_skeleton_data_loaded()) { return; } auto as = skeleton_data->getAnimations(); - for(size_t i=0; igetName().buffer()); - }else{ - res.push_back(""); + if (a) { + res.push_back(a->getName().buffer()); + } else { + res.push_back(""); } } } -void SpineSkeletonDataResource::get_skin_names(Vector &res) const{ - res.clear(); - if(!is_skeleton_data_loaded()){ +void SpineSkeletonDataResource::get_skin_names(Vector &res) const { + res.clear(); + if (!is_skeleton_data_loaded()) { return; } auto as = get_skins(); res.resize(as.size()); - for(size_t i=0; i(as[i]); - if(a.is_valid()){ + if (a.is_valid()) { res.push_back(a->get_skin_name()); - }else{ - res.push_back(""); + } else { + res.push_back(""); } } } -void SpineSkeletonDataResource::_get_property_list(List *p_list) const{ - PropertyInfo p; - Vector res; +void SpineSkeletonDataResource::_get_property_list(List *p_list) const { + PropertyInfo p; + Vector res; - p.name = "animations"; - p.type = Variant::STRING; - get_animation_names(res); - p.hint_string = String(",").join(res); - p.hint = PROPERTY_HINT_ENUM; - p_list->push_back(p); + p.name = "animations"; + p.type = Variant::STRING; + get_animation_names(res); + p.hint_string = String(",").join(res); + p.hint = PROPERTY_HINT_ENUM; + p_list->push_back(p); - p.name = "skins"; - p.type = Variant::STRING; - get_skin_names(res); - p.hint_string = String(",").join(res); - p.hint = PROPERTY_HINT_ENUM; - p_list->push_back(p); + p.name = "skins"; + p.type = Variant::STRING; + get_skin_names(res); + p.hint_string = String(",").join(res); + p.hint = PROPERTY_HINT_ENUM; + p_list->push_back(p); } diff --git a/spine-godot/spine_godot/SpineSkeletonDataResource.h b/spine-godot/spine_godot/SpineSkeletonDataResource.h index 14fc17c19..eaabaa11c 100644 --- a/spine-godot/spine_godot/SpineSkeletonDataResource.h +++ b/spine-godot/spine_godot/SpineSkeletonDataResource.h @@ -45,7 +45,7 @@ #include "SpinePathConstraintData.h" #include "SpineEventData.h" -class SpineSkeletonDataResource : public Resource{ +class SpineSkeletonDataResource : public Resource { GDCLASS(SpineSkeletonDataResource, Resource); protected: @@ -60,14 +60,14 @@ private: spine::SkeletonData *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; - if(s) + if (s) spine_object = true; } - inline spine::SkeletonData *get_spine_object(){ + inline spine::SkeletonData *get_spine_object() { return skeleton_data; } @@ -76,7 +76,7 @@ public: SpineSkeletonDataResource(); virtual ~SpineSkeletonDataResource(); - void _get_property_list(List *p_list) const; + void _get_property_list(List *p_list) const; void set_atlas_res(const Ref &a); Ref get_atlas_res(); @@ -84,17 +84,17 @@ public: void set_skeleton_json_res(const Ref &s); Ref 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; void get_animation_names(Vector &l) const; - void get_skin_names(Vector &l) const; + void get_skin_names(Vector &l) const; // spine api - Ref find_bone(const String &bone_name); + Ref find_bone(const String &bone_name); - Ref find_slot(const String &slot_name); + Ref find_slot(const String &slot_name); Ref find_skin(const String &skin_name); @@ -104,7 +104,7 @@ public: Ref find_ik_constraint(const String &constraint_name); Ref find_transform_constraint(const String &constraint_name); - Ref find_path_constraint(const String &constraint_name); + Ref find_path_constraint(const String &constraint_name); Array get_bones(); Array get_slots(); @@ -137,4 +137,4 @@ public: void set_fps(float v); }; -#endif //GODOT_SPINESKELETONDATARESOURCE_H +#endif//GODOT_SPINESKELETONDATARESOURCE_H diff --git a/spine-godot/spine_godot/SpineSkeletonJsonDataResource.cpp b/spine-godot/spine_godot/SpineSkeletonJsonDataResource.cpp index ef4c18afb..d332a791a 100644 --- a/spine-godot/spine_godot/SpineSkeletonJsonDataResource.cpp +++ b/spine-godot/spine_godot/SpineSkeletonJsonDataResource.cpp @@ -34,22 +34,22 @@ void SpineSkeletonJsonDataResource::_bind_methods() { } Error SpineSkeletonJsonDataResource::load_from_file(const String &p_path) { - Error err; + Error err; - json_string = FileAccess::get_file_as_string(p_path, &err); - return err; + json_string = FileAccess::get_file_as_string(p_path, &err); + return err; } Error SpineSkeletonJsonDataResource::save_to_file(const String &p_path) { - Error err; - FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); - if (err != OK) { - if (file) file->close(); - return err; - } + Error err; + FileAccess *file = FileAccess::open(p_path, FileAccess::WRITE, &err); + if (err != OK) { + if (file) file->close(); + return err; + } - file->store_string(json_string); - file->close(); + file->store_string(json_string); + file->close(); - return OK; + return OK; } diff --git a/spine-godot/spine_godot/SpineSkeletonJsonDataResource.h b/spine-godot/spine_godot/SpineSkeletonJsonDataResource.h index 54e2fe650..8b6045bf6 100644 --- a/spine-godot/spine_godot/SpineSkeletonJsonDataResource.h +++ b/spine-godot/spine_godot/SpineSkeletonJsonDataResource.h @@ -32,18 +32,19 @@ #include "core/variant_parser.h" -class SpineSkeletonJsonDataResource : public Resource{ +class SpineSkeletonJsonDataResource : public Resource { GDCLASS(SpineSkeletonJsonDataResource, Resource); protected: static void _bind_methods(); - String json_string; -public: - inline const String &get_json_string() {return json_string;} + String json_string; - Error load_from_file(const String &p_path); - Error save_to_file(const String &p_path); +public: + 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 diff --git a/spine-godot/spine_godot/SpineSkin.cpp b/spine-godot/spine_godot/SpineSkin.cpp index 92ece10de..b30f01ae5 100644 --- a/spine-godot/spine_godot/SpineSkin.cpp +++ b/spine-godot/spine_godot/SpineSkin.cpp @@ -47,53 +47,53 @@ void SpineSkin::_bind_methods() { ClassDB::bind_method(D_METHOD("get_all_constraint_data"), &SpineSkin::get_constraint); } -SpineSkin::SpineSkin():skin(NULL) {} +SpineSkin::SpineSkin() : skin(NULL) {} SpineSkin::~SpineSkin() {} #define S_T(x) (spine::String(x.utf8())) -Ref SpineSkin::init(const String &name){ +Ref SpineSkin::init(const String &name) { skin = new spine::Skin(S_T(name)); return this; } -void SpineSkin::set_attachment(uint64_t slot_index, const String &name, Ref attachment){ - if(!attachment.is_valid()){ +void SpineSkin::set_attachment(uint64_t slot_index, const String &name, Ref attachment) { + if (!attachment.is_valid()) { ERR_PRINT("attachment is invalid!"); return; } skin->setAttachment(slot_index, S_T(name), attachment->get_spine_object()); } -Ref SpineSkin::get_attachment(uint64_t slot_index, const String &name){ +Ref SpineSkin::get_attachment(uint64_t slot_index, const String &name) { auto a = skin->getAttachment(slot_index, S_T(name)); - if(a == NULL) return NULL; + if (a == NULL) return NULL; Ref gd_attachment(memnew(SpineAttachment)); gd_attachment->set_spine_object(a); 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)); } -Array SpineSkin::find_names_for_slot(uint64_t slot_index){ +Array SpineSkin::find_names_for_slot(uint64_t slot_index) { spine::Vector names; skin->findNamesForSlot(slot_index, names); Array gd_names; 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(); } return gd_names; } -Array SpineSkin::find_attachments_for_slot(uint64_t slot_index){ - spine::Vector as; +Array SpineSkin::find_attachments_for_slot(uint64_t slot_index) { + spine::Vector as; skin->findAttachmentsForSlot(slot_index, as); Array gd_as; gd_as.resize(as.size()); - for(size_t i=0; i < as.size(); ++i){ - if(as[i] == NULL) gd_as[i] = Ref(NULL); + for (size_t i = 0; i < as.size(); ++i) { + if (as[i] == NULL) gd_as[i] = Ref(NULL); else { Ref gd_a(memnew(SpineAttachment)); gd_a->set_spine_object(as[i]); @@ -103,41 +103,40 @@ Array SpineSkin::find_attachments_for_slot(uint64_t slot_index){ return gd_as; } -String SpineSkin::get_skin_name(){ +String SpineSkin::get_skin_name() { return skin->getName().buffer(); } -void SpineSkin::add_skin(Ref other){ - if(other.is_valid() && other->get_spine_object()){ +void SpineSkin::add_skin(Ref other) { + if (other.is_valid() && other->get_spine_object()) { skin->addSkin(other->get_spine_object()); - } else{ + } else { ERR_PRINT("other is NULL!"); } } -void SpineSkin::copy_skin(Ref other){ - if(other.is_valid() && other->get_spine_object()){ +void SpineSkin::copy_skin(Ref other) { + if (other.is_valid() && other->get_spine_object()) { skin->copySkin(other->get_spine_object()); - } else{ + } else { ERR_PRINT("other is NULL!"); } } -Ref SpineSkin::get_attachments(){ +Ref SpineSkin::get_attachments() { auto *es = new spine::Skin::AttachmentMap::Entries(skin->getAttachments()); Ref gd_es(memnew(SpineSkinAttachmentMapEntries)); gd_es->set_spine_object(es); return gd_es; - } -Array SpineSkin::get_bones(){ +Array SpineSkin::get_bones() { auto bs = skin->getBones(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i < bs.size(); ++i){ - if(bs[i] == NULL) gd_bs[i] = Ref(NULL); - else{ + for (size_t i = 0; i < bs.size(); ++i) { + if (bs[i] == NULL) gd_bs[i] = Ref(NULL); + else { Ref gd_b(memnew(SpineBoneData)); gd_b->set_spine_object(bs[i]); gd_bs[i] = gd_b; @@ -146,13 +145,13 @@ Array SpineSkin::get_bones(){ return gd_bs; } -Array SpineSkin::get_constraint(){ +Array SpineSkin::get_constraint() { auto cs = skin->getConstraints(); Array gd_cs; gd_cs.resize(cs.size()); - for(size_t i=0; i < cs.size(); ++i){ - if(cs[i] == NULL) gd_cs[i] = Ref(NULL); - else{ + for (size_t i = 0; i < cs.size(); ++i) { + if (cs[i] == NULL) gd_cs[i] = Ref(NULL); + else { Ref gd_c(memnew(SpineConstraintData)); gd_c->set_spine_object(cs[i]); gd_cs[i] = gd_c; diff --git a/spine-godot/spine_godot/SpineSkin.h b/spine-godot/spine_godot/SpineSkin.h index 1b6533414..3e1780f2a 100644 --- a/spine-godot/spine_godot/SpineSkin.h +++ b/spine-godot/spine_godot/SpineSkin.h @@ -50,10 +50,10 @@ public: SpineSkin(); ~SpineSkin(); - inline void set_spine_object(spine::Skin *s){ + inline void set_spine_object(spine::Skin *s) { skin = s; } - spine::Skin *get_spine_object(){ + spine::Skin *get_spine_object() { return skin; } @@ -82,4 +82,4 @@ public: Array get_constraint(); }; -#endif //GODOT_SPINESKIN_H +#endif//GODOT_SPINESKIN_H diff --git a/spine-godot/spine_godot/SpineSkinAttachmentMapEntries.cpp b/spine-godot/spine_godot/SpineSkinAttachmentMapEntries.cpp index 03e15203f..67089b011 100644 --- a/spine-godot/spine_godot/SpineSkinAttachmentMapEntries.cpp +++ b/spine-godot/spine_godot/SpineSkinAttachmentMapEntries.cpp @@ -38,33 +38,33 @@ void SpineSkinAttachmentMapEntry::_bind_methods() { ClassDB::bind_method(D_METHOD("set_attachment", "v"), &SpineSkinAttachmentMapEntry::set_attachment); } -SpineSkinAttachmentMapEntry::SpineSkinAttachmentMapEntry():entry(NULL) {} +SpineSkinAttachmentMapEntry::SpineSkinAttachmentMapEntry() : entry(NULL) {} SpineSkinAttachmentMapEntry::~SpineSkinAttachmentMapEntry() {} -uint64_t SpineSkinAttachmentMapEntry::get_slot_index(){ +uint64_t SpineSkinAttachmentMapEntry::get_slot_index() { return entry->_slotIndex; } -void SpineSkinAttachmentMapEntry::set_slot_index(uint64_t v){ +void SpineSkinAttachmentMapEntry::set_slot_index(uint64_t v) { entry->_slotIndex = v; } -String SpineSkinAttachmentMapEntry::get_entry_name(){ +String SpineSkinAttachmentMapEntry::get_entry_name() { 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()); } -Ref SpineSkinAttachmentMapEntry::get_attachment(){ - if(entry->_attachment == NULL) return NULL; +Ref SpineSkinAttachmentMapEntry::get_attachment() { + if (entry->_attachment == NULL) return NULL; Ref gd_attachment(memnew(SpineAttachment)); gd_attachment->set_spine_object(entry->_attachment); return gd_attachment; } -void SpineSkinAttachmentMapEntry::set_attachment(Ref v){ - if(v.is_valid()){ +void SpineSkinAttachmentMapEntry::set_attachment(Ref v) { + if (v.is_valid()) { entry->_attachment = v->get_spine_object(); - }else{ + } else { entry->_attachment = NULL; } } @@ -74,18 +74,18 @@ void SpineSkinAttachmentMapEntries::_bind_methods() { ClassDB::bind_method(D_METHOD("next"), &SpineSkinAttachmentMapEntries::next); } -SpineSkinAttachmentMapEntries::SpineSkinAttachmentMapEntries():entries(NULL) {} +SpineSkinAttachmentMapEntries::SpineSkinAttachmentMapEntries() : entries(NULL) {} SpineSkinAttachmentMapEntries::~SpineSkinAttachmentMapEntries() { - if(entries){ + if (entries) { delete entries; return; } } -bool SpineSkinAttachmentMapEntries::has_next(){ +bool SpineSkinAttachmentMapEntries::has_next() { return entries->hasNext(); } -Ref SpineSkinAttachmentMapEntries::next(){ +Ref SpineSkinAttachmentMapEntries::next() { auto &e = entries->next(); Ref gd_entry(memnew(SpineSkinAttachmentMapEntry)); gd_entry->set_spine_object(&e); diff --git a/spine-godot/spine_godot/SpineSkinAttachmentMapEntries.h b/spine-godot/spine_godot/SpineSkinAttachmentMapEntries.h index 9f5db61e3..b0f3922ef 100644 --- a/spine-godot/spine_godot/SpineSkinAttachmentMapEntries.h +++ b/spine-godot/spine_godot/SpineSkinAttachmentMapEntries.h @@ -49,10 +49,10 @@ public: SpineSkinAttachmentMapEntry(); ~SpineSkinAttachmentMapEntry(); - inline void set_spine_object(spine::Skin::AttachmentMap::Entry *e){ + inline void set_spine_object(spine::Skin::AttachmentMap::Entry *e) { entry = e; } - inline spine::Skin::AttachmentMap::Entry *get_spine_object(){ + inline spine::Skin::AttachmentMap::Entry *get_spine_object() { return entry; } @@ -79,10 +79,10 @@ public: SpineSkinAttachmentMapEntries(); ~SpineSkinAttachmentMapEntries(); - inline void set_spine_object(spine::Skin::AttachmentMap::Entries *e){ + inline void set_spine_object(spine::Skin::AttachmentMap::Entries *e) { entries = e; } - inline spine::Skin::AttachmentMap::Entries *get_spine_object(){ + inline spine::Skin::AttachmentMap::Entries *get_spine_object() { return entries; } @@ -90,4 +90,4 @@ public: Ref next(); }; -#endif //GODOT_SPINESKINATTACHMENTMAPENTRIES_H +#endif//GODOT_SPINESKINATTACHMENTMAPENTRIES_H diff --git a/spine-godot/spine_godot/SpineSlot.cpp b/spine-godot/spine_godot/SpineSlot.cpp index c26b98448..b1bbab708 100644 --- a/spine-godot/spine_godot/SpineSlot.cpp +++ b/spine-godot/spine_godot/SpineSlot.cpp @@ -51,98 +51,98 @@ void SpineSlot::_bind_methods() { ClassDB::bind_method(D_METHOD("set_deform", "v"), &SpineSlot::set_deform); } -SpineSlot::SpineSlot():slot(NULL) {} +SpineSlot::SpineSlot() : slot(NULL) {} SpineSlot::~SpineSlot() {} -void SpineSlot::set_to_setup_pos(){ +void SpineSlot::set_to_setup_pos() { slot->setToSetupPose(); } -Ref SpineSlot::get_data(){ +Ref SpineSlot::get_data() { auto &sd = slot->getData(); Ref gd_sd(memnew(SpineSlotData)); gd_sd->set_spine_object(&sd); return gd_sd; } -Ref SpineSlot::get_bone(){ +Ref SpineSlot::get_bone() { auto &b = slot->getBone(); Ref gd_b(memnew(SpineBone)); gd_b->set_spine_object(&b); return gd_b; } -Ref SpineSlot::get_skeleton(){ +Ref SpineSlot::get_skeleton() { auto &s = slot->getSkeleton(); Ref gd_s(memnew(SpineSkeleton)); gd_s->set_spine_object(&s); return gd_s; } -Color SpineSlot::get_color(){ +Color SpineSlot::get_color() { auto &c = slot->getColor(); 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(); c.set(v.r, v.g, v.b, v.a); } -Color SpineSlot::get_dark_color(){ +Color SpineSlot::get_dark_color() { auto &c = slot->getDarkColor(); 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(); c.set(v.r, v.g, v.b, v.a); } -bool SpineSlot::has_dark_color(){ +bool SpineSlot::has_dark_color() { return slot->hasDarkColor(); } -Ref SpineSlot::get_attachment(){ +Ref SpineSlot::get_attachment() { auto a = slot->getAttachment(); - if(a == NULL) return NULL; + if (a == NULL) return NULL; Ref gd_a(memnew(SpineAttachment)); gd_a->set_spine_object(a); return gd_a; } -void SpineSlot::set_attachment(Ref v){ - if(v.is_valid()){ +void SpineSlot::set_attachment(Ref v) { + if (v.is_valid()) { slot->setAttachment(v->get_spine_object()); - }else{ + } else { slot->setAttachment(NULL); } } -int SpineSlot::get_attachment_state(){ +int SpineSlot::get_attachment_state() { return slot->getAttachmentState(); } -void SpineSlot::set_attachment_state(int v){ +void SpineSlot::set_attachment_state(int v) { slot->setAttachmentState(v); } -float SpineSlot::get_attachment_time(){ +float SpineSlot::get_attachment_time() { return slot->getAttachmentTime(); } -void SpineSlot::set_attachment_time(float v){ +void SpineSlot::set_attachment_time(float v) { slot->setAttachmentTime(v); } -Array SpineSlot::get_deform(){ +Array SpineSlot::get_deform() { auto &ds = slot->getDeform(); Array gd_ds; 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]; } return gd_ds; } -void SpineSlot::set_deform(Array gd_ds){ +void SpineSlot::set_deform(Array gd_ds) { auto &ds = slot->getDeform(); 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]; } } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpineSlot.h b/spine-godot/spine_godot/SpineSlot.h index dff4cebcf..1d71eddb1 100644 --- a/spine-godot/spine_godot/SpineSlot.h +++ b/spine-godot/spine_godot/SpineSlot.h @@ -41,7 +41,7 @@ class SpineSkeleton; class SpineBone; -class SpineSlot : public Reference{ +class SpineSlot : public Reference { GDCLASS(SpineSlot, Reference); protected: @@ -54,10 +54,10 @@ public: SpineSlot(); ~SpineSlot(); - inline void set_spine_object(spine::Slot *s){ + inline void set_spine_object(spine::Slot *s) { slot = s; } - inline spine::Slot *get_spine_object(){ + inline spine::Slot *get_spine_object() { return slot; } @@ -90,4 +90,4 @@ public: void set_deform(Array v); }; -#endif //GODOT_SPINESLOT_H +#endif//GODOT_SPINESLOT_H diff --git a/spine-godot/spine_godot/SpineSlotData.cpp b/spine-godot/spine_godot/SpineSlotData.cpp index 82d77b9e1..bf3c48f20 100644 --- a/spine-godot/spine_godot/SpineSlotData.cpp +++ b/spine-godot/spine_godot/SpineSlotData.cpp @@ -51,62 +51,62 @@ void SpineSlotData::_bind_methods() { BIND_ENUM_CONSTANT(BLENDMODE_SCREEN); } -SpineSlotData::SpineSlotData():slot_data(NULL) {} +SpineSlotData::SpineSlotData() : slot_data(NULL) {} SpineSlotData::~SpineSlotData() {} #define S_T(x) (spine::String(x.utf8())) -int SpineSlotData::get_index(){ +int SpineSlotData::get_index() { return slot_data->getIndex(); } -String SpineSlotData::get_slot_name(){ +String SpineSlotData::get_slot_name() { return slot_data->getName().buffer(); } -Ref SpineSlotData::get_bone_data(){ +Ref SpineSlotData::get_bone_data() { auto &bd = slot_data->getBoneData(); Ref gd_bone_data(memnew(SpineBoneData)); gd_bone_data->set_spine_object(&bd); return gd_bone_data; } -Color SpineSlotData::get_color(){ +Color SpineSlotData::get_color() { auto &c = slot_data->getColor(); 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(); 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(); 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(); c.set(v.r, v.g, v.b, v.a); } -bool SpineSlotData::has_dark_color(){ +bool SpineSlotData::has_dark_color() { return slot_data->hasDarkColor(); } -void SpineSlotData::set_has_dark_color(bool v){ +void SpineSlotData::set_has_dark_color(bool v) { slot_data->setHasDarkColor(v); } -String SpineSlotData::get_attachment_name(){ +String SpineSlotData::get_attachment_name() { 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)); } -SpineSlotData::BlendMode SpineSlotData::get_blend_mode(){ +SpineSlotData::BlendMode SpineSlotData::get_blend_mode() { auto bm = (int) slot_data->getBlendMode(); return (BlendMode) bm; } -void SpineSlotData::set_blend_mode(BlendMode v){ +void SpineSlotData::set_blend_mode(BlendMode v) { auto bm = (int) v; slot_data->setBlendMode((spine::BlendMode) bm); } diff --git a/spine-godot/spine_godot/SpineSlotData.h b/spine-godot/spine_godot/SpineSlotData.h index 0b2f9abf5..1778bba55 100644 --- a/spine-godot/spine_godot/SpineSlotData.h +++ b/spine-godot/spine_godot/SpineSlotData.h @@ -48,10 +48,10 @@ public: SpineSlotData(); ~SpineSlotData(); - inline void set_spine_object(spine::SlotData *s){ + inline void set_spine_object(spine::SlotData *s) { slot_data = s; } - inline spine::SlotData *get_spine_object(){ + inline spine::SlotData *get_spine_object() { return slot_data; } @@ -85,4 +85,4 @@ public: }; VARIANT_ENUM_CAST(SpineSlotData::BlendMode); -#endif //GODOT_SPINESLOTDATA_H +#endif//GODOT_SPINESLOTDATA_H diff --git a/spine-godot/spine_godot/SpineSprite.cpp b/spine-godot/spine_godot/SpineSprite.cpp index 894545755..eb8c2c309 100644 --- a/spine-godot/spine_godot/SpineSprite.cpp +++ b/spine-godot/spine_godot/SpineSprite.cpp @@ -33,8 +33,8 @@ #include "SpineEvent.h" void SpineSprite::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_animation_state_data_res", "animation_state_data_res"), &SpineSprite::set_animation_state_data_res); - ClassDB::bind_method(D_METHOD("get_animation_state_data_res"), &SpineSprite::get_animation_state_data_res); + ClassDB::bind_method(D_METHOD("set_animation_state_data_res", "animation_state_data_res"), &SpineSprite::set_animation_state_data_res); + ClassDB::bind_method(D_METHOD("get_animation_state_data_res"), &SpineSprite::get_animation_state_data_res); ClassDB::bind_method(D_METHOD("_on_animation_data_created"), &SpineSprite::_on_animation_data_created); ClassDB::bind_method(D_METHOD("get_skeleton"), &SpineSprite::get_skeleton); ClassDB::bind_method(D_METHOD("get_animation_state"), &SpineSprite::get_animation_state); @@ -60,7 +60,7 @@ void SpineSprite::_bind_methods() { ClassDB::bind_method(D_METHOD("get_bind_slot_nodes"), &SpineSprite::get_bind_slot_nodes); ClassDB::bind_method(D_METHOD("set_bind_slot_nodes", "v"), &SpineSprite::set_bind_slot_nodes); ClassDB::bind_method(D_METHOD("get_overlap"), &SpineSprite::get_overlap); - ClassDB::bind_method(D_METHOD("set_overlap", "v"), &SpineSprite::set_overlap); + ClassDB::bind_method(D_METHOD("set_overlap", "v"), &SpineSprite::set_overlap); ClassDB::bind_method(D_METHOD("set_skin", "v"), &SpineSprite::set_skin); ClassDB::bind_method(D_METHOD("get_skin"), &SpineSprite::get_skin); ClassDB::bind_method(D_METHOD("_on_skin_property_changed"), &SpineSprite::_on_skin_property_changed); @@ -69,10 +69,10 @@ void SpineSprite::_bind_methods() { ClassDB::bind_method(D_METHOD("bone_get_global_transform", "bone_name"), &SpineSprite::bone_get_global_transform); ClassDB::bind_method(D_METHOD("bone_set_global_transform", "bone_name", "global_transform"), &SpineSprite::bone_set_global_transform); - ClassDB::bind_method(D_METHOD("set_process_mode", "v"), &SpineSprite::set_process_mode); - ClassDB::bind_method(D_METHOD("get_process_mode"), &SpineSprite::get_process_mode); + ClassDB::bind_method(D_METHOD("set_process_mode", "v"), &SpineSprite::set_process_mode); + ClassDB::bind_method(D_METHOD("get_process_mode"), &SpineSprite::get_process_mode); - ClassDB::bind_method(D_METHOD("manual_update", "delta"), &SpineSprite::_update_all); + ClassDB::bind_method(D_METHOD("manual_update", "delta"), &SpineSprite::_update_all); ADD_SIGNAL(MethodInfo("animation_state_ready", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "skeleton", PROPERTY_HINT_TYPE_STRING, "SpineSkeleton"))); ADD_SIGNAL(MethodInfo("animation_start", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); @@ -82,27 +82,25 @@ void SpineSprite::_bind_methods() { ADD_SIGNAL(MethodInfo("animation_dispose", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); ADD_SIGNAL(MethodInfo("animation_event", PropertyInfo(Variant::OBJECT, "animation_state", PROPERTY_HINT_TYPE_STRING, "SpineAnimationState"), PropertyInfo(Variant::OBJECT, "track_entry", PROPERTY_HINT_TYPE_STRING, "SpineTrackEntry"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_TYPE_STRING, "SpineEvent"))); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "animation_state_data_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineAnimationStateDataResource"), "set_animation_state_data_res", "get_animation_state_data_res"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "animation_state_data_res", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineAnimationStateDataResource"), "set_animation_state_data_res", "get_animation_state_data_res"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "overlap"), "set_overlap", "get_overlap"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "overlap"), "set_overlap", "get_overlap"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "bind_slot_nodes"), "set_bind_slot_nodes", "get_bind_slot_nodes"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "packed_skin_resource", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "PackedSpineSkinResource"), "set_skin", "get_skin"); - ADD_GROUP("animation", ""); - ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Process,Physics,Manually"), "set_process_mode", "get_process_mode"); + ADD_GROUP("animation", ""); + ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Process,Physics,Manually"), "set_process_mode", "get_process_mode"); ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "current_animations"), "set_current_animations", "get_current_animations"); - BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Process); - BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Physics); - BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Manual); + BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Process); + BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Physics); + BIND_ENUM_CONSTANT(ProcessMode::ProcessMode_Manual); } -SpineSprite::SpineSprite() : - select_track_id(0), empty_animation_duration(0.2f), skeleton_clipper(NULL), - overlap(false), - process_mode(ProcessMode_Process) - { +SpineSprite::SpineSprite() : select_track_id(0), empty_animation_duration(0.2f), skeleton_clipper(NULL), + overlap(false), + process_mode(ProcessMode_Process) { skeleton_clipper = new spine::SkeletonClipping(); } SpineSprite::~SpineSprite() { @@ -111,133 +109,129 @@ SpineSprite::~SpineSprite() { void SpineSprite::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_READY:{ - set_process_internal(process_mode == ProcessMode_Process); - set_physics_process_internal(process_mode == ProcessMode_Physics); + case NOTIFICATION_READY: { + set_process_internal(process_mode == ProcessMode_Process); + set_physics_process_internal(process_mode == ProcessMode_Physics); remove_redundant_mesh_instances(); } break; case NOTIFICATION_INTERNAL_PROCESS: { - if (process_mode == ProcessMode_Process) - _update_all(get_process_delta_time()); + if (process_mode == ProcessMode_Process) + _update_all(get_process_delta_time()); } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { - if (process_mode == ProcessMode_Physics) - _update_all(get_physics_process_delta_time()); - } break; + if (process_mode == ProcessMode_Physics) + _update_all(get_physics_process_delta_time()); + } break; } } void SpineSprite::_update_all(float delta) { - if (!(skeleton.is_valid() && animation_state.is_valid()) || mesh_instances.empty()) - return; + if (!(skeleton.is_valid() && animation_state.is_valid()) || mesh_instances.empty()) + return; - animation_state->update(delta); - if (!is_visible_in_tree()) - return; + animation_state->update(delta); + if (!is_visible_in_tree()) + return; - animation_state->apply(skeleton); + animation_state->apply(skeleton); - skeleton->update_world_transform(); + skeleton->update_world_transform(); - update_mesh_from_skeleton(skeleton); + update_mesh_from_skeleton(skeleton); - update(); + update(); - update_bind_slot_nodes(); + update_bind_slot_nodes(); } -void SpineSprite::update_bind_slot_nodes(){ - if(animation_state.is_valid() && skeleton.is_valid()){ - for(size_t i=0, n=bind_slot_nodes.size(); iis_class("Node2D")){ - Node2D *node2d = (Node2D*) node; + if (node && node->is_class("Node2D")) { + Node2D *node2d = (Node2D *) node; String slot_name = d["slot_name"]; auto slot = skeleton->find_slot(slot_name); - if(slot.is_valid()){ + if (slot.is_valid()) { auto bone = slot->get_bone(); - if(bone.is_valid()) - { + if (bone.is_valid()) { update_bind_slot_node_transform(bone, node2d); update_bind_slot_node_draw_order(slot_name, node2d); } } - } } - }else if(a.get_type() == Variant::ARRAY){ + } else if (a.get_type() == Variant::ARRAY) { auto as = (Array) a;// 0: slot_name, 1: node_path - if(as.size() >= 2 && as[0].get_type() == Variant::STRING && as[1].get_type() == Variant::NODE_PATH){ + if (as.size() >= 2 && as[0].get_type() == Variant::STRING && as[1].get_type() == Variant::NODE_PATH) { NodePath node_path = as[1]; Node *node = get_node_or_null(node_path); - if(node && node->is_class("Node2D")){ - Node2D *node2d = (Node2D*) node; + if (node && node->is_class("Node2D")) { + Node2D *node2d = (Node2D *) node; String slot_name = as[0]; auto slot = skeleton->find_slot(slot_name); - if(slot.is_valid()){ + if (slot.is_valid()) { auto bone = slot->get_bone(); - if(bone.is_valid()) - { + if (bone.is_valid()) { update_bind_slot_node_transform(bone, node2d); update_bind_slot_node_draw_order(slot_name, node2d); } } - } } } } } } -void SpineSprite::update_bind_slot_node_transform(Ref bone, Node2D *node2d){ +void SpineSprite::update_bind_slot_node_transform(Ref bone, Node2D *node2d) { bone->apply_world_transform_2d(node2d); } -void SpineSprite::update_bind_slot_node_draw_order(const String &slot_name, Node2D *node2d){ +void SpineSprite::update_bind_slot_node_draw_order(const String &slot_name, Node2D *node2d) { auto mesh_ins = find_node(slot_name); - if(mesh_ins){ + if (mesh_ins) { auto pos = mesh_ins->get_index(); // get child auto node = find_child_node_by_node(node2d); - if(node && node->get_index() != pos+1){ - move_child(node, pos+1); + if (node && node->get_index() != pos + 1) { + move_child(node, pos + 1); } } } -Node *SpineSprite::find_child_node_by_node(Node *node){ - if(node == NULL) return NULL; - while(node && node->get_parent() != this) node = node->get_parent(); +Node *SpineSprite::find_child_node_by_node(Node *node) { + if (node == NULL) return NULL; + while (node && node->get_parent() != this) node = node->get_parent(); return node; } void SpineSprite::set_animation_state_data_res(const Ref &s) { - animation_state_data_res = s; + animation_state_data_res = s; // update run time skeleton and meshes _on_animation_data_changed(); } Ref SpineSprite::get_animation_state_data_res() { - return animation_state_data_res; + return animation_state_data_res; } -void SpineSprite::_on_animation_data_created(){ -// print_line("_on_animation_data_created"); +void SpineSprite::_on_animation_data_created() { + // print_line("_on_animation_data_created"); skeleton = Ref(memnew(SpineSkeleton)); skeleton->load_skeleton(animation_state_data_res->get_skeleton()); skeleton->set_spine_sprite(this); -// print_line("Run time skeleton created."); + // print_line("Run time skeleton created."); animation_state = Ref(memnew(SpineAnimationState)); animation_state->load_animation_state(animation_state_data_res); animation_state->get_animation_state()->setListener(this); -// print_line("Run time animation state created."); + // print_line("Run time animation state created."); // add mesh instances related by current skeleton animation_state->update(0); @@ -246,29 +240,27 @@ void SpineSprite::_on_animation_data_created(){ gen_mesh_from_skeleton(skeleton); if (process_mode == ProcessMode_Process) { - _notification(NOTIFICATION_INTERNAL_PROCESS); - } else if (process_mode == ProcessMode_Physics) { - _notification(NOTIFICATION_INTERNAL_PHYSICS_PROCESS); + _notification(NOTIFICATION_INTERNAL_PROCESS); + } else if (process_mode == ProcessMode_Physics) { + _notification(NOTIFICATION_INTERNAL_PHYSICS_PROCESS); } emit_signal("animation_state_ready", animation_state, skeleton); } void SpineSprite::_on_animation_data_changed() { -// print_line("_on_animation_data_changed"); + // print_line("_on_animation_data_changed"); remove_mesh_instances(); skeleton.unref(); animation_state.unref(); - if(!animation_state_data_res.is_null()) - { - if(!animation_state_data_res->is_connected("animation_state_data_created", this, "_on_animation_data_created")) + if (!animation_state_data_res.is_null()) { + if (!animation_state_data_res->is_connected("animation_state_data_created", this, "_on_animation_data_created")) animation_state_data_res->connect("animation_state_data_created", this, "_on_animation_data_created"); - if(!animation_state_data_res->is_connected("skeleton_data_res_changed", this, "_on_animation_data_changed")) + if (!animation_state_data_res->is_connected("skeleton_data_res_changed", this, "_on_animation_data_changed")) animation_state_data_res->connect("skeleton_data_res_changed", this, "_on_animation_data_changed"); - if(!animation_state_data_res->is_connected("animation_state_data_changed", this, "_on_animation_data_changed")) + if (!animation_state_data_res->is_connected("animation_state_data_changed", this, "_on_animation_data_changed")) animation_state_data_res->connect("animation_state_data_changed", this, "_on_animation_data_changed"); - if(animation_state_data_res->is_animation_state_data_created()) - { + if (animation_state_data_res->is_animation_state_data_created()) { _on_animation_data_created(); } } @@ -283,8 +275,7 @@ Ref SpineSprite::get_animation_state() { void SpineSprite::gen_mesh_from_skeleton(Ref s) { auto sk = s->get_spine_object(); - for(size_t i=0, n = sk->getSlots().size(); i < n; ++i) - { + for (size_t i = 0, n = sk->getSlots().size(); i < n; ++i) { // creat a mesh instance 2d for every slot auto mesh_ins = memnew(SpineSpriteMeshInstance2D); add_child(mesh_ins); @@ -316,15 +307,14 @@ void SpineSprite::gen_mesh_from_skeleton(Ref s) { break; default: blend_mode = CanvasItemMaterial::BLEND_MODE_MIX; - } - mat->set_blend_mode(blend_mode); + } + mat->set_blend_mode(blend_mode); mesh_ins->set_material(mat); } } void SpineSprite::remove_mesh_instances() { - for(size_t i=0;i < mesh_instances.size();++i) - { + for (size_t i = 0; i < mesh_instances.size(); ++i) { remove_child(mesh_instances[i]); memdelete(mesh_instances[i]); } @@ -332,43 +322,42 @@ void SpineSprite::remove_mesh_instances() { } void SpineSprite::remove_redundant_mesh_instances() { - Vector ms; + Vector ms; // remove the redundant mesh instances that added by duplicating -// print_line("start clearing"); - for(size_t i=0, n=get_child_count(); iget_name()); - if(node && node->is_class("SpineSpriteMeshInstance2D")){ - if(mesh_instances.find((SpineSpriteMeshInstance2D*)node) == -1) - { -// print_line("marked clear"); + // print_line(String("get a node: ") + node->get_name()); + if (node && node->is_class("SpineSpriteMeshInstance2D")) { + if (mesh_instances.find((SpineSpriteMeshInstance2D *) node) == -1) { + // print_line("marked clear"); ms.push_back(node); } - } } - for(size_t i=0, n=ms.size(); i s) { static const unsigned short VERTEX_STRIDE = 2; static const unsigned short UV_STRIDE = 2; - static unsigned short quad_indices[] = { 0, 1, 2, 2, 3, 0 }; + static unsigned short quad_indices[] = {0, 1, 2, 2, 3, 0}; auto sk = s->get_spine_object(); - for(size_t i=0, n = sk->getSlots().size(); i < n; ++i) - { + for (size_t i = 0, n = sk->getSlots().size(); i < n; ++i) { spine::Vector vertices; spine::Vector uvs; spine::Vector indices; @@ -376,7 +365,7 @@ void SpineSprite::update_mesh_from_skeleton(Ref s) { spine::Slot *slot = sk->getDrawOrder()[i]; spine::Attachment *attachment = slot->getAttachment(); - if(!attachment){ + if (!attachment) { // set invisible to mesh instance mesh_instances[i]->set_visible(false); @@ -393,11 +382,10 @@ void SpineSprite::update_mesh_from_skeleton(Ref s) { Ref normal_tex; size_t v_num = 0; - if(attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) - { - spine::RegionAttachment *region_attachment = (spine::RegionAttachment*)attachment; + if (attachment->getRTTI().isExactly(spine::RegionAttachment::rtti)) { + spine::RegionAttachment *region_attachment = (spine::RegionAttachment *) attachment; - auto p_spine_renderer_object = (SpineRendererObject*) ((spine::AtlasRegion*)region_attachment->getRendererObject())->page->getRendererObject(); + auto p_spine_renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) region_attachment->getRendererObject())->page->getRendererObject(); tex = p_spine_renderer_object->tex; normal_tex = p_spine_renderer_object->normal_tex; @@ -409,7 +397,7 @@ void SpineSprite::update_mesh_from_skeleton(Ref s) { TEMP_COPY(uvs, region_attachment->getUVs()); indices.setSize(sizeof(quad_indices) / sizeof(unsigned short), 0); - for (size_t j = 0, qn = indices.size();j s) { tint.g *= attachment_color.g; tint.b *= attachment_color.b; tint.a *= attachment_color.a; - }else if(attachment->getRTTI().isExactly(spine::MeshAttachment::rtti)) { - spine::MeshAttachment *mesh = (spine::MeshAttachment*) attachment; + } else if (attachment->getRTTI().isExactly(spine::MeshAttachment::rtti)) { + spine::MeshAttachment *mesh = (spine::MeshAttachment *) attachment; - auto p_spine_renderer_object = (SpineRendererObject*) ((spine::AtlasRegion*)mesh->getRendererObject())->page->getRendererObject(); + auto p_spine_renderer_object = (SpineRendererObject *) ((spine::AtlasRegion *) mesh->getRendererObject())->page->getRendererObject(); tex = p_spine_renderer_object->tex; normal_tex = p_spine_renderer_object->normal_tex; - v_num = mesh->getWorldVerticesLength()/VERTEX_STRIDE; + v_num = mesh->getWorldVerticesLength() / VERTEX_STRIDE; vertices.setSize(mesh->getWorldVerticesLength(), 0); mesh->computeWorldVertices(*slot, vertices); -// uvs = mesh->getUVs(); -// indices = mesh->getTriangles(); + // uvs = mesh->getUVs(); + // indices = mesh->getTriangles(); TEMP_COPY(uvs, mesh->getUVs()); TEMP_COPY(indices, mesh->getTriangles()); @@ -450,7 +438,7 @@ void SpineSprite::update_mesh_from_skeleton(Ref s) { } auto mesh_ins = mesh_instances[i]; - VisualServer::get_singleton()->canvas_item_clear(mesh_ins->get_canvas_item()); + VisualServer::get_singleton()->canvas_item_clear(mesh_ins->get_canvas_item()); if (skeleton_clipper->isClipping()) { skeleton_clipper->clipTriangles(vertices, indices, uvs, VERTEX_STRIDE); @@ -461,7 +449,7 @@ void SpineSprite::update_mesh_from_skeleton(Ref s) { } auto &clipped_vertices = skeleton_clipper->getClippedVertices(); - v_num = clipped_vertices.size()/VERTEX_STRIDE; + v_num = clipped_vertices.size() / VERTEX_STRIDE; auto &clipped_uvs = skeleton_clipper->getClippedUVs(); auto &clipped_indices = skeleton_clipper->getClippedTriangles(); @@ -473,8 +461,8 @@ void SpineSprite::update_mesh_from_skeleton(Ref s) { p_uvs.resize(v_num); p_colors.resize(v_num); for (size_t j = 0; j < v_num; j++) { - p_points.set(j, Vector2(clipped_vertices[j*VERTEX_STRIDE], -clipped_vertices[j*VERTEX_STRIDE+1])); - p_uvs.set(j, Vector2(clipped_uvs[j*VERTEX_STRIDE], clipped_uvs[j*VERTEX_STRIDE+1])); + p_points.set(j, Vector2(clipped_vertices[j * VERTEX_STRIDE], -clipped_vertices[j * VERTEX_STRIDE + 1])); + p_uvs.set(j, Vector2(clipped_uvs[j * VERTEX_STRIDE], clipped_uvs[j * VERTEX_STRIDE + 1])); p_colors.set(j, Color(tint.r, tint.g, tint.b, tint.a)); } p_indices.resize(clipped_indices.size()); @@ -493,7 +481,7 @@ void SpineSprite::update_mesh_from_skeleton(Ref s) { -1, normal_tex.is_null() ? RID() : normal_tex->get_rid()); } - }else { + } else { if (indices.size() > 0) { Vector p_points, p_uvs; Vector p_colors; @@ -502,8 +490,8 @@ void SpineSprite::update_mesh_from_skeleton(Ref s) { p_uvs.resize(v_num); p_colors.resize(v_num); for (size_t j = 0; j < v_num; j++) { - p_points.set(j, Vector2(vertices[j*VERTEX_STRIDE], -vertices[j*VERTEX_STRIDE+1])); - p_uvs.set(j, Vector2(uvs[j*VERTEX_STRIDE], uvs[j*VERTEX_STRIDE+1])); + p_points.set(j, Vector2(vertices[j * VERTEX_STRIDE], -vertices[j * VERTEX_STRIDE + 1])); + p_uvs.set(j, Vector2(uvs[j * VERTEX_STRIDE], uvs[j * VERTEX_STRIDE + 1])); p_colors.set(j, Color(tint.r, tint.g, tint.b, tint.a)); } p_indices.resize(indices.size()); @@ -525,7 +513,7 @@ void SpineSprite::update_mesh_from_skeleton(Ref s) { } skeleton_clipper->clipEnd(*slot); - if (mesh_ins->get_material()->is_class("CanvasItemMaterial")){ + if (mesh_ins->get_material()->is_class("CanvasItemMaterial")) { Ref mat = mesh_ins->get_material(); CanvasItemMaterial::BlendMode blend_mode; switch (slot->getData().getBlendMode()) { @@ -543,7 +531,7 @@ void SpineSprite::update_mesh_from_skeleton(Ref s) { break; default: blend_mode = CanvasItemMaterial::BLEND_MODE_MIX; - } + } mat->set_blend_mode(blend_mode); } } @@ -554,40 +542,34 @@ void SpineSprite::callback(spine::AnimationState *state, spine::EventType type, Ref gd_entry(NULL); Ref gd_event(NULL); - if(entry){ + if (entry) { gd_entry = Ref(memnew(SpineTrackEntry)); gd_entry->set_spine_object(entry); } - if(event){ + if (event) { gd_event = Ref(memnew(SpineEvent)); gd_event->set_spine_object(event); } switch (type) { - case spine::EventType_Start: - { + case spine::EventType_Start: { emit_signal("animation_start", animation_state, gd_entry, gd_event); - }break; - case spine::EventType_Interrupt: - { + } break; + case spine::EventType_Interrupt: { emit_signal("animation_interrupt", animation_state, gd_entry, gd_event); - }break; - case spine::EventType_End: - { + } break; + case spine::EventType_End: { emit_signal("animation_end", animation_state, gd_entry, gd_event); - }break; - case spine::EventType_Complete: - { + } break; + case spine::EventType_Complete: { emit_signal("animation_complete", animation_state, gd_entry, gd_event); - }break; - case spine::EventType_Dispose: - { + } break; + case spine::EventType_Dispose: { emit_signal("animation_dispose", animation_state, gd_entry, gd_event); - }break; - case spine::EventType_Event: - { + } break; + case spine::EventType_Event: { emit_signal("animation_event", animation_state, gd_entry, gd_event); - }break; + } break; } } @@ -602,141 +584,137 @@ void SpineSprite::set_current_animations(Array as) { _validate_and_play_current_animations(); } -int SpineSprite::get_select_track_id(){ +int SpineSprite::get_select_track_id() { return select_track_id; } -void SpineSprite::set_select_track_id(int v){ +void SpineSprite::set_select_track_id(int v) { select_track_id = v; - if(select_track_id < 0) select_track_id = 0; + if (select_track_id < 0) select_track_id = 0; } -bool SpineSprite::get_clear_track(){ +bool SpineSprite::get_clear_track() { return false; } -void SpineSprite::set_clear_track(bool v){ - if(v && animation_state.is_valid() && skeleton.is_valid()) +void SpineSprite::set_clear_track(bool v) { + if (v && animation_state.is_valid() && skeleton.is_valid()) animation_state->clear_track(select_track_id); } -bool SpineSprite::get_clear_tracks(){ +bool SpineSprite::get_clear_tracks() { return false; } -void SpineSprite::set_clear_tracks(bool v){ - if(v && animation_state.is_valid() && skeleton.is_valid()) +void SpineSprite::set_clear_tracks(bool v) { + if (v && animation_state.is_valid() && skeleton.is_valid()) animation_state->clear_tracks(); } -float SpineSprite::get_empty_animation_duration(){ +float SpineSprite::get_empty_animation_duration() { return empty_animation_duration; } -void SpineSprite::set_empty_animation_duration(float v){ +void SpineSprite::set_empty_animation_duration(float v) { empty_animation_duration = v; } -bool SpineSprite::get_set_empty_animation(){ +bool SpineSprite::get_set_empty_animation() { return false; } -void SpineSprite::set_set_empty_animation(bool v){ - if(v && animation_state.is_valid() && skeleton.is_valid()) +void SpineSprite::set_set_empty_animation(bool v) { + if (v && animation_state.is_valid() && skeleton.is_valid()) animation_state->set_empty_animation(select_track_id, empty_animation_duration); } -bool SpineSprite::get_set_empty_animations(){ +bool SpineSprite::get_set_empty_animations() { return false; } -void SpineSprite::set_set_empty_animations(bool v){ - if(v && animation_state.is_valid() && skeleton.is_valid()) +void SpineSprite::set_set_empty_animations(bool v) { + if (v && animation_state.is_valid() && skeleton.is_valid()) animation_state->set_empty_animations(empty_animation_duration); } -Array SpineSprite::get_bind_slot_nodes(){ +Array SpineSprite::get_bind_slot_nodes() { return bind_slot_nodes; } void SpineSprite::set_bind_slot_nodes(Array v) { bind_slot_nodes = v; } -bool SpineSprite::get_overlap(){ +bool SpineSprite::get_overlap() { return overlap; } -void SpineSprite::set_overlap(bool v){ +void SpineSprite::set_overlap(bool v) { overlap = v; } -void SpineSprite::set_skin(Ref v) -{ - if(v != skin && skin.is_valid()){ - if(skin->is_connected("property_changed", this, "_on_skin_property_changed")) +void SpineSprite::set_skin(Ref v) { + if (v != skin && skin.is_valid()) { + if (skin->is_connected("property_changed", this, "_on_skin_property_changed")) skin->disconnect("property_changed", this, "_on_skin_property_changed"); } skin = v; - if(skin.is_valid()){ - if(!skin->is_connected("property_changed", this, "_on_skin_property_changed")) + if (skin.is_valid()) { + if (!skin->is_connected("property_changed", this, "_on_skin_property_changed")) skin->connect("property_changed", this, "_on_skin_property_changed"); update_runtime_skin(); } } -Ref SpineSprite::get_skin(){ +Ref SpineSprite::get_skin() { return skin; } -void SpineSprite::update_runtime_skin(){ +void SpineSprite::update_runtime_skin() { auto new_skin = gen_spine_skin_from_packed_resource(skin); - if(new_skin.is_valid()) - { + if (new_skin.is_valid()) { skeleton->set_skin(new_skin); skeleton->set_to_setup_pose(); } } -void SpineSprite::_on_skin_property_changed(){ +void SpineSprite::_on_skin_property_changed() { update_runtime_skin(); } -Ref SpineSprite::gen_spine_skin_from_packed_resource(Ref res){ - if(!(animation_state.is_valid() && skeleton.is_valid())) +Ref SpineSprite::gen_spine_skin_from_packed_resource(Ref res) { + if (!(animation_state.is_valid() && skeleton.is_valid())) return NULL; - if(!res.is_valid()) + if (!res.is_valid()) return NULL; - if(res->get_skin_name().empty()) + if (res->get_skin_name().empty()) return NULL; auto exist_skin = animation_state_data_res->get_skeleton()->find_skin(res->get_skin_name()); - if(exist_skin.is_valid()) - { + if (exist_skin.is_valid()) { return exist_skin; } auto new_skin = Ref(memnew(SpineSkin))->init(res->get_skin_name()); auto sub_skin_names = res->get_sub_skin_names(); - for(size_t i=0;iget_skeleton()->find_skin(skin_name); - if(sub_skin.is_valid()) + if (sub_skin.is_valid()) new_skin->add_skin(sub_skin); } return new_skin; } -void SpineSprite::bind_slot_with_node_2d(const String &slot_name, Node2D *n){ +void SpineSprite::bind_slot_with_node_2d(const String &slot_name, Node2D *n) { auto node_path = n->get_path_to(this); // check if has the same binding - for(size_t i=0, size=bind_slot_nodes.size(); i= 2 && as[0].get_type() == Variant::STRING && as[1].get_type() == Variant::NODE_PATH){ - if(slot_name == as[0] && node_path == as[1]){ + if (as.size() >= 2 && as[0].get_type() == Variant::STRING && as[1].get_type() == Variant::NODE_PATH) { + if (slot_name == as[0] && node_path == as[1]) { return; } } @@ -750,23 +728,23 @@ void SpineSprite::bind_slot_with_node_2d(const String &slot_name, Node2D *n){ bind_slot_nodes.append(bound); } -void SpineSprite::unbind_slot_with_node_2d(const String &slot_name, Node2D *n){ +void SpineSprite::unbind_slot_with_node_2d(const String &slot_name, Node2D *n) { auto node_path = n->get_path_to(this); - for(size_t i=0, size=bind_slot_nodes.size(); i= 2 && as[0].get_type() == Variant::STRING && as[1].get_type() == Variant::NODE_PATH){ - if(slot_name == as[0] && node_path == as[1]){ + if (as.size() >= 2 && as[0].get_type() == Variant::STRING && as[1].get_type() == Variant::NODE_PATH) { + if (slot_name == as[0] && node_path == as[1]) { bind_slot_nodes.remove(i); return; } @@ -776,264 +754,267 @@ void SpineSprite::unbind_slot_with_node_2d(const String &slot_name, Node2D *n){ } Transform2D SpineSprite::bone_get_global_transform(const String &bone_name) { - if (!animation_state.is_valid() && !skeleton.is_valid()) { - return get_global_transform(); - } - auto bone = skeleton->find_bone(bone_name); - if (!bone.is_valid()) { - print_error(vformat("Bone: '%s' not found.", bone_name)); - return get_global_transform(); - } - return bone->get_godot_global_transform(); + if (!animation_state.is_valid() && !skeleton.is_valid()) { + return get_global_transform(); + } + auto bone = skeleton->find_bone(bone_name); + if (!bone.is_valid()) { + print_error(vformat("Bone: '%s' not found.", bone_name)); + return get_global_transform(); + } + return bone->get_godot_global_transform(); } void SpineSprite::bone_set_global_transform(const String &bone_name, Transform2D transform) { - if (!animation_state.is_valid() && !skeleton.is_valid()) { - return; - } - auto bone = skeleton->find_bone(bone_name); - if (!bone.is_valid()) { - return; - } - bone->set_godot_global_transform(transform); + if (!animation_state.is_valid() && !skeleton.is_valid()) { + return; + } + auto bone = skeleton->find_bone(bone_name); + if (!bone.is_valid()) { + return; + } + bone->set_godot_global_transform(transform); } SpineSprite::ProcessMode SpineSprite::get_process_mode() { - return process_mode; + return process_mode; } void SpineSprite::set_process_mode(SpineSprite::ProcessMode v) { - process_mode = v; - set_process_internal(process_mode == ProcessMode_Process); - set_physics_process_internal(process_mode == ProcessMode_Physics); + process_mode = v; + set_process_internal(process_mode == ProcessMode_Process); + set_physics_process_internal(process_mode == ProcessMode_Physics); } void SpineSprite::_get_property_list(List *p_list) const { - p_list->push_back(PropertyInfo(Variant::NIL, "Current Animation Editor", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_CATEGORY)); - p_list->push_back(PropertyInfo(Variant::BOOL, "setup_pose_trigger", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); - p_list->push_back(PropertyInfo(Variant::BOOL, "clear_tracks_trigger", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); - p_list->push_back(PropertyInfo(Variant::BOOL, "set_empty_animations_trigger", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); - p_list->push_back(PropertyInfo(Variant::REAL, "empty_animation_duration")); - p_list->push_back(PropertyInfo(Variant::INT, "track_count", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); + p_list->push_back(PropertyInfo(Variant::NIL, "Current Animation Editor", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_CATEGORY)); + p_list->push_back(PropertyInfo(Variant::BOOL, "setup_pose_trigger", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); + p_list->push_back(PropertyInfo(Variant::BOOL, "clear_tracks_trigger", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); + p_list->push_back(PropertyInfo(Variant::BOOL, "set_empty_animations_trigger", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); + p_list->push_back(PropertyInfo(Variant::REAL, "empty_animation_duration")); + p_list->push_back(PropertyInfo(Variant::INT, "track_count", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); - for (size_t i=0; ipush_back(PropertyInfo(Variant::NIL, vformat("ID %d", (unsigned int)i), PROPERTY_HINT_NONE, prefix, PROPERTY_USAGE_GROUP)); - p_list->push_back(PropertyInfo(Variant::INT, vformat("%strack_id", prefix), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); + for (size_t i = 0; i < current_animations.size(); ++i) { + String prefix = vformat("ca/%d/", (unsigned int) i); + p_list->push_back(PropertyInfo(Variant::NIL, vformat("ID %d", (unsigned int) i), PROPERTY_HINT_NONE, prefix, PROPERTY_USAGE_GROUP)); + p_list->push_back(PropertyInfo(Variant::INT, vformat("%strack_id", prefix), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); - Vector anim_list; - if (skeleton.is_valid() && skeleton->get_data().is_valid()) { - skeleton->get_data()->get_animation_names(anim_list); - } - if (anim_list.empty()) anim_list.push_back("No Animation"); - p_list->push_back(PropertyInfo(Variant::STRING, vformat("%sanimation", prefix), PROPERTY_HINT_ENUM, String(",").join(anim_list), PROPERTY_USAGE_EDITOR)); + Vector anim_list; + if (skeleton.is_valid() && skeleton->get_data().is_valid()) { + skeleton->get_data()->get_animation_names(anim_list); + } + if (anim_list.empty()) anim_list.push_back("No Animation"); + p_list->push_back(PropertyInfo(Variant::STRING, vformat("%sanimation", prefix), PROPERTY_HINT_ENUM, String(",").join(anim_list), PROPERTY_USAGE_EDITOR)); - p_list->push_back(PropertyInfo(Variant::REAL, vformat("%sdelay", prefix), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); + p_list->push_back(PropertyInfo(Variant::REAL, vformat("%sdelay", prefix), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); - p_list->push_back(PropertyInfo(Variant::BOOL, vformat("%sloop", prefix), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); + p_list->push_back(PropertyInfo(Variant::BOOL, vformat("%sloop", prefix), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); - p_list->push_back(PropertyInfo(Variant::BOOL, vformat("%sempty", prefix), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); - p_list->push_back(PropertyInfo(Variant::REAL, vformat("%sempty_animation_duration", prefix), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); + p_list->push_back(PropertyInfo(Variant::BOOL, vformat("%sempty", prefix), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); + p_list->push_back(PropertyInfo(Variant::REAL, vformat("%sempty_animation_duration", prefix), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); - p_list->push_back(PropertyInfo(Variant::BOOL, vformat("%sclear", prefix), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); - } + p_list->push_back(PropertyInfo(Variant::BOOL, vformat("%sclear", prefix), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR)); + } } bool SpineSprite::_get(const StringName &p_property, Variant &r_value) const { - if (p_property == "setup_pose_trigger" || p_property == "clear_tracks_trigger" || p_property == "set_empty_animations_trigger") { - r_value = false; - return true; - } - if (p_property == "empty_animation_duration") { - r_value = empty_animation_duration; - return true; - } - if (p_property == "track_count") { - r_value = get_current_animation_count(); - return true; - } - String p = p_property; - if (p.size() > 2 && p[0] == 'c' && p[1] == 'a' && p[2] == '/') { - Vector sp = p.split("/"); - if (sp.size() > 2) { - int64_t id = sp[1].to_int64(); - if (id >= 0 && id < current_animations.size()) { - auto &key = sp[2]; - if (current_animations[id].get_type() == Variant::DICTIONARY) { - Dictionary dic = current_animations.get(id); - if (dic.has(key)) { - r_value = dic[key]; - } else { - if (key == "track_id") r_value = 0; - else if (key == "animation") r_value = ""; - else if (key == "loop") r_value = true; - else if (key == "empty") r_value = false; - else if (key == "empty_animation_duration") r_value = 0.3; - else if (key == "clear") r_value = false; - else if (key == "delay") r_value = 0; - else return false; - } - return true; - } - } - } - } - return false; + if (p_property == "setup_pose_trigger" || p_property == "clear_tracks_trigger" || p_property == "set_empty_animations_trigger") { + r_value = false; + return true; + } + if (p_property == "empty_animation_duration") { + r_value = empty_animation_duration; + return true; + } + if (p_property == "track_count") { + r_value = get_current_animation_count(); + return true; + } + String p = p_property; + if (p.size() > 2 && p[0] == 'c' && p[1] == 'a' && p[2] == '/') { + Vector sp = p.split("/"); + if (sp.size() > 2) { + int64_t id = sp[1].to_int64(); + if (id >= 0 && id < current_animations.size()) { + auto &key = sp[2]; + if (current_animations[id].get_type() == Variant::DICTIONARY) { + Dictionary dic = current_animations.get(id); + if (dic.has(key)) { + r_value = dic[key]; + } else { + if (key == "track_id") r_value = 0; + else if (key == "animation") + r_value = ""; + else if (key == "loop") + r_value = true; + else if (key == "empty") + r_value = false; + else if (key == "empty_animation_duration") + r_value = 0.3; + else if (key == "clear") + r_value = false; + else if (key == "delay") + r_value = 0; + else + return false; + } + return true; + } + } + } + } + return false; } bool SpineSprite::_set(const StringName &p_property, const Variant &p_value) { - if (p_property == "setup_pose_trigger") { - if (p_value) { - if (skeleton.is_valid()) { - skeleton->set_bones_to_setup_pose(); - skeleton->set_slots_to_setup_pose(); - } - } - return true; - } - if (p_property == "clear_tracks_trigger") { - if (p_value) { - if (animation_state.is_valid() && skeleton.is_valid()) { - animation_state->clear_tracks(); - } - } - return true; - } - if (p_property == "set_empty_animations_trigger") { - if (p_value) { - if (animation_state.is_valid() && skeleton.is_valid()) { - animation_state->set_empty_animations(empty_animation_duration); - } - } - return true; - } - if (p_property == "empty_animation_duration") { - empty_animation_duration = p_value; - return true; - } - if (p_property == "track_count") { - set_current_animation_count(p_value); - return true; - } - String p = p_property; - if (p.size() > 2 && p[0] == 'c' && p[1] == 'a' && p[2] == '/') { - Vector sp = p.split("/"); - if (sp.size() > 2) { - int64_t id = sp[1].to_int64(); - if (id >= 0 && id < current_animations.size()) { - auto &key = sp[2]; - if (current_animations[id].get_type() != Variant::DICTIONARY) { - current_animations.set(id, Dictionary()); - } + if (p_property == "setup_pose_trigger") { + if (p_value) { + if (skeleton.is_valid()) { + skeleton->set_bones_to_setup_pose(); + skeleton->set_slots_to_setup_pose(); + } + } + return true; + } + if (p_property == "clear_tracks_trigger") { + if (p_value) { + if (animation_state.is_valid() && skeleton.is_valid()) { + animation_state->clear_tracks(); + } + } + return true; + } + if (p_property == "set_empty_animations_trigger") { + if (p_value) { + if (animation_state.is_valid() && skeleton.is_valid()) { + animation_state->set_empty_animations(empty_animation_duration); + } + } + return true; + } + if (p_property == "empty_animation_duration") { + empty_animation_duration = p_value; + return true; + } + if (p_property == "track_count") { + set_current_animation_count(p_value); + return true; + } + String p = p_property; + if (p.size() > 2 && p[0] == 'c' && p[1] == 'a' && p[2] == '/') { + Vector sp = p.split("/"); + if (sp.size() > 2) { + int64_t id = sp[1].to_int64(); + if (id >= 0 && id < current_animations.size()) { + auto &key = sp[2]; + if (current_animations[id].get_type() != Variant::DICTIONARY) { + current_animations.set(id, Dictionary()); + } - Dictionary dic = current_animations.get(id); - dic[key] = p_value; + Dictionary dic = current_animations.get(id); + dic[key] = p_value; - _validate_and_play_current_animations(); - return true; - } - } - } - return false; + _validate_and_play_current_animations(); + return true; + } + } + } + return false; } int64_t SpineSprite::get_current_animation_count() const { - return current_animations.size(); + return current_animations.size(); } void SpineSprite::set_current_animation_count(int64_t v) { - if (v < 0) v = 0; - while (current_animations.size() < v) { - Dictionary d; - d["track_id"] = current_animations.size(); - d["animation"] = ""; - d["delay"] = 0; - d["loop"] = true; - d["empty"] = false; - d["empty_animation_duration"] = 0.3; - d["clear"] = false; - current_animations.push_back(d); - } - while (current_animations.size() > v) { - if (animation_state.is_valid() && skeleton.is_valid()) { - if (current_animations.back().get_type() == Variant::DICTIONARY) { - Dictionary back = current_animations.back(); - if (back.has("track_id")) { - int64_t track_id = back["track_id"]; - int track_cnt = 0; - for (size_t i=0; iclear_track(track_id); - } - } - } - current_animations.pop_back(); - } - property_list_changed_notify(); + if (v < 0) v = 0; + while (current_animations.size() < v) { + Dictionary d; + d["track_id"] = current_animations.size(); + d["animation"] = ""; + d["delay"] = 0; + d["loop"] = true; + d["empty"] = false; + d["empty_animation_duration"] = 0.3; + d["clear"] = false; + current_animations.push_back(d); + } + while (current_animations.size() > v) { + if (animation_state.is_valid() && skeleton.is_valid()) { + if (current_animations.back().get_type() == Variant::DICTIONARY) { + Dictionary back = current_animations.back(); + if (back.has("track_id")) { + int64_t track_id = back["track_id"]; + int track_cnt = 0; + for (size_t i = 0; i < current_animations.size(); ++i) { + if (current_animations[i].get_type() == Variant::DICTIONARY) { + Dictionary d = current_animations[i]; + if (d.has("track_id") && track_id == (int64_t) d["track_id"]) { + track_cnt += 1; + } + } + } + if (track_cnt == 0) + animation_state->clear_track(track_id); + } + } + } + current_animations.pop_back(); + } + property_list_changed_notify(); } void SpineSprite::_validate_and_play_current_animations() { - if(animation_state.is_valid() && skeleton.is_valid()){ - int64_t track_cnt = 0; - HashMap has_track; - for(size_t i=0; i has_track; + for (size_t i = 0; i < current_animations.size(); ++i) { + auto a = current_animations[i]; + if (a.get_type() == Variant::DICTIONARY) { + Dictionary d = a; - int64_t track_id = 0; - String animation = ""; - float delay = 0; - bool loop = true; - bool empty = false; - float empty_animation_duration = 0.3; - bool clear = false; + int64_t track_id = 0; + String animation = ""; + float delay = 0; + bool loop = true; + bool empty = false; + float empty_animation_duration = 0.3; + bool clear = false; - if (d.has("track_id")) track_id = d["track_id"]; - if (d.has("animation")) animation = d["animation"]; - if (d.has("delay")) delay = d["delay"]; - if (d.has("loop")) loop = d["loop"]; - if (d.has("empty")) empty = d["empty"]; - if (d.has("empty_animation_duration")) empty_animation_duration = d["empty_animation_duration"]; - if (d.has("clear")) clear = d["clear"]; + if (d.has("track_id")) track_id = d["track_id"]; + if (d.has("animation")) animation = d["animation"]; + if (d.has("delay")) delay = d["delay"]; + if (d.has("loop")) loop = d["loop"]; + if (d.has("empty")) empty = d["empty"]; + if (d.has("empty_animation_duration")) empty_animation_duration = d["empty_animation_duration"]; + if (d.has("clear")) clear = d["clear"]; - if (track_id < 0) { - print_line(vformat("track_id at 'ID %d' can not be less than 0!", (unsigned int)i)); - continue; - } + if (track_id < 0) { + print_line(vformat("track_id at 'ID %d' can not be less than 0!", (unsigned int) i)); + continue; + } - track_cnt += 1; + track_cnt += 1; - if (empty) { - if (has_track.has(track_id)) - animation_state->add_empty_animation(track_id, empty_animation_duration, delay); - else - animation_state->set_empty_animation(track_id, empty_animation_duration); - has_track[track_id] = true; - } else if (clear) { - animation_state->clear_track(track_id); - } else if (skeleton->get_data()->find_animation(animation).is_valid()) { - if (has_track.has(track_id)) - animation_state->add_animation(animation, delay, loop, track_id); - else - animation_state->set_animation(animation, loop, track_id); - has_track[track_id] = true; - } + if (empty) { + if (has_track.has(track_id)) + animation_state->add_empty_animation(track_id, empty_animation_duration, delay); + else + animation_state->set_empty_animation(track_id, empty_animation_duration); + has_track[track_id] = true; + } else if (clear) { + animation_state->clear_track(track_id); + } else if (skeleton->get_data()->find_animation(animation).is_valid()) { + if (has_track.has(track_id)) + animation_state->add_animation(animation, delay, loop, track_id); + else + animation_state->set_animation(animation, loop, track_id); + has_track[track_id] = true; + } + } + } - } - } - - if (track_cnt == 0) animation_state->clear_tracks(); - } + if (track_cnt == 0) animation_state->clear_tracks(); + } } - - - diff --git a/spine-godot/spine_godot/SpineSprite.h b/spine-godot/spine_godot/SpineSprite.h index 48c9d9f29..0bf686584 100644 --- a/spine-godot/spine_godot/SpineSprite.h +++ b/spine-godot/spine_godot/SpineSprite.h @@ -41,31 +41,33 @@ #include "PackedSpineSkinResource.h" class SpineSprite : public Node2D, public spine::AnimationStateListenerObject { - GDCLASS(SpineSprite, Node2D); + GDCLASS(SpineSprite, Node2D); + protected: - static void _bind_methods(); + static void _bind_methods(); void _notification(int p_what); - void _get_property_list(List *p_list) const; - bool _get(const StringName &p_property, Variant &r_value) const; - bool _set(const StringName &p_property, const Variant &p_value); + void _get_property_list(List *p_list) const; + bool _get(const StringName &p_property, Variant &r_value) const; + bool _set(const StringName &p_property, const Variant &p_value); + + void _validate_and_play_current_animations(); - void _validate_and_play_current_animations(); public: - enum ProcessMode { - ProcessMode_Process, - ProcessMode_Physics, - ProcessMode_Manual - }; -private: + enum ProcessMode { + ProcessMode_Process, + ProcessMode_Physics, + ProcessMode_Manual + }; - Ref animation_state_data_res; +private: + Ref animation_state_data_res; Ref skeleton; Ref animation_state; - Vector mesh_instances; + Vector mesh_instances; Array current_animations; int select_track_id; @@ -75,7 +77,7 @@ private: bool overlap; Ref skin; - ProcessMode process_mode; + ProcessMode process_mode; spine::SkeletonClipping *skeleton_clipper; @@ -83,8 +85,8 @@ public: SpineSprite(); ~SpineSprite(); - void set_animation_state_data_res(const Ref &a); - Ref get_animation_state_data_res(); + void set_animation_state_data_res(const Ref &a); + Ref get_animation_state_data_res(); Ref get_skeleton(); Ref get_animation_state(); @@ -100,7 +102,7 @@ public: void update_bind_slot_node_draw_order(const String &slot_name, Node2D *node2d); 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_changed(); @@ -150,13 +152,13 @@ public: Ref gen_spine_skin_from_packed_resource(Ref res); - // current animation count - int64_t get_current_animation_count() const; - void set_current_animation_count(int64_t v); + // current animation count + int64_t get_current_animation_count() const; + void set_current_animation_count(int64_t v); ProcessMode get_process_mode(); void set_process_mode(ProcessMode v); }; VARIANT_ENUM_CAST(SpineSprite::ProcessMode); -#endif //GODOT_SPINESPRITE_H +#endif//GODOT_SPINESPRITE_H diff --git a/spine-godot/spine_godot/SpineSpriteAnimateDialog.cpp b/spine-godot/spine_godot/SpineSpriteAnimateDialog.cpp index 2d102a451..33bebdd66 100644 --- a/spine-godot/spine_godot/SpineSpriteAnimateDialog.cpp +++ b/spine-godot/spine_godot/SpineSpriteAnimateDialog.cpp @@ -34,316 +34,317 @@ #include "SpineSprite.h" void SpineSpriteAnimateDialog::_bind_methods() { - 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_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_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_hide"), &SpineSpriteAnimateDialog::_on_scene_tree_hide); + ClassDB::bind_method(D_METHOD("_on_animate_dialog_action"), &SpineSpriteAnimateDialog::_on_animate_dialog_action); } SpineSpriteAnimateDialog::SpineSpriteAnimateDialog() { - animate_dialog = memnew(ConfirmationDialog); - add_child(animate_dialog); - animate_dialog->get_ok()->set_text("Generate"); - animate_dialog_override_button = animate_dialog->add_button("Override", false, "override"); - animate_dialog_override_button->set_visible(false); - animate_dialog->set_title("Animations Generator"); - animate_dialog->set_resizable(true); - animate_dialog->set_custom_minimum_size(Vector2(550, 400)); - animate_dialog->set_hide_on_ok(false); - animate_dialog->connect("custom_action", this, "_on_animate_dialog_action"); - Vector al; - al.push_back("confirmed"); - animate_dialog->connect("confirmed", this, "_on_animate_dialog_action", al); + animate_dialog = memnew(ConfirmationDialog); + add_child(animate_dialog); + animate_dialog->get_ok()->set_text("Generate"); + animate_dialog_override_button = animate_dialog->add_button("Override", false, "override"); + animate_dialog_override_button->set_visible(false); + animate_dialog->set_title("Animations Generator"); + animate_dialog->set_resizable(true); + animate_dialog->set_custom_minimum_size(Vector2(550, 400)); + animate_dialog->set_hide_on_ok(false); + animate_dialog->connect("custom_action", this, "_on_animate_dialog_action"); + Vector al; + al.push_back("confirmed"); + animate_dialog->connect("confirmed", this, "_on_animate_dialog_action", al); - auto vb = memnew(VBoxContainer); - animate_dialog->add_child(vb); + auto vb = memnew(VBoxContainer); + animate_dialog->add_child(vb); - auto scroll = memnew(ScrollContainer); - scroll->set_h_size_flags(SIZE_EXPAND_FILL); - scroll->set_v_size_flags(SIZE_EXPAND_FILL); -// vb->add_margin_child("Animations", scroll); - vb->add_child(scroll); + auto scroll = memnew(ScrollContainer); + scroll->set_h_size_flags(SIZE_EXPAND_FILL); + scroll->set_v_size_flags(SIZE_EXPAND_FILL); + // vb->add_margin_child("Animations", scroll); + vb->add_child(scroll); - animate_dialog_tree = memnew(Tree); - animate_dialog_tree->set_h_size_flags(SIZE_EXPAND_FILL); - animate_dialog_tree->set_v_size_flags(SIZE_EXPAND_FILL); - scroll->add_child(animate_dialog_tree); + animate_dialog_tree = memnew(Tree); + animate_dialog_tree->set_h_size_flags(SIZE_EXPAND_FILL); + animate_dialog_tree->set_v_size_flags(SIZE_EXPAND_FILL); + scroll->add_child(animate_dialog_tree); - animate_dialog_tree->set_columns(3); - animate_dialog_tree->set_column_titles_visible(true); - animate_dialog_tree->set_hide_folding(true); - animate_dialog_tree->set_hide_root(true); + animate_dialog_tree->set_columns(3); + animate_dialog_tree->set_column_titles_visible(true); + animate_dialog_tree->set_hide_folding(true); + animate_dialog_tree->set_hide_root(true); - animate_dialog_tree->set_column_title(0, TTR("Animation")); - 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(0, TTR("Animation")); + animate_dialog_tree->set_column_title(1, TTR("Loop")); + animate_dialog_tree->set_column_title(2, TTR("Track ID")); - animate_dialog_tree->create_item(); - add_row("test1"); - add_row("test12"); - add_row("test13"); + animate_dialog_tree->create_item(); + add_row("test1"); + add_row("test12"); + add_row("test13"); - auto l = memnew(Label); - l->set_text("W.I.P"); - vb->add_child(l); + auto l = memnew(Label); + l->set_text("W.I.P"); + vb->add_child(l); - scene_tree_dialog = memnew(SceneTreeDialog); - scene_tree_dialog->set_title("Choose a AnimationPlayer to override, or choose none to create a new one."); - Vector valid_types; - valid_types.push_back("AnimationPlayer"); - 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_ok()->hide(); - add_child(scene_tree_dialog); - scene_tree_dialog->connect("selected", this, "_on_scene_tree_selected"); - scene_tree_dialog->connect("popup_hide", this, "_on_scene_tree_hide"); + scene_tree_dialog = memnew(SceneTreeDialog); + scene_tree_dialog->set_title("Choose a AnimationPlayer to override, or choose none to create a new one."); + Vector valid_types; + valid_types.push_back("AnimationPlayer"); + 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_ok()->hide(); + add_child(scene_tree_dialog); + scene_tree_dialog->connect("selected", this, "_on_scene_tree_selected"); + scene_tree_dialog->connect("popup_hide", this, "_on_scene_tree_hide"); - error_dialog = memnew(AcceptDialog); - add_child(error_dialog); + error_dialog = memnew(AcceptDialog); + add_child(error_dialog); } SpineSpriteAnimateDialog::~SpineSpriteAnimateDialog() { - } void SpineSpriteAnimateDialog::set_animate_button(ToolButton *b) { - animate_button = b; - animate_button->connect("pressed", this, "_on_animate_button_pressed"); + animate_button = b; + animate_button->connect("pressed", this, "_on_animate_button_pressed"); } void SpineSpriteAnimateDialog::add_row(const String &animation, bool loop, int64_t track_id) { - auto item = animate_dialog_tree->create_item(); - item->set_text(0, animation); + auto item = animate_dialog_tree->create_item(); + item->set_text(0, animation); - item->set_cell_mode(1, TreeItem::CELL_MODE_CHECK); - item->set_checked(1, loop); - item->set_editable(1, true); + item->set_cell_mode(1, TreeItem::CELL_MODE_CHECK); + item->set_checked(1, loop); + item->set_editable(1, true); - item->set_cell_mode(2, TreeItem::CELL_MODE_RANGE); - item->set_range(2, track_id); - item->set_editable(2, true); + item->set_cell_mode(2, TreeItem::CELL_MODE_RANGE); + item->set_range(2, track_id); + item->set_editable(2, true); } void SpineSpriteAnimateDialog::clear_tree() { - animate_dialog_tree->clear(); - animate_dialog_tree->create_item(); + animate_dialog_tree->clear(); + animate_dialog_tree->create_item(); } void SpineSpriteAnimateDialog::error(const String &text, const String &title) { - error_dialog->set_text(text); - error_dialog->set_title(title); - error_dialog->popup_centered(); + error_dialog->set_text(text); + error_dialog->set_title(title); + 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) { - if (sprite == nullptr) { - ERROR_MSG("The sprite is null."); - } - if (!sprite->get_animation_state().is_valid() || !sprite->get_skeleton().is_valid()) { - ERROR_MSG("The sprite is not loaded."); - } - clear_tree(); + if (sprite == nullptr) { + ERROR_MSG("The sprite is null."); + } + if (!sprite->get_animation_state().is_valid() || !sprite->get_skeleton().is_valid()) { + ERROR_MSG("The sprite is not loaded."); + } + clear_tree(); - Vector animations; - sprite->get_skeleton()->get_data()->get_animation_names(animations); + Vector animations; + sprite->get_skeleton()->get_data()->get_animation_names(animations); - for (size_t i=0; iget_animation_state().is_valid() || !sprite->get_skeleton().is_valid()) { - ERROR_MSG("The sprite is not loaded."); - } - auto p = sprite->get_parent(); - if (p == nullptr) { - p = sprite; - } + if (sprite == nullptr) { + ERROR_MSG("The sprite player is null."); + } + if (!sprite->get_animation_state().is_valid() || !sprite->get_skeleton().is_valid()) { + ERROR_MSG("The sprite is not loaded."); + } + auto p = sprite->get_parent(); + if (p == nullptr) { + p = sprite; + } - auto anim_player = memnew(AnimationPlayer); - anim_player->set_name("AnimationPlayer"); - p->add_child(anim_player); - anim_player->set_owner(sprite->get_owner()); - anim_player->set_root(anim_player->get_path_to(p)); + auto anim_player = memnew(AnimationPlayer); + anim_player->set_name("AnimationPlayer"); + p->add_child(anim_player); + anim_player->set_owner(sprite->get_owner()); + 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 res; - if (animate_dialog_tree->get_root() == nullptr) return res; + Dictionary res; + if (animate_dialog_tree->get_root() == nullptr) return res; - auto item = animate_dialog_tree->get_root()->get_children(); - while (item) { - Dictionary row; - row["loop"] = item->is_checked(1); - row["track_id"] = item->get_range(2); + auto item = animate_dialog_tree->get_root()->get_children(); + while (item) { + Dictionary row; + row["loop"] = item->is_checked(1); + row["track_id"] = item->get_range(2); - res[item->get_text(0)] = row; - item = item->get_next(); - } - return res; + res[item->get_text(0)] = row; + item = item->get_next(); + } + return res; } void SpineSpriteAnimateDialog::gen_animations(SpineSprite *sprite, AnimationPlayer *anim_player, const Dictionary &config, float min_duration, bool &err) { - if (sprite == nullptr || anim_player == nullptr) { - ERROR_MSG("The sprite or animation player is null."); - } - if (!sprite->get_animation_state().is_valid() || !sprite->get_skeleton().is_valid()) { - ERROR_MSG("The sprite is not loaded."); - } - if (anim_player->get_node_or_null(anim_player->get_root()) == nullptr) { - ERROR_MSG("The root node of animation player is null."); - } + if (sprite == nullptr || anim_player == nullptr) { + ERROR_MSG("The sprite or animation player is null."); + } + if (!sprite->get_animation_state().is_valid() || !sprite->get_skeleton().is_valid()) { + ERROR_MSG("The sprite is not loaded."); + } + if (anim_player->get_node_or_null(anim_player->get_root()) == nullptr) { + 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(); - for (size_t i=0; i) animations[i]; + Array animations = sprite->get_skeleton()->get_data()->get_animations(); + for (size_t i = 0; i < animations.size(); ++i) { + auto spine_anim = (Ref) animations[i]; - Dictionary ca; - if (config.has(spine_anim->get_anim_name())) { - ca = config[spine_anim->get_anim_name()]; - } + Dictionary ca; + if (config.has(spine_anim->get_anim_name())) { + ca = config[spine_anim->get_anim_name()]; + } - if (!ca.has("loop")) ca["loop"] = true; - if (!ca.has("track_id")) ca["track_id"] = 0; + if (!ca.has("loop")) ca["loop"] = true; + if (!ca.has("track_id")) ca["track_id"] = 0; - 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)); + 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)); - auto anim = Ref(memnew(Animation)); - 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->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->value_track_set_update_mode(track_index, Animation::UPDATE_DISCRETE); + auto anim = Ref(memnew(Animation)); + 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->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->value_track_set_update_mode(track_index, Animation::UPDATE_DISCRETE); - if (anim_player->has_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); - } + if (anim_player->has_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); + } - 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 res; - res["animation"] = animation; - res["track_id"] = track_id; - res["loop"] = loop; - res["clear"] = clear; - res["empty"] = empty; - res["empty_animation_duration"] = empty_duration; - res["delay"] = delay; - return res; + Dictionary res; + res["animation"] = animation; + res["track_id"] = track_id; + res["loop"] = loop; + res["clear"] = clear; + res["empty"] = empty; + res["empty_animation_duration"] = empty_duration; + res["delay"] = delay; + return res; } void SpineSpriteAnimateDialog::load_data_from_anim_player(AnimationPlayer *anim_player, bool &err) { - if (anim_player == nullptr) { - ERROR_MSG("The animation player is null."); - } - auto root = anim_player->get_node_or_null(anim_player->get_root()); - if (root == nullptr) return; + if (anim_player == nullptr) { + ERROR_MSG("The animation player is null."); + } + auto root = anim_player->get_node_or_null(anim_player->get_root()); + if (root == nullptr) return; - auto sprite = get_node_or_null(spine_sprite_path); - if (sprite == nullptr) return; + auto sprite = get_node_or_null(spine_sprite_path); + if (sprite == nullptr) return; - auto item = animate_dialog_tree->get_root()->get_children(); - while (item) { - String animation = item->get_text(0); + auto item = animate_dialog_tree->get_root()->get_children(); + while (item) { + String animation = item->get_text(0); - auto anim = anim_player->get_animation(animation); - if (anim.is_valid() && anim->get_track_count() > 0) { - if (anim->track_get_type(0) == Animation::TYPE_VALUE) { - auto track_path = anim->track_get_path(0); - if (root->get_node_or_null(track_path) == sprite) { - if (anim->track_get_key_count(0) > 0) { - Array key_frame_value = anim->track_get_key_value(0, 0); - if (!key_frame_value.empty()) { - Dictionary _ca = key_frame_value.front(); - if (_ca.has("loop")) item->set_checked(1, _ca["loop"]); - if (_ca.has("track_id")) item->set_range(2, _ca["track_id"]); - } - } - } - } + auto anim = anim_player->get_animation(animation); + if (anim.is_valid() && anim->get_track_count() > 0) { + if (anim->track_get_type(0) == Animation::TYPE_VALUE) { + auto track_path = anim->track_get_path(0); + if (root->get_node_or_null(track_path) == sprite) { + if (anim->track_get_key_count(0) > 0) { + Array key_frame_value = anim->track_get_key_value(0, 0); + if (!key_frame_value.empty()) { + Dictionary _ca = key_frame_value.front(); + if (_ca.has("loop")) item->set_checked(1, _ca["loop"]); + 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 ----- void SpineSpriteAnimateDialog::_on_scene_tree_selected(NodePath path) { -// print_line(vformat("anime: %s", path)); - auto node = get_node_or_null(path); - if (node == nullptr) { - error("The node you chose is null."); - return; - } - if (!node->is_class("AnimationPlayer")) { - error("The node you chose is not AnimationPlayer."); - return; - } - anim_player_path = path; + // print_line(vformat("anime: %s", path)); + auto node = get_node_or_null(path); + if (node == nullptr) { + error("The node you chose is null."); + return; + } + if (!node->is_class("AnimationPlayer")) { + error("The node you chose is not AnimationPlayer."); + return; + } + anim_player_path = path; } void SpineSpriteAnimateDialog::_on_animate_button_pressed() { - anim_player_path = String(""); - auto node = (Node*)the_plugin->get_editor_interface()->get_selection()->get_selected_nodes().back(); - spine_sprite_path = node->get_path(); + anim_player_path = String(""); + auto node = (Node *) the_plugin->get_editor_interface()->get_selection()->get_selected_nodes().back(); + 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); - scene_tree_dialog->popup_centered_ratio(); + animate_dialog_override_button->set_visible(false); + scene_tree_dialog->popup_centered_ratio(); } void SpineSpriteAnimateDialog::_on_scene_tree_hide() { - animate_dialog->popup_centered(); + animate_dialog->popup_centered(); - bool err = false; - 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); - } + bool err = false; + 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); + } } void SpineSpriteAnimateDialog::_on_animate_dialog_action(const String &act) { - bool err = false; - if (act == "confirmed") { - gen_new_animation_player((SpineSprite*)get_node_or_null(spine_sprite_path), err); - } 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); - } - if (!err) { - animate_dialog->hide(); - } + bool err = false; + if (act == "confirmed") { + gen_new_animation_player((SpineSprite *) get_node_or_null(spine_sprite_path), err); + } 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); + } + if (!err) { + animate_dialog->hide(); + } } diff --git a/spine-godot/spine_godot/SpineSpriteAnimateDialog.h b/spine-godot/spine_godot/SpineSpriteAnimateDialog.h index b4446ec78..04f26d619 100644 --- a/spine-godot/spine_godot/SpineSpriteAnimateDialog.h +++ b/spine-godot/spine_godot/SpineSpriteAnimateDialog.h @@ -36,51 +36,52 @@ class SpineSprite; class SpineSpriteAnimateDialog : public Control { - GDCLASS(SpineSpriteAnimateDialog, Control); + GDCLASS(SpineSpriteAnimateDialog, Control); protected: - static void _bind_methods(); + static void _bind_methods(); - AcceptDialog *error_dialog; + AcceptDialog *error_dialog; - ToolButton *animate_button; - EditorPlugin *the_plugin; + ToolButton *animate_button; + EditorPlugin *the_plugin; - ConfirmationDialog *animate_dialog; - Button *animate_dialog_override_button; - Tree *animate_dialog_tree; - SceneTreeDialog *scene_tree_dialog; + ConfirmationDialog *animate_dialog; + Button *animate_dialog_override_button; + Tree *animate_dialog_tree; + SceneTreeDialog *scene_tree_dialog; - NodePath spine_sprite_path; - NodePath anim_player_path; + NodePath spine_sprite_path; + NodePath anim_player_path; - void add_row(const String &animation, bool loop=true, int64_t track_id=0); - void clear_tree(); + void add_row(const String &animation, bool loop = true, int64_t track_id = 0); + 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_anim_player(AnimationPlayer *anim_player, bool &err); + void load_data_from_sprite(SpineSprite *sprite, 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: - SpineSpriteAnimateDialog(); - ~SpineSpriteAnimateDialog(); + SpineSpriteAnimateDialog(); + ~SpineSpriteAnimateDialog(); - void set_animate_button(ToolButton *b); - inline ToolButton *get_animate_button() {return animate_button;} + void set_animate_button(ToolButton *b); + 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_scene_tree_selected(NodePath path); - void _on_scene_tree_hide(); - void _on_animate_dialog_action(const String &act); + void _on_animate_button_pressed(); + void _on_scene_tree_selected(NodePath path); + void _on_scene_tree_hide(); + void _on_animate_dialog_action(const String &act); }; #endif -#endif //GODOT_SPINESPRITEANIMATEDIALOG_H +#endif//GODOT_SPINESPRITEANIMATEDIALOG_H diff --git a/spine-godot/spine_godot/SpineSpriteMeshInstance2D.cpp b/spine-godot/spine_godot/SpineSpriteMeshInstance2D.cpp index ca0fc5cb2..aba2064f0 100644 --- a/spine-godot/spine_godot/SpineSpriteMeshInstance2D.cpp +++ b/spine-godot/spine_godot/SpineSpriteMeshInstance2D.cpp @@ -43,6 +43,6 @@ Ref SpineSpriteMeshInstance2D::get_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); } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpineSpriteMeshInstance2D.h b/spine-godot/spine_godot/SpineSpriteMeshInstance2D.h index 8458d74b2..c748b21cb 100644 --- a/spine-godot/spine_godot/SpineSpriteMeshInstance2D.h +++ b/spine-godot/spine_godot/SpineSpriteMeshInstance2D.h @@ -41,11 +41,12 @@ protected: static void _bind_methods(); Ref slot; + public: SpineSpriteMeshInstance2D(); ~SpineSpriteMeshInstance2D(); - inline void set_slot(Ref s){ + inline void set_slot(Ref s) { slot = s; } Ref get_slot(); @@ -53,4 +54,4 @@ public: void apply_transform_2d(Variant o); }; -#endif //GODOT_SPINESPRITEMESHINSTANCE2D_H +#endif//GODOT_SPINESPRITEMESHINSTANCE2D_H diff --git a/spine-godot/spine_godot/SpineTimeline.cpp b/spine-godot/spine_godot/SpineTimeline.cpp index d4233f1d4..d2de60065 100644 --- a/spine-godot/spine_godot/SpineTimeline.cpp +++ b/spine-godot/spine_godot/SpineTimeline.cpp @@ -36,68 +36,64 @@ #include "core/method_bind_ext.gen.inc" void SpineTimeline::_bind_methods() { - 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_count"), &SpineTimeline::get_frame_count); - 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("getPropertyIds"), &SpineTimeline::getPropertyIds); + 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_count"), &SpineTimeline::get_frame_count); + 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("getPropertyIds"), &SpineTimeline::getPropertyIds); } -SpineTimeline::SpineTimeline():timeline(nullptr) { - +SpineTimeline::SpineTimeline() : timeline(nullptr) { } SpineTimeline::~SpineTimeline() { - } void SpineTimeline::apply(Ref skeleton, float lastTime, float time, Array pEvents, float alpha, - SpineConstant::MixBlend blend, SpineConstant::MixDirection direction) { - spine::Vector events; - events.setSize(pEvents.size(), nullptr); - for (size_t i=0; i)pEvents[i])->get_spine_object(); - } + SpineConstant::MixBlend blend, SpineConstant::MixDirection direction) { + spine::Vector events; + events.setSize(pEvents.size(), nullptr); + for (size_t i = 0; i < events.size(); ++i) { + events[i] = ((Ref) 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() { - return timeline->getFrameEntries(); + return timeline->getFrameEntries(); } int64_t SpineTimeline::get_frame_count() { - return timeline->getFrameCount(); + return timeline->getFrameCount(); } Array SpineTimeline::get_frames() { - auto &frames = timeline->getFrames(); - Array res; - res.resize(frames.size()); + auto &frames = timeline->getFrames(); + Array res; + res.resize(frames.size()); - for (size_t i=0; igetDuration(); + return timeline->getDuration(); } Array SpineTimeline::getPropertyIds() { - auto &ids = timeline->getPropertyIds(); - Array res; - res.resize(ids.size()); + auto &ids = timeline->getPropertyIds(); + Array res; + res.resize(ids.size()); - for (size_t i=0; i - void apply(Ref skeleton, float lastTime, float time, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction); + // Vector + void apply(Ref 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 - Array get_frames(); + // Vector + Array get_frames(); - float get_duration(); + float get_duration(); - // Vector - Array getPropertyIds(); + // Vector + Array getPropertyIds(); }; -#endif //GODOT_SPINETIMELINE_H +#endif//GODOT_SPINETIMELINE_H diff --git a/spine-godot/spine_godot/SpineTrackEntry.cpp b/spine-godot/spine_godot/SpineTrackEntry.cpp index 2906e7a52..fe6979af9 100644 --- a/spine-godot/spine_godot/SpineTrackEntry.cpp +++ b/spine-godot/spine_godot/SpineTrackEntry.cpp @@ -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("set_hold_previous", "v"), &SpineTrackEntry::set_hold_previous); - 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("get_reverse"), &SpineTrackEntry::get_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("set_delay", "v"), &SpineTrackEntry::set_delay); @@ -99,167 +99,167 @@ void SpineTrackEntry::_bind_methods() { BIND_ENUM_CONSTANT(MIXBLEND_ADD); } -SpineTrackEntry::SpineTrackEntry():track_entry(NULL) {} +SpineTrackEntry::SpineTrackEntry() : track_entry(NULL) {} SpineTrackEntry::~SpineTrackEntry() {} -int SpineTrackEntry::get_track_index(){ +int SpineTrackEntry::get_track_index() { return track_entry->getTrackIndex(); } -Ref SpineTrackEntry::get_animation(){ +Ref SpineTrackEntry::get_animation() { Ref gd_anim(memnew(SpineAnimation)); auto anim = track_entry->getAnimation(); - if(anim == NULL) return NULL; + if (anim == NULL) return NULL; gd_anim->set_spine_object(anim); return gd_anim; } -bool SpineTrackEntry::get_loop(){ +bool SpineTrackEntry::get_loop() { return track_entry->getLoop(); } -void SpineTrackEntry::set_loop(bool v){ +void SpineTrackEntry::set_loop(bool v) { track_entry->setLoop(v); } -bool SpineTrackEntry::get_hold_previous(){ +bool SpineTrackEntry::get_hold_previous() { return track_entry->getHoldPrevious(); } -void SpineTrackEntry::set_hold_previous(bool v){ +void SpineTrackEntry::set_hold_previous(bool v) { track_entry->setHoldPrevious(v); } -float SpineTrackEntry::get_delay(){ +float SpineTrackEntry::get_delay() { return track_entry->getDelay(); } -void SpineTrackEntry::set_delay(float v){ +void SpineTrackEntry::set_delay(float v) { track_entry->setDelay(v); } -float SpineTrackEntry::get_track_time(){ +float SpineTrackEntry::get_track_time() { return track_entry->getTrackTime(); } -void SpineTrackEntry::set_track_time(float v){ +void SpineTrackEntry::set_track_time(float v) { track_entry->setTrackTime(v); } -float SpineTrackEntry::get_track_end(){ +float SpineTrackEntry::get_track_end() { return track_entry->getTrackEnd(); } -void SpineTrackEntry::set_track_end(float v){ +void SpineTrackEntry::set_track_end(float v) { track_entry->setTrackEnd(v); } -float SpineTrackEntry::get_animation_start(){ +float SpineTrackEntry::get_animation_start() { return track_entry->getAnimationStart(); } -void SpineTrackEntry::set_animation_start(float v){ +void SpineTrackEntry::set_animation_start(float v) { track_entry->setAnimationStart(v); } -float SpineTrackEntry::get_animation_last(){ +float SpineTrackEntry::get_animation_last() { return track_entry->getAnimationLast(); } -void SpineTrackEntry::set_animation_last(float v){ +void SpineTrackEntry::set_animation_last(float v) { track_entry->setAnimationLast(v); } -float SpineTrackEntry::get_animation_time(){ +float SpineTrackEntry::get_animation_time() { return track_entry->getAnimationTime(); } -float SpineTrackEntry::get_time_scale(){ +float SpineTrackEntry::get_time_scale() { return track_entry->getTimeScale(); } -void SpineTrackEntry::set_time_scale(float v){ +void SpineTrackEntry::set_time_scale(float v) { track_entry->setTimeScale(v); } -float SpineTrackEntry::get_alpha(){ +float SpineTrackEntry::get_alpha() { return track_entry->getAlpha(); } -void SpineTrackEntry::set_alpha(float v){ +void SpineTrackEntry::set_alpha(float v) { track_entry->setAlpha(v); } -float SpineTrackEntry::get_event_threshold(){ +float SpineTrackEntry::get_event_threshold() { return track_entry->getEventThreshold(); } -void SpineTrackEntry::set_event_threshold(float v){ +void SpineTrackEntry::set_event_threshold(float v) { track_entry->setEventThreshold(v); } -float SpineTrackEntry::get_attachment_threshold(){ +float SpineTrackEntry::get_attachment_threshold() { return track_entry->getAttachmentThreshold(); } -void SpineTrackEntry::set_attachment_threshold(float v){ +void SpineTrackEntry::set_attachment_threshold(float v) { track_entry->setAttachmentThreshold(v); } -float SpineTrackEntry::get_draw_order_threshold(){ +float SpineTrackEntry::get_draw_order_threshold() { return track_entry->getDrawOrderThreshold(); } -void SpineTrackEntry::set_draw_order_threshold(float v){ +void SpineTrackEntry::set_draw_order_threshold(float v) { track_entry->setDrawOrderThreshold(v); } -Ref SpineTrackEntry::get_next(){ +Ref SpineTrackEntry::get_next() { Ref gd_entry(memnew(SpineTrackEntry)); auto entry = track_entry->getNext(); - if(entry == NULL) return NULL; + if (entry == NULL) return NULL; gd_entry->set_spine_object(entry); return gd_entry; } -bool SpineTrackEntry::is_complete(){ +bool SpineTrackEntry::is_complete() { return track_entry->isComplete(); } -float SpineTrackEntry::get_mix_time(){ +float SpineTrackEntry::get_mix_time() { return track_entry->getMixTime(); } -void SpineTrackEntry::set_mix_time(float v){ +void SpineTrackEntry::set_mix_time(float v) { track_entry->setMixTime(v); } -float SpineTrackEntry::get_mix_duration(){ +float SpineTrackEntry::get_mix_duration() { return track_entry->getMixDuration(); } -void SpineTrackEntry::set_mix_duration(float v){ +void SpineTrackEntry::set_mix_duration(float v) { track_entry->setMixDuration(v); } -SpineTrackEntry::MixBlend SpineTrackEntry::get_mix_blend(){ +SpineTrackEntry::MixBlend SpineTrackEntry::get_mix_blend() { int mb = track_entry->getMixBlend(); return (MixBlend) mb; } -void SpineTrackEntry::set_mix_blend(SpineTrackEntry::MixBlend v){ +void SpineTrackEntry::set_mix_blend(SpineTrackEntry::MixBlend v) { int mb = (int) v; - track_entry->setMixBlend((spine::MixBlend)mb); + track_entry->setMixBlend((spine::MixBlend) mb); } -Ref SpineTrackEntry::get_mixing_from(){ +Ref SpineTrackEntry::get_mixing_from() { Ref gd_entry(memnew(SpineTrackEntry)); auto entry = track_entry->getMixingFrom(); - if(entry == NULL) return NULL; + if (entry == NULL) return NULL; gd_entry->set_spine_object(entry); return gd_entry; } -Ref SpineTrackEntry::get_mixing_to(){ +Ref SpineTrackEntry::get_mixing_to() { Ref gd_entry(memnew(SpineTrackEntry)); auto entry = track_entry->getMixingTo(); - if(entry == NULL) return NULL; + if (entry == NULL) return NULL; gd_entry->set_spine_object(entry); return gd_entry; } -void SpineTrackEntry::reset_rotation_directions(){ +void SpineTrackEntry::reset_rotation_directions() { track_entry->resetRotationDirections(); } bool SpineTrackEntry::get_reverse() { - return track_entry->getReverse(); + return track_entry->getReverse(); } void SpineTrackEntry::set_reverse(bool v) { - track_entry->setReverse(v); + track_entry->setReverse(v); } diff --git a/spine-godot/spine_godot/SpineTrackEntry.h b/spine-godot/spine_godot/SpineTrackEntry.h index aad56ec4a..25c4b785f 100644 --- a/spine-godot/spine_godot/SpineTrackEntry.h +++ b/spine-godot/spine_godot/SpineTrackEntry.h @@ -36,7 +36,7 @@ #include "SpineAnimation.h" -class SpineTrackEntry : public Reference{ +class SpineTrackEntry : public Reference { GDCLASS(SpineTrackEntry, Reference); protected: @@ -49,10 +49,10 @@ public: SpineTrackEntry(); ~SpineTrackEntry(); - inline void set_spine_object(spine::TrackEntry *t){ + inline void set_spine_object(spine::TrackEntry *t) { track_entry = t; } - inline spine::TrackEntry *get_spine_object(){ + inline spine::TrackEntry *get_spine_object() { return track_entry; } @@ -73,8 +73,8 @@ public: bool get_hold_previous(); void set_hold_previous(bool v); - bool get_reverse(); - void set_reverse(bool v); + bool get_reverse(); + void set_reverse(bool v); float get_delay(); void set_delay(float v); @@ -128,4 +128,4 @@ public: }; VARIANT_ENUM_CAST(SpineTrackEntry::MixBlend); -#endif //GODOT_SPINETRACKENTRY_H +#endif//GODOT_SPINETRACKENTRY_H diff --git a/spine-godot/spine_godot/SpineTransformConstraint.cpp b/spine-godot/spine_godot/SpineTransformConstraint.cpp index 15450361e..2166a5917 100644 --- a/spine-godot/spine_godot/SpineTransformConstraint.cpp +++ b/spine-godot/spine_godot/SpineTransformConstraint.cpp @@ -51,31 +51,31 @@ void SpineTransformConstraint::_bind_methods() { ClassDB::bind_method(D_METHOD("set_active", "v"), &SpineTransformConstraint::set_active); } -SpineTransformConstraint::SpineTransformConstraint():transform_constraint(NULL) {} +SpineTransformConstraint::SpineTransformConstraint() : transform_constraint(NULL) {} SpineTransformConstraint::~SpineTransformConstraint() {} -void SpineTransformConstraint::update(){ +void SpineTransformConstraint::update() { transform_constraint->update(); } -int SpineTransformConstraint::get_order(){ +int SpineTransformConstraint::get_order() { return transform_constraint->getOrder(); } -Ref SpineTransformConstraint::get_data(){ +Ref SpineTransformConstraint::get_data() { auto &d = transform_constraint->getData(); Ref gd_d(memnew(SpineTransformConstraintData)); gd_d->set_spine_object(&d); return gd_d; } -Array SpineTransformConstraint::get_bones(){ +Array SpineTransformConstraint::get_bones() { auto &bs = transform_constraint->getBones(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i(NULL); + if (b == NULL) gd_bs[i] = Ref(NULL); Ref gd_b(memnew(SpineBone)); gd_b->set_spine_object(b); gd_bs[i] = gd_b; @@ -83,66 +83,66 @@ Array SpineTransformConstraint::get_bones(){ return gd_bs; } -Ref SpineTransformConstraint::get_target(){ +Ref SpineTransformConstraint::get_target() { auto b = transform_constraint->getTarget(); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineBone)); gd_b->set_spine_object(b); return gd_b; } -void SpineTransformConstraint::set_target(Ref v){ - if(v.is_valid()){ +void SpineTransformConstraint::set_target(Ref v) { + if (v.is_valid()) { transform_constraint->setTarget(v->get_spine_object()); - } else{ + } else { transform_constraint->setTarget(NULL); } } -float SpineTransformConstraint::get_mix_rotate(){ +float SpineTransformConstraint::get_mix_rotate() { return transform_constraint->getMixRotate(); } -void SpineTransformConstraint::set_mix_rotate(float v){ +void SpineTransformConstraint::set_mix_rotate(float v) { transform_constraint->setMixRotate(v); } -float SpineTransformConstraint::get_mix_x(){ +float SpineTransformConstraint::get_mix_x() { return transform_constraint->getMixX(); } -void SpineTransformConstraint::set_mix_x(float v){ +void SpineTransformConstraint::set_mix_x(float v) { transform_constraint->setMixX(v); } -float SpineTransformConstraint::get_mix_y(){ +float SpineTransformConstraint::get_mix_y() { return transform_constraint->getMixY(); } -void SpineTransformConstraint::set_mix_y(float v){ +void SpineTransformConstraint::set_mix_y(float v) { transform_constraint->setMixY(v); } -float SpineTransformConstraint::get_mix_scale_x(){ +float SpineTransformConstraint::get_mix_scale_x() { return transform_constraint->getMixScaleX(); } -void SpineTransformConstraint::set_mix_scale_x(float v){ +void SpineTransformConstraint::set_mix_scale_x(float v) { transform_constraint->setMixScaleX(v); } -float SpineTransformConstraint::get_mix_scale_y(){ +float SpineTransformConstraint::get_mix_scale_y() { return transform_constraint->getMixScaleY(); } -void SpineTransformConstraint::set_mix_scale_y(float v){ +void SpineTransformConstraint::set_mix_scale_y(float v) { transform_constraint->setMixScaleY(v); } -float SpineTransformConstraint::get_mix_shear_y(){ +float SpineTransformConstraint::get_mix_shear_y() { return transform_constraint->getMixShearY(); } -void SpineTransformConstraint::set_mix_shear_y(float v){ +void SpineTransformConstraint::set_mix_shear_y(float v) { transform_constraint->setMixShearY(v); } -bool SpineTransformConstraint::is_active(){ +bool SpineTransformConstraint::is_active() { return transform_constraint->isActive(); } -void SpineTransformConstraint::set_active(bool v){ +void SpineTransformConstraint::set_active(bool v) { transform_constraint->setActive(v); } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpineTransformConstraint.h b/spine-godot/spine_godot/SpineTransformConstraint.h index a2b3a2be3..6430f05fb 100644 --- a/spine-godot/spine_godot/SpineTransformConstraint.h +++ b/spine-godot/spine_godot/SpineTransformConstraint.h @@ -37,7 +37,7 @@ #include "SpineTransformConstraintData.h" #include "SpineBone.h" -class SpineTransformConstraint : public Reference{ +class SpineTransformConstraint : public Reference { GDCLASS(SpineTransformConstraint, Reference); protected: @@ -50,10 +50,10 @@ public: SpineTransformConstraint(); ~SpineTransformConstraint(); - inline void set_spine_object(spine::TransformConstraint *tc){ + inline void set_spine_object(spine::TransformConstraint *tc) { transform_constraint = tc; } - inline spine::TransformConstraint *get_spine_object(){ + inline spine::TransformConstraint *get_spine_object() { return transform_constraint; } @@ -90,4 +90,4 @@ public: void set_active(bool v); }; -#endif //GODOT_SPINETRANSFORMCONSTRAINT_H +#endif//GODOT_SPINETRANSFORMCONSTRAINT_H diff --git a/spine-godot/spine_godot/SpineTransformConstraintData.cpp b/spine-godot/spine_godot/SpineTransformConstraintData.cpp index af62fea32..c7534cafb 100644 --- a/spine-godot/spine_godot/SpineTransformConstraintData.cpp +++ b/spine-godot/spine_godot/SpineTransformConstraintData.cpp @@ -51,12 +51,12 @@ void SpineTransformConstraintData::_bind_methods() { SpineTransformConstraintData::SpineTransformConstraintData() {} SpineTransformConstraintData::~SpineTransformConstraintData() {} -Array SpineTransformConstraintData::get_bones(){ +Array SpineTransformConstraintData::get_bones() { auto bs = get_spine_data()->getBones(); Array gd_bs; gd_bs.resize(bs.size()); - for(size_t i=0; i < bs.size(); ++i){ - if(bs[i] == NULL) gd_bs[i] = Ref(NULL); + for (size_t i = 0; i < bs.size(); ++i) { + if (bs[i] == NULL) gd_bs[i] = Ref(NULL); else { Ref gd_b(memnew(SpineBoneData)); gd_b->set_spine_object(bs[i]); @@ -65,54 +65,54 @@ Array SpineTransformConstraintData::get_bones(){ } return gd_bs; } -Ref SpineTransformConstraintData::get_target(){ +Ref SpineTransformConstraintData::get_target() { auto b = get_spine_data()->getTarget(); - if(b == NULL) return NULL; + if (b == NULL) return NULL; Ref gd_b(memnew(SpineBoneData)); gd_b->set_spine_object(b); return gd_b; } -float SpineTransformConstraintData::get_mix_rotate(){ +float SpineTransformConstraintData::get_mix_rotate() { return get_spine_data()->getMixRotate(); } -float SpineTransformConstraintData::get_mix_x(){ +float SpineTransformConstraintData::get_mix_x() { return get_spine_data()->getMixX(); } -float SpineTransformConstraintData::get_mix_y(){ +float SpineTransformConstraintData::get_mix_y() { return get_spine_data()->getMixY(); } -float SpineTransformConstraintData::get_mix_scale_x(){ +float SpineTransformConstraintData::get_mix_scale_x() { return get_spine_data()->getMixScaleX(); } -float SpineTransformConstraintData::get_mix_scale_y(){ +float SpineTransformConstraintData::get_mix_scale_y() { return get_spine_data()->getMixScaleY(); } -float SpineTransformConstraintData::get_mix_shear_y(){ +float SpineTransformConstraintData::get_mix_shear_y() { return get_spine_data()->getMixShearY(); } -float SpineTransformConstraintData::get_offset_rotation(){ +float SpineTransformConstraintData::get_offset_rotation() { return get_spine_data()->getOffsetRotation(); } -float SpineTransformConstraintData::get_offset_x(){ +float SpineTransformConstraintData::get_offset_x() { return get_spine_data()->getOffsetX(); } -float SpineTransformConstraintData::get_offset_y(){ +float SpineTransformConstraintData::get_offset_y() { return get_spine_data()->getOffsetY(); } -float SpineTransformConstraintData::get_offset_scale_x(){ +float SpineTransformConstraintData::get_offset_scale_x() { return get_spine_data()->getOffsetScaleX(); } -float SpineTransformConstraintData::get_offset_scale_y(){ +float SpineTransformConstraintData::get_offset_scale_y() { return get_spine_data()->getOffsetScaleY(); } -float SpineTransformConstraintData::get_offset_shear_y(){ +float SpineTransformConstraintData::get_offset_shear_y() { return get_spine_data()->getOffsetShearY(); } -bool SpineTransformConstraintData::is_relative(){ +bool SpineTransformConstraintData::is_relative() { return get_spine_data()->isRelative(); } -bool SpineTransformConstraintData::is_local(){ +bool SpineTransformConstraintData::is_local() { return get_spine_data()->isLocal(); } \ No newline at end of file diff --git a/spine-godot/spine_godot/SpineTransformConstraintData.h b/spine-godot/spine_godot/SpineTransformConstraintData.h index 5408d0e5b..6c1b21569 100644 --- a/spine-godot/spine_godot/SpineTransformConstraintData.h +++ b/spine-godot/spine_godot/SpineTransformConstraintData.h @@ -47,8 +47,8 @@ public: SpineTransformConstraintData(); ~SpineTransformConstraintData(); - virtual inline spine::TransformConstraintData *get_spine_data(){ - return (spine::TransformConstraintData*) SpineConstraintData::get_spine_object(); + virtual inline spine::TransformConstraintData *get_spine_data() { + return (spine::TransformConstraintData *) SpineConstraintData::get_spine_object(); } Array get_bones(); @@ -71,4 +71,4 @@ public: bool is_local(); }; -#endif //GODOT_SPINETRANSFORMCONSTRAINTDATA_H +#endif//GODOT_SPINETRANSFORMCONSTRAINTDATA_H diff --git a/spine-godot/spine_godot/register_types.cpp b/spine-godot/spine_godot/register_types.cpp index a6039a240..5aa2f7de7 100644 --- a/spine-godot/spine_godot/register_types.cpp +++ b/spine-godot/spine_godot/register_types.cpp @@ -74,22 +74,22 @@ static Ref json_skeleton_saver; #include "SpineRuntimeEditorPlugin.h" 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 -void register_spine_godot_types(){ +void register_spine_godot_types() { #ifdef TOOLS_ENABLED - ClassDB::register_class(); + ClassDB::register_class(); EditorNode::add_init_callback(editor_init_callback); #endif - - ClassDB::register_class(); - ClassDB::register_class(); + + ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); @@ -120,26 +120,25 @@ void register_spine_godot_types(){ ClassDB::register_class(); ClassDB::register_class(); - atlas_loader.instance(); - ResourceLoader::add_resource_format_loader(atlas_loader); + atlas_loader.instance(); + ResourceLoader::add_resource_format_loader(atlas_loader); - atlas_saver.instance(); - ResourceSaver::add_resource_format_saver(atlas_saver); + atlas_saver.instance(); + ResourceSaver::add_resource_format_saver(atlas_saver); json_skeleton_loader.instance(); ResourceLoader::add_resource_format_loader(json_skeleton_loader); json_skeleton_saver.instance(); ResourceSaver::add_resource_format_saver(json_skeleton_saver); - } -void unregister_spine_godot_types(){ - ResourceLoader::remove_resource_format_loader(atlas_loader); - atlas_loader.unref(); +void unregister_spine_godot_types() { + ResourceLoader::remove_resource_format_loader(atlas_loader); + atlas_loader.unref(); - ResourceSaver::remove_resource_format_saver(atlas_saver); - atlas_saver.unref(); + ResourceSaver::remove_resource_format_saver(atlas_saver); + atlas_saver.unref(); ResourceLoader::remove_resource_format_loader(json_skeleton_loader); json_skeleton_loader.unref(); diff --git a/spine-godot/spine_godot/register_types.h b/spine-godot/spine_godot/register_types.h index 694761811..59ef9515f 100644 --- a/spine-godot/spine_godot/register_types.h +++ b/spine-godot/spine_godot/register_types.h @@ -29,4 +29,3 @@ void register_spine_godot_types(); void unregister_spine_godot_types(); - diff --git a/spine-ts/spine-core/src/AnimationState.ts b/spine-ts/spine-core/src/AnimationState.ts index fd0691bf1..4dac3da2d 100644 --- a/spine-ts/spine-core/src/AnimationState.ts +++ b/spine-ts/spine-core/src/AnimationState.ts @@ -1095,24 +1095,24 @@ export enum EventType { * {@link AnimationState#addListener()}. */ export interface AnimationStateListener { /** 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 * 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. */ - 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. * 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. */ - complete? (entry: TrackEntry): void; + complete?(entry: TrackEntry): void; /** 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 {