mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-14 02:58:44 +08:00
[godot] More clean-up.
This commit is contained in:
parent
cea5adfe1b
commit
25e55b4009
@ -63,14 +63,14 @@ void SpineAnimation::set_duration(float duration) {
|
||||
}
|
||||
|
||||
void SpineAnimation::apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, bool loop,
|
||||
Array pEvents, float alpha, SpineConstant::MixBlend blend,
|
||||
SpineConstant::MixDirection direction) {
|
||||
spine::Vector<spine::Event *> events;
|
||||
events.setSize(pEvents.size(), nullptr);
|
||||
Array events, float alpha, SpineConstant::MixBlend blend,
|
||||
SpineConstant::MixDirection direction) {
|
||||
spine::Vector<spine::Event *> spineEvents;
|
||||
spineEvents.setSize(events.size(), nullptr);
|
||||
for (size_t i = 0; i < events.size(); ++i) {
|
||||
events[i] = ((Ref<SpineEvent>) (pEvents[i]))->get_spine_object();
|
||||
spineEvents[i] = ((Ref<SpineEvent>) (events[i]))->get_spine_object();
|
||||
}
|
||||
animation->apply(*(skeleton->get_spine_object()), lastTime, time, loop, &events, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction);
|
||||
animation->apply(*(skeleton->get_spine_object()), lastTime, time, loop, &spineEvents, alpha, (spine::MixBlend) blend, (spine::MixDirection) direction);
|
||||
}
|
||||
|
||||
Array SpineAnimation::get_timelines() {
|
||||
@ -88,11 +88,11 @@ Array SpineAnimation::get_timelines() {
|
||||
}
|
||||
|
||||
bool SpineAnimation::has_timeline(Array ids) {
|
||||
spine::Vector<spine::PropertyId> propertyIds;
|
||||
propertyIds.setSize(ids.size(), 0);
|
||||
spine::Vector<spine::PropertyId> property_ids;
|
||||
property_ids.setSize(ids.size(), 0);
|
||||
|
||||
for (size_t i = 0; i < propertyIds.size(); ++i) {
|
||||
propertyIds[i] = (int64_t) ids[i];
|
||||
for (size_t i = 0; i < property_ids.size(); ++i) {
|
||||
property_ids[i] = (int64_t) ids[i];
|
||||
}
|
||||
return animation->hasTimeline(propertyIds);
|
||||
return animation->hasTimeline(property_ids);
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ public:
|
||||
inline void set_spine_object(spine::Animation *animation) { this->animation = animation; }
|
||||
inline spine::Animation *get_spine_object() { return animation; }
|
||||
|
||||
void apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, bool loop, Array pEvents, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction);
|
||||
void apply(Ref<SpineSkeleton> skeleton, float lastTime, float time, bool loop, Array events, float alpha, SpineConstant::MixBlend blend, SpineConstant::MixDirection direction);
|
||||
|
||||
Array get_timelines();
|
||||
|
||||
|
||||
@ -44,7 +44,6 @@ void SpineAnimationState::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &SpineAnimationState::set_time_scale);
|
||||
ClassDB::bind_method(D_METHOD("disable_queue"), &SpineAnimationState::disable_queue);
|
||||
ClassDB::bind_method(D_METHOD("enable_queue"), &SpineAnimationState::enable_queue);
|
||||
// ClassDB::bind_method(D_METHOD("reload"), &SpineAnimationState::reload_animation_state);
|
||||
ClassDB::bind_method(D_METHOD("get_current", "track_id"), &SpineAnimationState::get_current);
|
||||
}
|
||||
|
||||
@ -58,25 +57,13 @@ SpineAnimationState::~SpineAnimationState() {
|
||||
}
|
||||
}
|
||||
|
||||
void SpineAnimationState::load_animation_state(Ref<SpineAnimationStateDataResource> ad) {
|
||||
void SpineAnimationState::load_animation_state(Ref<SpineAnimationStateDataResource> animation_state_data) {
|
||||
if (animation_state) {
|
||||
delete animation_state;
|
||||
animation_state = NULL;
|
||||
}
|
||||
animation_state = new spine::AnimationState(ad->get_animation_state_data());
|
||||
anim_state_data_res = ad;
|
||||
}
|
||||
|
||||
void SpineAnimationState::reload_animation_state() {
|
||||
if (!anim_state_data_res.is_valid()) {
|
||||
ERR_PRINT(" Reload animation state fail, because anim_state_data_res not set!");
|
||||
return;
|
||||
}
|
||||
if (animation_state) {
|
||||
delete animation_state;
|
||||
animation_state = NULL;
|
||||
}
|
||||
animation_state = new spine::AnimationState(anim_state_data_res->get_animation_state_data());
|
||||
animation_state = new spine::AnimationState(animation_state_data->get_animation_state_data());
|
||||
anim_state_data_res = animation_state_data;
|
||||
}
|
||||
|
||||
#define CHECK_V \
|
||||
@ -164,9 +151,9 @@ float SpineAnimationState::get_time_scale() {
|
||||
CHECK_X(0);
|
||||
return animation_state->getTimeScale();
|
||||
}
|
||||
void SpineAnimationState::set_time_scale(float v) {
|
||||
void SpineAnimationState::set_time_scale(float time_scale) {
|
||||
CHECK_V;
|
||||
animation_state->setTimeScale(v);
|
||||
animation_state->setTimeScale(time_scale);
|
||||
}
|
||||
|
||||
void SpineAnimationState::disable_queue() {
|
||||
|
||||
@ -30,8 +30,6 @@
|
||||
#ifndef GODOT_SPINEANIMATIONSTATE_H
|
||||
#define GODOT_SPINEANIMATIONSTATE_H
|
||||
|
||||
#include "core/variant_parser.h"
|
||||
|
||||
#include "SpineAnimationStateDataResource.h"
|
||||
#include "SpineSkeleton.h"
|
||||
#include "SpineTrackEntry.h"
|
||||
@ -48,47 +46,40 @@ private:
|
||||
Ref<SpineAnimationStateDataResource> anim_state_data_res;
|
||||
|
||||
public:
|
||||
void load_animation_state(Ref<SpineAnimationStateDataResource> ad);
|
||||
SpineAnimationState();
|
||||
~SpineAnimationState();
|
||||
|
||||
inline void set_animation_state(spine::AnimationState *a) {
|
||||
animation_state = a;
|
||||
}
|
||||
inline spine::AnimationState *get_animation_state() {
|
||||
return animation_state;
|
||||
}
|
||||
void load_animation_state(Ref<SpineAnimationStateDataResource> animation_state_data);
|
||||
|
||||
void reload_animation_state();
|
||||
inline void set_spine_object(spine::AnimationState *animation_state) { this->animation_state = animation_state; }
|
||||
inline spine::AnimationState *get_spine_object() { return animation_state; }
|
||||
|
||||
Ref<SpineTrackEntry> set_animation(const String &anim_name, bool loop, uint64_t track_id);
|
||||
inline void set_animation_by_ref(Ref<SpineAnimation> anim, bool loop, uint64_t track_id) {
|
||||
if (anim.is_valid()) {
|
||||
animation_state->setAnimation(track_id, anim->get_spine_object(), loop);
|
||||
}
|
||||
}
|
||||
|
||||
Ref<SpineTrackEntry> add_animation(const String &anim_name, float delay, bool loop, uint64_t track_id);
|
||||
|
||||
Ref<SpineTrackEntry> set_empty_animation(uint64_t track_id, float mix_duration);
|
||||
|
||||
Ref<SpineTrackEntry> add_empty_animation(uint64_t track_id, float mix_duration, float delay);
|
||||
void set_empty_animations(float mix_duration);
|
||||
|
||||
Ref<SpineAnimationStateDataResource> get_data();
|
||||
|
||||
float get_time_scale();
|
||||
void set_time_scale(float v);
|
||||
void set_time_scale(float time_scale);
|
||||
|
||||
void disable_queue();
|
||||
void enable_queue();
|
||||
|
||||
void update(float delta);
|
||||
|
||||
bool apply(Ref<SpineSkeleton> skeleton);
|
||||
|
||||
void clear_tracks();
|
||||
|
||||
void clear_track(uint64_t track_id);
|
||||
|
||||
Ref<SpineTrackEntry> get_current(uint64_t track_index);
|
||||
|
||||
SpineAnimationState();
|
||||
~SpineAnimationState();
|
||||
};
|
||||
|
||||
#endif//GODOT_SPINEANIMATIONSTATE_H
|
||||
|
||||
@ -37,7 +37,7 @@ void SpineSprite::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_animation_state_data_res"), &SpineSprite::get_animation_state_data_res);
|
||||
ClassDB::bind_method(D_METHOD("_on_animation_data_created"), &SpineSprite::_on_animation_data_created);
|
||||
ClassDB::bind_method(D_METHOD("get_skeleton"), &SpineSprite::get_skeleton);
|
||||
ClassDB::bind_method(D_METHOD("get_animation_state"), &SpineSprite::get_animation_state);
|
||||
ClassDB::bind_method(D_METHOD("get_spine_object"), &SpineSprite::get_animation_state);
|
||||
ClassDB::bind_method(D_METHOD("_on_animation_data_changed"), &SpineSprite::_on_animation_data_changed);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_bind_slot_nodes"), &SpineSprite::get_bind_slot_nodes);
|
||||
@ -197,7 +197,7 @@ void SpineSprite::_on_animation_data_created() {
|
||||
|
||||
animation_state = Ref<SpineAnimationState>(memnew(SpineAnimationState));
|
||||
animation_state->load_animation_state(animation_state_data_res);
|
||||
animation_state->get_animation_state()->setListener(this);
|
||||
animation_state->get_spine_object()->setListener(this);
|
||||
|
||||
animation_state->update(0);
|
||||
animation_state->apply(skeleton);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user