소스 검색

[godot] Clean-up SpineTrackEntry.

Mario Zechner 3 년 전
부모
커밋
0118871bd2

+ 4 - 4
spine-godot/spine_godot/SpineConstant.cpp

@@ -76,8 +76,8 @@ void SpineConstant::_bind_methods() {
 	BIND_ENUM_CONSTANT(RotateMode_Chain)
 	BIND_ENUM_CONSTANT(RotateMode_ChainScale)
 
-	BIND_ENUM_CONSTANT(BLENDMODE_NORMAL)
-	BIND_ENUM_CONSTANT(BLENDMODE_ADDITIVE)
-	BIND_ENUM_CONSTANT(BLENDMODE_MULTIPLY)
-	BIND_ENUM_CONSTANT(BLENDMODE_SCREEN)
+	BIND_ENUM_CONSTANT(BlendMode_Normal)
+	BIND_ENUM_CONSTANT(BlendMode_Additive)
+	BIND_ENUM_CONSTANT(BlendMode_Multiply)
+	BIND_ENUM_CONSTANT(BlendMode_Screen)
 }

+ 12 - 12
spine-godot/spine_godot/SpineConstant.h

@@ -100,20 +100,20 @@ public:
 	};
 
 	enum BlendMode {
-		BLENDMODE_NORMAL = 0,
-		BLENDMODE_ADDITIVE,
-		BLENDMODE_MULTIPLY,
-		BLENDMODE_SCREEN
+		BlendMode_Normal = 0,
+		BlendMode_Additive,
+		BlendMode_Multiply,
+		BlendMode_Screen
 	};
 };
 
-VARIANT_ENUM_CAST(SpineConstant::MixBlend);
-VARIANT_ENUM_CAST(SpineConstant::MixDirection);
-VARIANT_ENUM_CAST(SpineConstant::PropertyId);
-VARIANT_ENUM_CAST(SpineConstant::TransformMode);
-VARIANT_ENUM_CAST(SpineConstant::PositionMode);
-VARIANT_ENUM_CAST(SpineConstant::SpacingMode);
-VARIANT_ENUM_CAST(SpineConstant::RotateMode);
-VARIANT_ENUM_CAST(SpineConstant::BlendMode);
+VARIANT_ENUM_CAST(SpineConstant::MixBlend)
+VARIANT_ENUM_CAST(SpineConstant::MixDirection)
+VARIANT_ENUM_CAST(SpineConstant::PropertyId)
+VARIANT_ENUM_CAST(SpineConstant::TransformMode)
+VARIANT_ENUM_CAST(SpineConstant::PositionMode)
+VARIANT_ENUM_CAST(SpineConstant::SpacingMode)
+VARIANT_ENUM_CAST(SpineConstant::RotateMode)
+VARIANT_ENUM_CAST(SpineConstant::BlendMode)
 
 #endif//GODOT_SPINECONSTANT_H

+ 1 - 1
spine-godot/spine_godot/SpineSlotData.cpp

@@ -112,7 +112,7 @@ void SpineSlotData::set_attachment_name(const String &v) {
 }
 
 SpineConstant::BlendMode SpineSlotData::get_blend_mode() {
-	SPINE_CHECK(slot_data, SpineConstant::BLENDMODE_NORMAL)
+	SPINE_CHECK(slot_data, SpineConstant::BlendMode_Normal)
 	return (SpineConstant::BlendMode)slot_data->getBlendMode();
 }
 void SpineSlotData::set_blend_mode(SpineConstant::BlendMode v) {

+ 128 - 61
spine-godot/spine_godot/SpineTrackEntry.cpp

@@ -28,238 +28,305 @@
  *****************************************************************************/
 
 #include "SpineTrackEntry.h"
+#include "SpineCommon.h"
 
 void SpineTrackEntry::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("get_track_index"), &SpineTrackEntry::get_track_index);
-
 	ClassDB::bind_method(D_METHOD("get_animation"), &SpineTrackEntry::get_animation);
-
+	ClassDB::bind_method(D_METHOD("get_previous"), &SpineTrackEntry::get_previous);
 	ClassDB::bind_method(D_METHOD("get_loop"), &SpineTrackEntry::get_loop);
 	ClassDB::bind_method(D_METHOD("set_loop", "v"), &SpineTrackEntry::set_loop);
-
 	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_shortest_rotation"), &SpineTrackEntry::get_shortest_rotation);
+	ClassDB::bind_method(D_METHOD("set_shortest_rotation", "v"), &SpineTrackEntry::set_shortest_rotation);
 	ClassDB::bind_method(D_METHOD("get_delay"), &SpineTrackEntry::get_delay);
 	ClassDB::bind_method(D_METHOD("set_delay", "v"), &SpineTrackEntry::set_delay);
-
 	ClassDB::bind_method(D_METHOD("get_track_time"), &SpineTrackEntry::get_track_time);
 	ClassDB::bind_method(D_METHOD("set_track_time", "v"), &SpineTrackEntry::set_track_time);
-
 	ClassDB::bind_method(D_METHOD("get_track_end"), &SpineTrackEntry::get_track_end);
 	ClassDB::bind_method(D_METHOD("set_track_end", "v"), &SpineTrackEntry::set_track_end);
-
 	ClassDB::bind_method(D_METHOD("get_animation_start"), &SpineTrackEntry::get_animation_start);
 	ClassDB::bind_method(D_METHOD("set_animation_start", "v"), &SpineTrackEntry::set_animation_start);
-
+	ClassDB::bind_method(D_METHOD("get_animation_end"), &SpineTrackEntry::get_animation_end);
+	ClassDB::bind_method(D_METHOD("set_animation_end", "v"), &SpineTrackEntry::set_animation_end);
 	ClassDB::bind_method(D_METHOD("get_animation_last"), &SpineTrackEntry::get_animation_last);
 	ClassDB::bind_method(D_METHOD("set_animation_last", "v"), &SpineTrackEntry::set_animation_last);
-
 	ClassDB::bind_method(D_METHOD("get_animation_time"), &SpineTrackEntry::get_animation_time);
-
 	ClassDB::bind_method(D_METHOD("get_time_scale"), &SpineTrackEntry::get_time_scale);
 	ClassDB::bind_method(D_METHOD("set_time_scale", "v"), &SpineTrackEntry::set_time_scale);
-
 	ClassDB::bind_method(D_METHOD("get_alpha"), &SpineTrackEntry::get_alpha);
 	ClassDB::bind_method(D_METHOD("set_alpha", "v"), &SpineTrackEntry::set_alpha);
-
 	ClassDB::bind_method(D_METHOD("get_event_threshold"), &SpineTrackEntry::get_event_threshold);
 	ClassDB::bind_method(D_METHOD("set_event_threshold", "v"), &SpineTrackEntry::set_event_threshold);
-
 	ClassDB::bind_method(D_METHOD("get_attachment_threshold"), &SpineTrackEntry::get_attachment_threshold);
 	ClassDB::bind_method(D_METHOD("set_attachment_threshold", "v"), &SpineTrackEntry::set_attachment_threshold);
-
 	ClassDB::bind_method(D_METHOD("get_draw_order_threshold"), &SpineTrackEntry::get_draw_order_threshold);
 	ClassDB::bind_method(D_METHOD("set_draw_order_threshold", "v"), &SpineTrackEntry::set_draw_order_threshold);
-
 	ClassDB::bind_method(D_METHOD("get_next"), &SpineTrackEntry::get_next);
-
 	ClassDB::bind_method(D_METHOD("is_complete"), &SpineTrackEntry::is_complete);
-
 	ClassDB::bind_method(D_METHOD("get_mix_time"), &SpineTrackEntry::get_mix_time);
 	ClassDB::bind_method(D_METHOD("set_mix_time", "v"), &SpineTrackEntry::set_mix_time);
-
 	ClassDB::bind_method(D_METHOD("get_mix_duration"), &SpineTrackEntry::get_mix_duration);
 	ClassDB::bind_method(D_METHOD("set_mix_duration", "v"), &SpineTrackEntry::set_mix_duration);
-
 	ClassDB::bind_method(D_METHOD("get_mix_blend"), &SpineTrackEntry::get_mix_blend);
 	ClassDB::bind_method(D_METHOD("set_mix_blend", "v"), &SpineTrackEntry::set_mix_blend);
-
 	ClassDB::bind_method(D_METHOD("get_mixing_from"), &SpineTrackEntry::get_mixing_from);
 	ClassDB::bind_method(D_METHOD("get_mixing_to"), &SpineTrackEntry::get_mixing_to);
-
 	ClassDB::bind_method(D_METHOD("reset_rotation_directions"), &SpineTrackEntry::reset_rotation_directions);
-
-	BIND_ENUM_CONSTANT(MIXBLEND_SETUP);
-	BIND_ENUM_CONSTANT(MIXBLEND_FIRST);
-	BIND_ENUM_CONSTANT(MIXBLEND_REPLACE);
-	BIND_ENUM_CONSTANT(MIXBLEND_ADD);
+	ClassDB::bind_method(D_METHOD("get_track_complete"), &SpineTrackEntry::get_track_complete);
 }
 
-SpineTrackEntry::SpineTrackEntry() : track_entry(NULL) {}
-SpineTrackEntry::~SpineTrackEntry() {}
+SpineTrackEntry::SpineTrackEntry() : track_entry(nullptr) {
+}
 
 int SpineTrackEntry::get_track_index() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getTrackIndex();
 }
 
 Ref<SpineAnimation> SpineTrackEntry::get_animation() {
-	Ref<SpineAnimation> gd_anim(memnew(SpineAnimation));
-	auto anim = track_entry->getAnimation();
-	if (anim == NULL) return NULL;
-	gd_anim->set_spine_object(anim);
-	return gd_anim;
+	SPINE_CHECK(track_entry, nullptr)
+	auto animation = track_entry->getAnimation();
+	if (!animation) return nullptr;
+	Ref<SpineAnimation> animation_ref(memnew(SpineAnimation));
+	animation_ref->set_spine_object(animation);
+	return animation_ref;
+}
+
+Ref<SpineTrackEntry> SpineTrackEntry::get_previous() {
+	SPINE_CHECK(track_entry, nullptr)
+	auto previous = track_entry->getPrevious();
+	if (!previous) return nullptr;
+	Ref<SpineTrackEntry> previous_ref(memnew(SpineTrackEntry));
+	previous_ref->set_spine_object(previous);
+	return previous_ref;
 }
 
 bool SpineTrackEntry::get_loop() {
+	SPINE_CHECK(track_entry, false)
 	return track_entry->getLoop();
 }
+
 void SpineTrackEntry::set_loop(bool v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setLoop(v);
 }
 
 bool SpineTrackEntry::get_hold_previous() {
+	SPINE_CHECK(track_entry, false)
 	return track_entry->getHoldPrevious();
 }
+
 void SpineTrackEntry::set_hold_previous(bool v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setHoldPrevious(v);
 }
 
+bool SpineTrackEntry::get_reverse() {
+	SPINE_CHECK(track_entry, false)
+	return track_entry->getReverse();
+}
+
+void SpineTrackEntry::set_reverse(bool v) {
+	SPINE_CHECK(track_entry,)
+	track_entry->setReverse(v);
+}
+
+bool  SpineTrackEntry::get_shortest_rotation() {
+	SPINE_CHECK(track_entry, false)
+	return track_entry->getShortestRotation();
+}
+
+void  SpineTrackEntry::set_shortest_rotation(bool v) {
+	SPINE_CHECK(track_entry,)
+	track_entry->setShortestRotation(v);
+}
+
 float SpineTrackEntry::get_delay() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getDelay();
 }
+
 void SpineTrackEntry::set_delay(float v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setDelay(v);
 }
 
 float SpineTrackEntry::get_track_time() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getTrackTime();
 }
+
 void SpineTrackEntry::set_track_time(float v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setTrackTime(v);
 }
 
 float SpineTrackEntry::get_track_end() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getTrackEnd();
 }
+
 void SpineTrackEntry::set_track_end(float v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setTrackEnd(v);
 }
 
 float SpineTrackEntry::get_animation_start() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getAnimationStart();
 }
+
 void SpineTrackEntry::set_animation_start(float v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setAnimationStart(v);
 }
 
+float SpineTrackEntry::get_animation_end() {
+	SPINE_CHECK(track_entry, 0)
+	return track_entry->getAnimationEnd();
+}
+
+void SpineTrackEntry::set_animation_end(float v) {
+	SPINE_CHECK(track_entry,)
+	track_entry->setAnimationEnd(v);
+}
+
 float SpineTrackEntry::get_animation_last() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getAnimationLast();
 }
+
 void SpineTrackEntry::set_animation_last(float v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setAnimationLast(v);
 }
 
 float SpineTrackEntry::get_animation_time() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getAnimationTime();
 }
 
 float SpineTrackEntry::get_time_scale() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getTimeScale();
 }
+
 void SpineTrackEntry::set_time_scale(float v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setTimeScale(v);
 }
 
 float SpineTrackEntry::get_alpha() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getAlpha();
 }
+
 void SpineTrackEntry::set_alpha(float v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setAlpha(v);
 }
 
 float SpineTrackEntry::get_event_threshold() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getEventThreshold();
 }
+
 void SpineTrackEntry::set_event_threshold(float v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setEventThreshold(v);
 }
 
 float SpineTrackEntry::get_attachment_threshold() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getAttachmentThreshold();
 }
+
 void SpineTrackEntry::set_attachment_threshold(float v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setAttachmentThreshold(v);
 }
 
 float SpineTrackEntry::get_draw_order_threshold() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getDrawOrderThreshold();
 }
+
 void SpineTrackEntry::set_draw_order_threshold(float v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setDrawOrderThreshold(v);
 }
 
 Ref<SpineTrackEntry> SpineTrackEntry::get_next() {
-	Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry));
-	auto entry = track_entry->getNext();
-	if (entry == NULL) return NULL;
-	gd_entry->set_spine_object(entry);
-	return gd_entry;
+	SPINE_CHECK(track_entry, nullptr)
+	auto next = track_entry->getNext();
+	if (!next) return nullptr;
+	Ref<SpineTrackEntry> next_ref(memnew(SpineTrackEntry));
+	next_ref->set_spine_object(next);
+	return next_ref;
 }
 
 bool SpineTrackEntry::is_complete() {
+	SPINE_CHECK(track_entry, false)
 	return track_entry->isComplete();
 }
 
 float SpineTrackEntry::get_mix_time() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getMixTime();
 }
+
 void SpineTrackEntry::set_mix_time(float v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setMixTime(v);
 }
 
 float SpineTrackEntry::get_mix_duration() {
+	SPINE_CHECK(track_entry, 0)
 	return track_entry->getMixDuration();
 }
+
 void SpineTrackEntry::set_mix_duration(float v) {
+	SPINE_CHECK(track_entry,)
 	track_entry->setMixDuration(v);
 }
 
-SpineTrackEntry::MixBlend SpineTrackEntry::get_mix_blend() {
-	int mb = track_entry->getMixBlend();
-	return (MixBlend) mb;
+SpineConstant::MixBlend SpineTrackEntry::get_mix_blend() {
+	SPINE_CHECK(track_entry, SpineConstant::MixBlend_Setup)
+	return (SpineConstant::MixBlend)track_entry->getMixBlend();
 }
-void SpineTrackEntry::set_mix_blend(SpineTrackEntry::MixBlend v) {
-	int mb = (int) v;
-	track_entry->setMixBlend((spine::MixBlend) mb);
+
+void SpineTrackEntry::set_mix_blend(SpineConstant::MixBlend v) {
+	SPINE_CHECK(track_entry,)
+	track_entry->setMixBlend((spine::MixBlend) v);
 }
 
 Ref<SpineTrackEntry> SpineTrackEntry::get_mixing_from() {
-	Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry));
-	auto entry = track_entry->getMixingFrom();
-	if (entry == NULL) return NULL;
-	gd_entry->set_spine_object(entry);
-	return gd_entry;
+	SPINE_CHECK(track_entry, nullptr)
+	auto mixing_from = track_entry->getMixingFrom();
+	if (!mixing_from) return nullptr;
+	Ref<SpineTrackEntry> mixing_from_ref(memnew(SpineTrackEntry));
+	mixing_from_ref->set_spine_object(mixing_from);
+	return mixing_from_ref;
 }
 Ref<SpineTrackEntry> SpineTrackEntry::get_mixing_to() {
-	Ref<SpineTrackEntry> gd_entry(memnew(SpineTrackEntry));
-	auto entry = track_entry->getMixingTo();
-	if (entry == NULL) return NULL;
-	gd_entry->set_spine_object(entry);
-	return gd_entry;
+	SPINE_CHECK(track_entry, nullptr)
+	auto mixing_to = track_entry->getMixingTo();
+	if (!mixing_to) return nullptr;
+	Ref<SpineTrackEntry> mixing_to_ref(memnew(SpineTrackEntry));
+	mixing_to_ref->set_spine_object(mixing_to);
+	return mixing_to_ref;
 }
 
 void SpineTrackEntry::reset_rotation_directions() {
+	SPINE_CHECK(track_entry,)
 	track_entry->resetRotationDirections();
 }
 
-bool SpineTrackEntry::get_reverse() {
-	return track_entry->getReverse();
-}
-
-void SpineTrackEntry::set_reverse(bool v) {
-	track_entry->setReverse(v);
+float SpineTrackEntry::get_track_complete() {
+	SPINE_CHECK(track_entry, 0)
+	return track_entry->getTrackComplete();
 }

+ 36 - 22
spine-godot/spine_godot/SpineTrackEntry.h

@@ -30,11 +30,9 @@
 #ifndef GODOT_SPINETRACKENTRY_H
 #define GODOT_SPINETRACKENTRY_H
 
-#include "core/variant_parser.h"
-
-#include <spine/spine.h>
-
 #include "SpineAnimation.h"
+#include "SpineConstant.h"
+#include <spine/AnimationState.h>
 
 class SpineTrackEntry : public Reference {
 	GDCLASS(SpineTrackEntry, Reference);
@@ -47,65 +45,76 @@ private:
 
 public:
 	SpineTrackEntry();
-	~SpineTrackEntry();
-
-	inline void set_spine_object(spine::TrackEntry *t) {
-		track_entry = t;
-	}
-	inline spine::TrackEntry *get_spine_object() {
-		return track_entry;
-	}
-
-	enum MixBlend {
-		MIXBLEND_SETUP = 0,
-		MIXBLEND_FIRST,
-		MIXBLEND_REPLACE,
-		MIXBLEND_ADD
-	};
+
+	void set_spine_object(spine::TrackEntry *_track_entry) { this->track_entry = _track_entry; }
+	spine::TrackEntry *get_spine_object() { return track_entry; }
 
 	int get_track_index();
 
 	Ref<SpineAnimation> get_animation();
 
+	Ref<SpineTrackEntry> get_previous();
+
 	bool get_loop();
+
 	void set_loop(bool v);
 
 	bool get_hold_previous();
+
 	void set_hold_previous(bool v);
 
 	bool get_reverse();
+
 	void set_reverse(bool v);
 
+	bool get_shortest_rotation();
+
+	void set_shortest_rotation(bool v);
+
 	float get_delay();
+
 	void set_delay(float v);
 
 	float get_track_time();
+
 	void set_track_time(float v);
 
 	float get_track_end();
+
 	void set_track_end(float v);
 
 	float get_animation_start();
+
 	void set_animation_start(float v);
 
+	float get_animation_end();
+
+	void set_animation_end(float v);
+
 	float get_animation_last();
+
 	void set_animation_last(float v);
 
 	float get_animation_time();
 
 	float get_time_scale();
+
 	void set_time_scale(float v);
 
 	float get_alpha();
+
 	void set_alpha(float v);
 
 	float get_event_threshold();
+
 	void set_event_threshold(float v);
 
 	float get_attachment_threshold();
+
 	void set_attachment_threshold(float v);
 
 	float get_draw_order_threshold();
+
 	void set_draw_order_threshold(float v);
 
 	Ref<SpineTrackEntry> get_next();
@@ -113,19 +122,24 @@ public:
 	bool is_complete();
 
 	float get_mix_time();
+
 	void set_mix_time(float v);
 
 	float get_mix_duration();
+
 	void set_mix_duration(float v);
 
-	MixBlend get_mix_blend();
-	void set_mix_blend(MixBlend v);
+	SpineConstant::MixBlend get_mix_blend();
+
+	void set_mix_blend(SpineConstant::MixBlend v);
 
 	Ref<SpineTrackEntry> get_mixing_from();
+
 	Ref<SpineTrackEntry> get_mixing_to();
 
 	void reset_rotation_directions();
+
+	float get_track_complete();
 };
 
-VARIANT_ENUM_CAST(SpineTrackEntry::MixBlend);
 #endif//GODOT_SPINETRACKENTRY_H