mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-10 00:58:43 +08:00
Move atlas format loader/saver to spineatlas.h, remove custom skin resource.
This commit is contained in:
parent
51a236c60f
commit
9ad9fff97e
@ -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]
|
||||
|
||||
@ -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" ]
|
||||
@ -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<SpineAtlasResource> atlas = memnew(SpineAtlasResource);
|
||||
atlas->load_from_file(p_path);
|
||||
|
||||
if (r_error) {
|
||||
*r_error = OK;
|
||||
}
|
||||
return atlas;
|
||||
}
|
||||
|
||||
void ResourceFormatLoaderSpineAtlas::get_recognized_extensions(List<String> *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");
|
||||
}
|
||||
@ -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<String> *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
|
||||
@ -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<SpineAtlasResource> 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<String> *p_extensions) const {
|
||||
if (Object::cast_to<SpineAtlasResource>(*p_resource)) {
|
||||
p_extensions->push_back("spatlas");
|
||||
}
|
||||
}
|
||||
|
||||
bool ResourceFormatSaverSpineAtlas::recognize(const RES &p_resource) const {
|
||||
return Object::cast_to<SpineAtlasResource>(*p_resource) != nullptr;
|
||||
}
|
||||
@ -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<String> *p_extensions) const override;
|
||||
bool recognize(const RES &p_resource) const override;
|
||||
};
|
||||
|
||||
|
||||
#endif//GODOT_RESOURCEFORMATSAVERSPINEATLAS_H
|
||||
@ -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<SpineAtlasResource> atlas = memnew(SpineAtlasResource);
|
||||
atlas->load_from_file(p_path);
|
||||
|
||||
if (r_error) {
|
||||
*r_error = OK;
|
||||
}
|
||||
return atlas;
|
||||
}
|
||||
|
||||
void SpineAtlasResourceFormatLoader::get_recognized_extensions(List<String> *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<SpineAtlasResource> 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<String> *p_extensions) const {
|
||||
if (Object::cast_to<SpineAtlasResource>(*p_resource)) {
|
||||
p_extensions->push_back("spatlas");
|
||||
}
|
||||
}
|
||||
|
||||
bool SpineAtlasResourceFormatSaver::recognize(const RES &p_resource) const {
|
||||
return Object::cast_to<SpineAtlasResource>(*p_resource) != nullptr;
|
||||
}
|
||||
|
||||
@ -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 <spine/SpineString.h>
|
||||
#include <spine/TextureLoader.h>
|
||||
#include <spine/Atlas.h>
|
||||
#include <scene/resources/texture.h>
|
||||
#include <core/io/image_loader.h>
|
||||
#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<String> *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<String> *p_extensions) const override;
|
||||
bool recognize(const RES &p_resource) const override;
|
||||
};
|
||||
|
||||
|
||||
#endif//GODOT_SPINEATLASRESOURCE_H
|
||||
|
||||
@ -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;
|
||||
}
|
||||
@ -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
|
||||
@ -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<SpineCustomSkinResource> 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<SpineCustomSkinResource> 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<SpineSkin> SpineSprite::gen_spine_skin_from_packed_resource(Ref<SpineCustomSkinResource> 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<SpineSkin>(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);
|
||||
|
||||
|
||||
@ -31,13 +31,10 @@
|
||||
#define GODOT_SPINESPRITE_H
|
||||
|
||||
#include <scene/resources/texture.h>
|
||||
|
||||
#include <scene/2d/collision_polygon_2d.h>
|
||||
|
||||
#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<SpineCustomSkinResource> skin;
|
||||
|
||||
ProcessMode process_mode;
|
||||
|
||||
@ -146,13 +142,6 @@ public:
|
||||
bool get_overlap();
|
||||
void set_overlap(bool v);
|
||||
|
||||
void set_skin(Ref<SpineCustomSkinResource> v);
|
||||
Ref<SpineCustomSkinResource> get_skin();
|
||||
void _on_skin_property_changed();
|
||||
void update_runtime_skin();
|
||||
|
||||
Ref<SpineSkin> gen_spine_skin_from_packed_resource(Ref<SpineCustomSkinResource> res);
|
||||
|
||||
// current animation count
|
||||
int64_t get_current_animation_count() const;
|
||||
void set_current_animation_count(int64_t v);
|
||||
|
||||
@ -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<ResourceFormatLoaderSpineAtlas> atlas_loader;
|
||||
static Ref<ResourceFormatSaverSpineAtlas> atlas_saver;
|
||||
static Ref<SpineAtlasResourceFormatLoader> atlas_loader;
|
||||
static Ref<SpineAtlasResourceFormatSaver> atlas_saver;
|
||||
static Ref<ResourceFormatLoaderSpineSkeletonJsonData> json_skeleton_loader;
|
||||
static Ref<ResourceFormatSaverSpineSkeletonJsonData> json_skeleton_saver;
|
||||
|
||||
@ -71,7 +68,6 @@ static Ref<ResourceFormatSaverSpineSkeletonJsonData> 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<SpinePathConstraint>();
|
||||
ClassDB::register_class<SpineTransformConstraint>();
|
||||
ClassDB::register_class<SpineSpriteMeshInstance2D>();
|
||||
ClassDB::register_class<SpineCustomSkinResource>();
|
||||
ClassDB::register_class<SpineTimeline>();
|
||||
ClassDB::register_class<SpineConstant>();
|
||||
ClassDB::register_class<SpineCollisionShapeProxy>();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user