mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[godot] Clean-up SpineAnimation, add simple unit test scene and script.
This commit is contained in:
parent
dd163d9a81
commit
773173d589
15
spine-godot/example/tests/unit-tests.gd
Normal file
15
spine-godot/example/tests/unit-tests.gd
Normal file
@ -0,0 +1,15 @@
|
||||
extends SpineSprite
|
||||
|
||||
func _ready():
|
||||
|
||||
# Test SpineAnimation
|
||||
var walkAnim: SpineAnimation = get_skeleton().get_data().find_animation("walk")
|
||||
assert(walkAnim.get_name() == "walk")
|
||||
var duration = walkAnim.get_duration()
|
||||
walkAnim.set_duration(duration + 1)
|
||||
assert(walkAnim.get_duration() == duration + 1)
|
||||
assert(walkAnim.get_timelines().size() == 39)
|
||||
var timeline: SpineTimeline = walkAnim.get_timelines()[0]
|
||||
var propertyIds = timeline.getPropertyIds()
|
||||
assert(walkAnim.has_timeline(propertyIds))
|
||||
assert(!walkAnim.has_timeline([0]))
|
||||
350
spine-godot/example/tests/unit-tests.tscn
Normal file
350
spine-godot/example/tests/unit-tests.tscn
Normal file
@ -0,0 +1,350 @@
|
||||
[gd_scene load_steps=56 format=2]
|
||||
|
||||
[ext_resource path="res://tests/unit-tests.gd" type="Script" id=1]
|
||||
[ext_resource path="res://spineboy/spineboy-data.tres" type="SpineSkeletonDataResource" id=2]
|
||||
|
||||
[sub_resource type="SpineAnimationStateDataResource" id=1]
|
||||
skeleton = ExtResource( 2 )
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=2]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=3]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=4]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=5]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=6]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=7]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=8]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=9]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=10]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=11]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=12]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=13]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=14]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=15]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=16]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=17]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=18]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=19]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=20]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=21]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=22]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=23]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=24]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=25]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=26]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=27]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=28]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=29]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=30]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=31]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=32]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=33]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=34]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=35]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=36]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=37]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=38]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=39]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=40]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=41]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=42]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=43]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=44]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=45]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=46]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=47]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=48]
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=49]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=50]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=51]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=52]
|
||||
blend_mode = 1
|
||||
|
||||
[sub_resource type="CanvasItemMaterial" id=53]
|
||||
blend_mode = 1
|
||||
|
||||
[node name="SpineSprite" type="SpineSprite"]
|
||||
position = Vector2( 496.659, 431.634 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
animation_state_data_res = SubResource( 1 )
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="portal-bg" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 2 )
|
||||
|
||||
[node name="portal-shade" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 3 )
|
||||
|
||||
[node name="portal-streaks2" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 4 )
|
||||
|
||||
[node name="portal-streaks1" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 5 )
|
||||
|
||||
[node name="portal-flare8" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 6 )
|
||||
|
||||
[node name="portal-flare9" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 7 )
|
||||
|
||||
[node name="portal-flare10" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 8 )
|
||||
|
||||
[node name="clipping" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 9 )
|
||||
|
||||
[node name="exhaust3" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 10 )
|
||||
|
||||
[node name="hoverboard-thruster-rear" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 11 )
|
||||
|
||||
[node name="hoverboard-thruster-front" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 12 )
|
||||
|
||||
[node name="hoverboard-board" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 13 )
|
||||
|
||||
[node name="side-glow1" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 14 )
|
||||
|
||||
[node name="side-glow3" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 15 )
|
||||
|
||||
[node name="side-glow2" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 16 )
|
||||
|
||||
[node name="hoverglow-front" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 17 )
|
||||
|
||||
[node name="hoverglow-rear" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 18 )
|
||||
|
||||
[node name="exhaust1" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 19 )
|
||||
|
||||
[node name="exhaust2" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 20 )
|
||||
|
||||
[node name="rear-upper-arm" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 21 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="rear-bracer" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 22 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="gun" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 23 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="rear-foot" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 24 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="rear-thigh" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 25 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="rear-shin" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 26 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="neck" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 27 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="torso" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 28 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="front-upper-arm" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 29 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="head" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 30 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="eye" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 31 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="front-thigh" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 32 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="front-foot" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 33 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="front-shin" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 34 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="mouth" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 35 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="goggles" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 36 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="front-bracer" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 37 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="front-fist" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
material = SubResource( 38 )
|
||||
scale = Vector2( 0.7, 0.7 )
|
||||
|
||||
[node name="muzzle" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 39 )
|
||||
|
||||
[node name="head-bb" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 40 )
|
||||
|
||||
[node name="portal-flare1" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 41 )
|
||||
|
||||
[node name="portal-flare2" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 42 )
|
||||
|
||||
[node name="portal-flare3" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 43 )
|
||||
|
||||
[node name="portal-flare4" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 44 )
|
||||
|
||||
[node name="portal-flare5" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 45 )
|
||||
|
||||
[node name="portal-flare6" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 46 )
|
||||
|
||||
[node name="portal-flare7" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 47 )
|
||||
|
||||
[node name="crosshair" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 48 )
|
||||
|
||||
[node name="muzzle-glow" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 49 )
|
||||
|
||||
[node name="muzzle-ring" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 50 )
|
||||
|
||||
[node name="muzzle-ring2" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 51 )
|
||||
|
||||
[node name="muzzle-ring3" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 52 )
|
||||
|
||||
[node name="muzzle-ring4" type="SpineSpriteMeshInstance2D" parent="."]
|
||||
visible = false
|
||||
material = SubResource( 53 )
|
||||
@ -28,36 +28,38 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "SpineAnimation.h"
|
||||
|
||||
#include "SpineSkeleton.h"
|
||||
#include "SpineEvent.h"
|
||||
#include "SpineTimeline.h"
|
||||
|
||||
// enable more than 5 arguments of a method bind function
|
||||
#include "core/method_bind_ext.gen.inc"
|
||||
|
||||
void SpineAnimation::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_anim_name"), &SpineAnimation::get_anim_name);
|
||||
ClassDB::bind_method(D_METHOD("get_name"), &SpineAnimation::get_name);
|
||||
ClassDB::bind_method(D_METHOD("get_duration"), &SpineAnimation::get_duration);
|
||||
ClassDB::bind_method(D_METHOD("set_duration", "v"), &SpineAnimation::set_duration);
|
||||
ClassDB::bind_method(D_METHOD("set_duration", "duration"), &SpineAnimation::set_duration);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("apply", "skeleton", "last_time", "time", "loop", "events", "alpha", "blend", "direction"), &SpineAnimation::apply);
|
||||
ClassDB::bind_method(D_METHOD("get_timelines"), &SpineAnimation::get_timelines);
|
||||
ClassDB::bind_method(D_METHOD("has_timeline", "ids"), &SpineAnimation::has_timeline);
|
||||
}
|
||||
|
||||
SpineAnimation::SpineAnimation() : animation(NULL) {}
|
||||
SpineAnimation::~SpineAnimation() {}
|
||||
SpineAnimation::SpineAnimation() : animation(NULL) {
|
||||
}
|
||||
|
||||
String SpineAnimation::get_anim_name() {
|
||||
SpineAnimation::~SpineAnimation() {
|
||||
}
|
||||
|
||||
String SpineAnimation::get_name() {
|
||||
return animation->getName().buffer();
|
||||
}
|
||||
|
||||
float SpineAnimation::get_duration() {
|
||||
return animation->getDuration();
|
||||
}
|
||||
void SpineAnimation::set_duration(float v) {
|
||||
animation->setDuration(v);
|
||||
|
||||
void SpineAnimation::set_duration(float duration) {
|
||||
animation->setDuration(duration);
|
||||
}
|
||||
|
||||
void SpineAnimation::apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, bool loop,
|
||||
@ -73,24 +75,24 @@ void SpineAnimation::apply(Ref<SpineSkeleton> skeleton, float lastTime, float ti
|
||||
|
||||
Array SpineAnimation::get_timelines() {
|
||||
auto &timelines = animation->getTimelines();
|
||||
Array res;
|
||||
res.resize(timelines.size());
|
||||
Array result;
|
||||
result.resize(timelines.size());
|
||||
|
||||
for (size_t i = 0; i < res.size(); ++i) {
|
||||
auto a = Ref<SpineTimeline>(memnew(SpineTimeline));
|
||||
a->set_spine_object(timelines[i]);
|
||||
res.set(i, a);
|
||||
for (size_t i = 0; i < result.size(); ++i) {
|
||||
auto timeline = Ref<SpineTimeline>(memnew(SpineTimeline));
|
||||
timeline->set_spine_object(timelines[i]);
|
||||
result.set(i, timeline);
|
||||
}
|
||||
|
||||
return res;
|
||||
return result;
|
||||
}
|
||||
|
||||
bool SpineAnimation::has_timeline(Array ids) {
|
||||
spine::Vector<spine::PropertyId> list;
|
||||
list.setSize(ids.size(), 0);
|
||||
spine::Vector<spine::PropertyId> propertyIds;
|
||||
propertyIds.setSize(ids.size(), 0);
|
||||
|
||||
for (size_t i = 0; i < list.size(); ++i) {
|
||||
list[i] = (int64_t) ids[i];
|
||||
for (size_t i = 0; i < propertyIds.size(); ++i) {
|
||||
propertyIds[i] = (int64_t) ids[i];
|
||||
}
|
||||
return animation->hasTimeline(list);
|
||||
return animation->hasTimeline(propertyIds);
|
||||
}
|
||||
|
||||
@ -30,8 +30,6 @@
|
||||
#ifndef GODOT_SPINEANIMATION_H
|
||||
#define GODOT_SPINEANIMATION_H
|
||||
|
||||
#include "core/variant_parser.h"
|
||||
|
||||
#include "SpineConstant.h"
|
||||
|
||||
#include <spine/spine.h>
|
||||
@ -53,8 +51,8 @@ public:
|
||||
SpineAnimation();
|
||||
~SpineAnimation();
|
||||
|
||||
inline void set_spine_object(spine::Animation *a) {
|
||||
animation = a;
|
||||
inline void set_spine_object(spine::Animation *animation) {
|
||||
this->animation = animation;
|
||||
}
|
||||
inline spine::Animation *get_spine_object() {
|
||||
return animation;
|
||||
@ -64,11 +62,14 @@ public:
|
||||
void apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, bool loop, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction);
|
||||
|
||||
Array get_timelines(); // Vector<Ref<SpineTimeline>>
|
||||
|
||||
bool has_timeline(Array ids);// Vector<SpineConstant::PropertyId>
|
||||
|
||||
String get_anim_name();
|
||||
String get_name();
|
||||
|
||||
float get_duration();
|
||||
void set_duration(float v);
|
||||
|
||||
void set_duration(float duration);
|
||||
};
|
||||
|
||||
#endif//GODOT_SPINEANIMATION_H
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user