ソースを参照

[godot] Clean-up SpineAttachment, perform checks on native object.

badlogic 3 年 前
コミット
d62ef56066

+ 13 - 11
spine-godot/spine_godot/SpineAttachment.cpp

@@ -28,28 +28,30 @@
  *****************************************************************************/
 
 #include "SpineAttachment.h"
+#include "common.h"
 
 void SpineAttachment::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_attachment_name"), &SpineAttachment::get_attachment_name);
 	ClassDB::bind_method(D_METHOD("copy"), &SpineAttachment::copy);
 }
 
-SpineAttachment::SpineAttachment() : attachment(NULL) {}
+SpineAttachment::SpineAttachment() : attachment(nullptr) {
+}
+
 SpineAttachment::~SpineAttachment() {
-	if (attachment) {
-		attachment->dereference();
-		attachment = NULL;
-	}
+	if (attachment) attachment->dereference();
 }
 
 String SpineAttachment::get_attachment_name() {
+	SPINE_CHECK(attachment, "")
 	return attachment->getName().buffer();
 }
 
 Ref<SpineAttachment> SpineAttachment::copy() {
-	auto a = attachment->copy();
-	if (a == NULL) return NULL;
-	Ref<SpineAttachment> gd_attachment(memnew(SpineAttachment));
-	gd_attachment->set_spine_object(a);
-	return gd_attachment;
-}
+	SPINE_CHECK(attachment, nullptr)
+	auto copy = attachment->copy();
+	if (!copy) return nullptr;
+	Ref<SpineAttachment> attachment_ref(memnew(SpineAttachment));
+	attachment_ref->set_spine_object(copy);
+	return attachment_ref;
+}

+ 7 - 8
spine-godot/spine_godot/SpineAttachment.h

@@ -30,12 +30,11 @@
 #ifndef GODOT_SPINEATTACHMENT_H
 #define GODOT_SPINEATTACHMENT_H
 
-#include "core/variant_parser.h"
-
 #include <spine/spine.h>
+#include "core/reference.h"
 
 class SpineAttachment : public Reference {
-	GDCLASS(SpineAttachment, Reference);
+	GDCLASS(SpineAttachment, Reference)
 
 protected:
 	static void _bind_methods();
@@ -47,12 +46,12 @@ public:
 	SpineAttachment();
 	~SpineAttachment();
 
-	inline void set_spine_object(spine::Attachment *a) {
-		attachment = a;
-		if (attachment)
-			attachment->reference();
+	void set_spine_object(spine::Attachment *_attachment) {
+		attachment = _attachment;
+		if (attachment) attachment->reference();
 	}
-	inline spine::Attachment *get_spine_object() {
+
+	spine::Attachment *get_spine_object() {
 		return attachment;
 	}