Forráskód Böngészése

[godot] Clean-up SpineSkinAttachmentMapEntry

Entirely rewritten, we now return an array of SpineSkinEntry items instead.
Mario Zechner 3 éve
szülő
commit
6ba8f3d67c

+ 17 - 13
spine-godot/example/examples/mix-and-match/mix-and-match.gd

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

+ 37 - 6
spine-godot/spine_godot/SpineSkin.cpp

@@ -136,12 +136,22 @@ void SpineSkin::copy_skin(Ref<SpineSkin> other) {
 	skin->copySkin(other->get_spine_object());
 }
 
-Ref<SpineSkinAttachmentMapEntries> SpineSkin::get_attachments() {
-	SPINE_CHECK(skin, nullptr)
-	auto *entries = new spine::Skin::AttachmentMap::Entries(skin->getAttachments());
-	Ref<SpineSkinAttachmentMapEntries> entries_ref(memnew(SpineSkinAttachmentMapEntries));
-	entries_ref->set_spine_object(entries);
-	return entries_ref;
+Array SpineSkin::get_attachments() {
+	Array result;
+	SPINE_CHECK(skin, result)
+	auto entries = skin->getAttachments();
+	while(entries.hasNext()) {
+		spine::Skin::AttachmentMap::Entry &entry = entries.next();
+		Ref<SpineSkinEntry> entry_ref = memnew(SpineSkinEntry);
+		Ref<SpineAttachment> attachment_ref = nullptr;
+		if (entry._attachment) {
+			Ref<SpineAttachment> attachment_ref = memnew(SpineAttachment);
+			attachment_ref->set_spine_object(entry._attachment);
+		}
+		entry_ref->init(entry._slotIndex, entry._name.buffer(), attachment_ref);
+		result.push_back(entry_ref);
+	}
+	return result;
 }
 
 Array SpineSkin::get_bones() {
@@ -169,3 +179,24 @@ Array SpineSkin::get_constraints() {
 	}
 	return result;
 }
+
+void SpineSkinEntry::_bind_methods() {
+	ClassDB::bind_method(D_METHOD("get_slot_index"), &SpineSkinEntry::get_slot_index);
+	ClassDB::bind_method(D_METHOD("get_name"), &SpineSkinEntry::get_name);
+	ClassDB::bind_method(D_METHOD("get_attachment"), &SpineSkinEntry::get_attachment);
+}
+
+SpineSkinEntry::SpineSkinEntry() : slot_index(0) {
+}
+
+uint64_t SpineSkinEntry::get_slot_index() {
+	return slot_index;
+}
+
+const String &SpineSkinEntry::get_name() {
+	return name;
+}
+
+Ref<SpineAttachment> SpineSkinEntry::get_attachment() {
+	return attachment;
+}

+ 29 - 2
spine-godot/spine_godot/SpineSkin.h

@@ -31,7 +31,6 @@
 #define GODOT_SPINESKIN_H
 
 #include "SpineAttachment.h"
-#include "SpineSkinAttachmentMapEntries.h"
 
 class SpineSkin : public Reference {
 	GDCLASS(SpineSkin, Reference);
@@ -68,11 +67,39 @@ public:
 
 	void copy_skin(Ref<SpineSkin> other);
 
-	Ref<SpineSkinAttachmentMapEntries> get_attachments();
+	Array get_attachments();
 
 	Array get_bones();
 
 	Array get_constraints();
 };
 
+class SpineSkinEntry : public Reference {
+GDCLASS(SpineSkinEntry, Reference);
+
+	friend class SpineSkin;
+
+protected:
+	static void _bind_methods();
+
+	void init(uint64_t slot_index, const String &name, Ref<SpineAttachment> attachment) {
+		this->slot_index = slot_index;
+		this->name = name;
+		this->attachment = attachment;
+	}
+private:
+	uint64_t slot_index;
+	String name;
+	Ref<SpineAttachment> attachment;
+
+public:
+	SpineSkinEntry();
+
+	uint64_t get_slot_index();
+
+	const String &get_name();
+
+	Ref<SpineAttachment> get_attachment();
+};
+
 #endif//GODOT_SPINESKIN_H

+ 0 - 93
spine-godot/spine_godot/SpineSkinAttachmentMapEntries.cpp

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

+ 0 - 93
spine-godot/spine_godot/SpineSkinAttachmentMapEntries.h

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

+ 1 - 3
spine-godot/spine_godot/register_types.cpp

@@ -41,7 +41,6 @@
 #include "SpineBoneData.h"
 #include "SpineSlotData.h"
 #include "SpineAttachment.h"
-#include "SpineSkinAttachmentMapEntries.h"
 #include "SpineConstraintData.h"
 #include "SpineSkin.h"
 #include "SpineIkConstraintData.h"
@@ -88,8 +87,7 @@ void register_spine_godot_types() {
 	ClassDB::register_class<SpineBoneData>();
 	ClassDB::register_class<SpineSlotData>();
 	ClassDB::register_class<SpineAttachment>();
-	ClassDB::register_class<SpineSkinAttachmentMapEntry>();
-	ClassDB::register_class<SpineSkinAttachmentMapEntries>();
+	ClassDB::register_class<SpineSkinEntry>();
 	ClassDB::register_class<SpineConstraintData>();
 	ClassDB::register_class<SpineSkin>();
 	ClassDB::register_class<SpineIkConstraintData>();