From 9ad9fff97eac580a7cd9e95608eb1d89f1daa9a8 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Fri, 1 Oct 2021 15:40:53 +0200 Subject: [PATCH] Move atlas format loader/saver to spineatlas.h, remove custom skin resource. --- spine-godot/example/project.godot | 2 +- .../example/{test.tscn => spineboy.tscn} | 11 ++-- .../ResourceFormatLoaderSpineAtlas.cpp | 56 ---------------- .../ResourceFormatLoaderSpineAtlas.h | 46 ------------- .../ResourceFormatSaverSpineAtlas.cpp | 48 -------------- .../ResourceFormatSaverSpineAtlas.h | 45 ------------- .../spine_godot/SpineAtlasResource.cpp | 42 ++++++++++++ spine-godot/spine_godot/SpineAtlasResource.h | 25 +++++++- .../spine_godot/SpineCustomSkinResource.cpp | 64 ------------------- .../spine_godot/SpineCustomSkinResource.h | 58 ----------------- spine-godot/spine_godot/SpineSprite.cpp | 61 +----------------- spine-godot/spine_godot/SpineSprite.h | 11 ---- spine-godot/spine_godot/register_types.cpp | 9 +-- 13 files changed, 77 insertions(+), 401 deletions(-) rename spine-godot/example/{test.tscn => spineboy.tscn} (72%) delete mode 100644 spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.cpp delete mode 100644 spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.h delete mode 100644 spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.cpp delete mode 100644 spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.h delete mode 100644 spine-godot/spine_godot/SpineCustomSkinResource.cpp delete mode 100644 spine-godot/spine_godot/SpineCustomSkinResource.h diff --git a/spine-godot/example/project.godot b/spine-godot/example/project.godot index 1f28721fa..c7fc9bd26 100644 --- a/spine-godot/example/project.godot +++ b/spine-godot/example/project.godot @@ -11,7 +11,7 @@ config_version=4 [application] config/name="spine-godot-examples" -run/main_scene="res://test.tscn" +run/main_scene="res://spineboy.tscn" config/icon="res://icon.png" [physics] diff --git a/spine-godot/example/test.tscn b/spine-godot/example/spineboy.tscn similarity index 72% rename from spine-godot/example/test.tscn rename to spine-godot/example/spineboy.tscn index edaa0c6e4..8a99d91f3 100644 --- a/spine-godot/example/test.tscn +++ b/spine-godot/example/spineboy.tscn @@ -1,11 +1,11 @@ [gd_scene load_steps=5 format=2] -[ext_resource path="res://spineboy/spineboy.atlas" type="SpineAtlasResource" id=1] -[ext_resource path="res://spineboy/spineboy-pro.json" type="SpineSkeletonJsonDataResource" id=2] +[ext_resource path="res://spineboy/spineboy-pro.json" type="SpineSkeletonJsonDataResource" id=1] +[ext_resource path="res://spineboy/spineboy.atlas" type="SpineAtlasResource" id=2] [sub_resource type="SpineSkeletonDataResource" id=1] -atlas_res = ExtResource( 1 ) -skeleton_json_res = ExtResource( 2 ) +atlas_res = ExtResource( 2 ) +skeleton_json_res = ExtResource( 1 ) animations = null skins = null @@ -13,7 +13,8 @@ skins = null skeleton = SubResource( 1 ) [node name="Node2D" type="Node2D"] -position = Vector2( 500.369, 609.791 ) [node name="SpineSprite" type="SpineSprite" parent="."] +position = Vector2( 504, 622 ) animation_state_data_res = SubResource( 2 ) +current_animations = [ "walk" ] diff --git a/spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.cpp b/spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.cpp deleted file mode 100644 index f3c5c8ada..000000000 --- a/spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/****************************************************************************** - * Spine Runtimes License Agreement - * Last updated January 1, 2020. Replaces all prior versions. - * - * Copyright (c) 2013-2020, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, - * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -#include "ResourceFormatLoaderSpineAtlas.h" -#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); - - 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); - } -} - -String ResourceFormatLoaderSpineAtlas::get_resource_type(const String &p_path) const { - return "SpineAtlasResource"; -} - -bool ResourceFormatLoaderSpineAtlas::handles_type(const String &p_type) const { - 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 deleted file mode 100644 index 27133afca..000000000 --- a/spine-godot/spine_godot/ResourceFormatLoaderSpineAtlas.h +++ /dev/null @@ -1,46 +0,0 @@ -/****************************************************************************** - * Spine Runtimes License Agreement - * Last updated January 1, 2020. Replaces all prior versions. - * - * Copyright (c) 2013-2020, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, - * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -#ifndef GODOT_RESOURCEFORMATLOADERSPINEATLAS_H -#define GODOT_RESOURCEFORMATLOADERSPINEATLAS_H - -#include "core/io/resource_loader.h" - -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; -}; - - -#endif//GODOT_RESOURCEFORMATLOADERSPINEATLAS_H diff --git a/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.cpp b/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.cpp deleted file mode 100644 index ef051f31c..000000000 --- a/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.cpp +++ /dev/null @@ -1,48 +0,0 @@ -/****************************************************************************** - * Spine Runtimes License Agreement - * Last updated January 1, 2020. Replaces all prior versions. - * - * Copyright (c) 2013-2020, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, - * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -#include "ResourceFormatSaverSpineAtlas.h" - -#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; -} - -void ResourceFormatSaverSpineAtlas::get_recognized_extensions(const RES &p_resource, List *p_extensions) const { - 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; -} diff --git a/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.h b/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.h deleted file mode 100644 index b20420772..000000000 --- a/spine-godot/spine_godot/ResourceFormatSaverSpineAtlas.h +++ /dev/null @@ -1,45 +0,0 @@ -/****************************************************************************** - * Spine Runtimes License Agreement - * Last updated January 1, 2020. Replaces all prior versions. - * - * Copyright (c) 2013-2020, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, - * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -#ifndef GODOT_RESOURCEFORMATSAVERSPINEATLAS_H -#define GODOT_RESOURCEFORMATSAVERSPINEATLAS_H - -#include "core/io/resource_saver.h" - -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; -}; - - -#endif//GODOT_RESOURCEFORMATSAVERSPINEATLAS_H diff --git a/spine-godot/spine_godot/SpineAtlasResource.cpp b/spine-godot/spine_godot/SpineAtlasResource.cpp index e8e0d3bc0..088426621 100644 --- a/spine-godot/spine_godot/SpineAtlasResource.cpp +++ b/spine-godot/spine_godot/SpineAtlasResource.cpp @@ -101,6 +101,7 @@ public: }; SpineAtlasResource::SpineAtlasResource() : atlas(nullptr), normal_texture_prefix("n") {} + SpineAtlasResource::~SpineAtlasResource() { if (atlas) delete atlas; } @@ -195,3 +196,44 @@ Error SpineAtlasResource::save_to_file(const String &p_path) { return OK; } + +RES SpineAtlasResourceFormatLoader::load(const String &p_path, const String &p_original_path, Error *r_error) { + Ref atlas = memnew(SpineAtlasResource); + atlas->load_from_file(p_path); + + if (r_error) { + *r_error = OK; + } + return atlas; +} + +void SpineAtlasResourceFormatLoader::get_recognized_extensions(List *r_extensions) const { + const char atlas_ext[] = "spatlas"; + if (!r_extensions->find(atlas_ext)) { + r_extensions->push_back(atlas_ext); + } +} + +String SpineAtlasResourceFormatLoader::get_resource_type(const String &p_path) const { + return "SpineAtlasResource"; +} + +bool SpineAtlasResourceFormatLoader::handles_type(const String &p_type) const { + return p_type == "SpineAtlasResource" || ClassDB::is_parent_class(p_type, "SpineAtlasResource"); +} + +Error SpineAtlasResourceFormatSaver::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; +} + +void SpineAtlasResourceFormatSaver::get_recognized_extensions(const RES &p_resource, List *p_extensions) const { + if (Object::cast_to(*p_resource)) { + p_extensions->push_back("spatlas"); + } +} + +bool SpineAtlasResourceFormatSaver::recognize(const RES &p_resource) const { + return Object::cast_to(*p_resource) != nullptr; +} diff --git a/spine-godot/spine_godot/SpineAtlasResource.h b/spine-godot/spine_godot/SpineAtlasResource.h index eea94bbbf..84c7cc9ca 100644 --- a/spine-godot/spine_godot/SpineAtlasResource.h +++ b/spine-godot/spine_godot/SpineAtlasResource.h @@ -32,12 +32,14 @@ #include "core/variant_parser.h" +#include "core/io/resource_loader.h" +#include "core/io/resource_saver.h" +#include "core/io/image_loader.h" +#include "scene/resources/texture.h" #include #include #include -#include -#include #include "SpineRendererObject.h" class SpineAtlasResource : public Resource { @@ -75,5 +77,24 @@ public: virtual ~SpineAtlasResource(); }; +class SpineAtlasResourceFormatLoader : public ResourceFormatLoader { +GDCLASS(SpineAtlasResourceFormatLoader, 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; +}; + +class SpineAtlasResourceFormatSaver : public ResourceFormatSaver { +GDCLASS(SpineAtlasResourceFormatSaver, 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; +}; + #endif//GODOT_SPINEATLASRESOURCE_H diff --git a/spine-godot/spine_godot/SpineCustomSkinResource.cpp b/spine-godot/spine_godot/SpineCustomSkinResource.cpp deleted file mode 100644 index e15677dba..000000000 --- a/spine-godot/spine_godot/SpineCustomSkinResource.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/****************************************************************************** - * Spine Runtimes License Agreement - * Last updated January 1, 2020. Replaces all prior versions. - * - * Copyright (c) 2013-2020, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, - * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -#include "SpineCustomSkinResource.h" - -void SpineCustomSkinResource::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_skin_name", "v"), &SpineCustomSkinResource::set_skin_name); - ClassDB::bind_method(D_METHOD("get_skin_name"), &SpineCustomSkinResource::get_skin_name); - ClassDB::bind_method(D_METHOD("set_sub_skin_names", "v"), &SpineCustomSkinResource::set_sub_skin_names); - ClassDB::bind_method(D_METHOD("get_sub_skin_names"), &SpineCustomSkinResource::get_sub_skin_names); - - ADD_SIGNAL(MethodInfo("property_changed")); - - ADD_PROPERTY(PropertyInfo(Variant::STRING, "skin_name"), "set_skin_name", "get_skin_name"); - ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "sub_skin_names"), "set_sub_skin_names", "get_sub_skin_names"); -} - -SpineCustomSkinResource::SpineCustomSkinResource() : skin_name("custom_skin_name") {} - -SpineCustomSkinResource::~SpineCustomSkinResource() {} - -void SpineCustomSkinResource::set_skin_name(const String &v) { - skin_name = v; - emit_signal("property_changed"); -} - -String SpineCustomSkinResource::get_skin_name() { - return skin_name; -} - -void SpineCustomSkinResource::set_sub_skin_names(Array v) { - sub_skin_names = v; - emit_signal("property_changed"); -} - -Array SpineCustomSkinResource::get_sub_skin_names() { - return sub_skin_names; -} \ No newline at end of file diff --git a/spine-godot/spine_godot/SpineCustomSkinResource.h b/spine-godot/spine_godot/SpineCustomSkinResource.h deleted file mode 100644 index ebcd5dd7f..000000000 --- a/spine-godot/spine_godot/SpineCustomSkinResource.h +++ /dev/null @@ -1,58 +0,0 @@ -/****************************************************************************** - * Spine Runtimes License Agreement - * Last updated January 1, 2020. Replaces all prior versions. - * - * Copyright (c) 2013-2020, Esoteric Software LLC - * - * Integration of the Spine Runtimes into software or otherwise creating - * derivative works of the Spine Runtimes is permitted under the terms and - * conditions of Section 2 of the Spine Editor License Agreement: - * http://esotericsoftware.com/spine-editor-license - * - * Otherwise, it is permitted to integrate the Spine Runtimes into software - * or otherwise create derivative works of the Spine Runtimes (collectively, - * "Products"), provided that each user of the Products must obtain their own - * Spine Editor license and redistribution of the Products in any form must - * include this license and copyright notice. - * - * THE SPINE RUNTIMES ARE PROVIDED BY ESOTERIC SOFTWARE LLC "AS IS" AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL ESOTERIC SOFTWARE LLC BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, - * BUSINESS INTERRUPTION, OR LOSS OF USE, DATA, OR PROFITS) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - * THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - *****************************************************************************/ - -#ifndef GODOT_SPINECUSTOMSKINRESOURCE_H -#define GODOT_SPINECUSTOMSKINRESOURCE_H - -#include "core/variant_parser.h" -#include "SpineSkin.h" - -class SpineCustomSkinResource : public Resource { - GDCLASS(SpineCustomSkinResource, Resource); - -protected: - static void _bind_methods(); - -private: - String skin_name; - Array sub_skin_names; - -public: - SpineCustomSkinResource(); - virtual ~SpineCustomSkinResource(); - - void set_skin_name(const String &v); - String get_skin_name(); - - void set_sub_skin_names(Array v); - Array get_sub_skin_names(); -}; -#include "SpineSkin.h" -#include "core/variant_parser.h" -#endif //GODOT_SPINECUSTOMSKINRESOURCE_H diff --git a/spine-godot/spine_godot/SpineSprite.cpp b/spine-godot/spine_godot/SpineSprite.cpp index 7de4bd19f..1da9c898d 100644 --- a/spine-godot/spine_godot/SpineSprite.cpp +++ b/spine-godot/spine_godot/SpineSprite.cpp @@ -29,7 +29,6 @@ #include "SpineSprite.h" -#include "SpineCustomSkinResource.h" #include "SpineEvent.h" #include "SpineTrackEntry.h" @@ -62,10 +61,6 @@ void SpineSprite::_bind_methods() { 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_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); - ClassDB::bind_method(D_METHOD("gen_spine_skin_from_packed_resource", "res"), &SpineSprite::gen_spine_skin_from_packed_resource); 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); @@ -87,7 +82,7 @@ void SpineSprite::_bind_methods() { 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, "SpineCustomSkinResource"), "set_skin", "get_skin"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "custom_skin_resource", PropertyHint::PROPERTY_HINT_RESOURCE_TYPE, "SpineCustomSkinResource"), "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"); @@ -636,6 +631,7 @@ void SpineSprite::set_set_empty_animations(bool v) { Array SpineSprite::get_bind_slot_nodes() { return bind_slot_nodes; } + void SpineSprite::set_bind_slot_nodes(Array v) { bind_slot_nodes = v; } @@ -643,62 +639,11 @@ void SpineSprite::set_bind_slot_nodes(Array v) { bool SpineSprite::get_overlap() { return overlap; } + 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")) - 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")) - skin->connect("property_changed", this, "_on_skin_property_changed"); - update_runtime_skin(); - } -} -Ref SpineSprite::get_skin() { - return skin; -} -void SpineSprite::update_runtime_skin() { - auto new_skin = gen_spine_skin_from_packed_resource(skin); - - if (new_skin.is_valid()) { - skeleton->set_skin(new_skin); - skeleton->set_to_setup_pose(); - } -} -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())) - return NULL; - if (!res.is_valid()) - return NULL; - 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()) { - 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; i < sub_skin_names.size(); ++i) { - auto skin_name = (String) sub_skin_names[i]; - auto sub_skin = animation_state_data_res->get_skeleton()->find_skin(skin_name); - 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) { auto node_path = n->get_path_to(this); diff --git a/spine-godot/spine_godot/SpineSprite.h b/spine-godot/spine_godot/SpineSprite.h index 79d24b6ed..fc7276091 100644 --- a/spine-godot/spine_godot/SpineSprite.h +++ b/spine-godot/spine_godot/SpineSprite.h @@ -31,13 +31,10 @@ #define GODOT_SPINESPRITE_H #include - #include -#include "SpineCustomSkinResource.h" #include "SpineAnimationState.h" #include "SpineAnimationStateDataResource.h" -#include "SpineCustomSkinResource.h" #include "SpineSkeleton.h" #include "SpineSpriteMeshInstance2D.h" @@ -76,7 +73,6 @@ private: Array bind_slot_nodes; bool overlap; - Ref skin; ProcessMode process_mode; @@ -146,13 +142,6 @@ public: bool get_overlap(); void set_overlap(bool v); - void set_skin(Ref v); - Ref get_skin(); - void _on_skin_property_changed(); - void update_runtime_skin(); - - 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); diff --git a/spine-godot/spine_godot/register_types.cpp b/spine-godot/spine_godot/register_types.cpp index 429ff926b..1fd9ad626 100644 --- a/spine-godot/spine_godot/register_types.cpp +++ b/spine-godot/spine_godot/register_types.cpp @@ -32,8 +32,6 @@ #include "core/class_db.h" #include "SpineAtlasResource.h" -#include "ResourceFormatLoaderSpineAtlas.h" -#include "ResourceFormatSaverSpineAtlas.h" #include "SpineSkeletonDataResource.h" #include "ResourceFormatLoaderSpineSkeletonJsonData.h" #include "ResourceFormatSaverSpineSkeletonJsonData.h" @@ -54,15 +52,14 @@ #include "SpineTransformConstraintData.h" #include "SpinePathConstraintData.h" #include "SpineSpriteMeshInstance2D.h" -#include "SpineCustomSkinResource.h" #include "SpineTimeline.h" #include "SpineConstant.h" #include "SpineCollisionShapeProxy.h" #include "SpineSpriteAnimateDialog.h" -static Ref atlas_loader; -static Ref atlas_saver; +static Ref atlas_loader; +static Ref atlas_saver; static Ref json_skeleton_loader; static Ref json_skeleton_saver; @@ -71,7 +68,6 @@ static Ref json_skeleton_saver; #include "editor/editor_export.h" #include "editor/editor_node.h" -#include "SpineCustomSkinResource.h" #include "SpineRuntimeEditorPlugin.h" static void editor_init_callback() { @@ -116,7 +112,6 @@ void register_spine_godot_types() { ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); - ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class();