From adcbcf87dd285343b86b755f287748c3cd205801 Mon Sep 17 00:00:00 2001 From: Tomasz Chabora Date: Fri, 31 May 2019 00:39:00 +0200 Subject: Add track_set_key_time() to Animation --- doc/classes/Animation.xml | 13 ++++++++ scene/resources/animation.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++ scene/resources/animation.h | 1 + 3 files changed, 87 insertions(+) diff --git a/doc/classes/Animation.xml b/doc/classes/Animation.xml index 9885f30883..53d3663d4f 100644 --- a/doc/classes/Animation.xml +++ b/doc/classes/Animation.xml @@ -562,6 +562,19 @@ Set the value of an existing key. + + + + + + + + + + + Set the time of an existing key. + + diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 6ab78326b2..b49b551252 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -1298,6 +1298,78 @@ float Animation::track_get_key_time(int p_track, int p_key_idx) const { ERR_FAIL_V(-1); } +void Animation::track_set_key_time(int p_track, int p_key_idx, float p_time) { + + ERR_FAIL_INDEX(p_track, tracks.size()); + Track *t = tracks[p_track]; + + switch (t->type) { + + case TYPE_TRANSFORM: { + + TransformTrack *tt = static_cast(t); + ERR_FAIL_INDEX(p_key_idx, tt->transforms.size()); + TKey key = tt->transforms[p_key_idx]; + key.time = p_time; + tt->transforms.remove(p_key_idx); + _insert(p_time, tt->transforms, key); + return; + } + case TYPE_VALUE: { + + ValueTrack *vt = static_cast(t); + ERR_FAIL_INDEX(p_key_idx, vt->values.size()); + TKey key = vt->values[p_key_idx]; + key.time = p_time; + vt->values.remove(p_key_idx); + _insert(p_time, vt->values, key); + return; + } + case TYPE_METHOD: { + + MethodTrack *mt = static_cast(t); + ERR_FAIL_INDEX(p_key_idx, mt->methods.size()); + MethodKey key = mt->methods[p_key_idx]; + key.time = p_time; + mt->methods.remove(p_key_idx); + _insert(p_time, mt->methods, key); + return; + } + case TYPE_BEZIER: { + + BezierTrack *bt = static_cast(t); + ERR_FAIL_INDEX(p_key_idx, bt->values.size()); + TKey key = bt->values[p_key_idx]; + key.time = p_time; + bt->values.remove(p_key_idx); + _insert(p_time, bt->values, key); + return; + } + case TYPE_AUDIO: { + + AudioTrack *at = static_cast(t); + ERR_FAIL_INDEX(p_key_idx, at->values.size()); + TKey key = at->values[p_key_idx]; + key.time = p_time; + at->values.remove(p_key_idx); + _insert(p_time, at->values, key); + return; + } + case TYPE_ANIMATION: { + + AnimationTrack *at = static_cast(t); + ERR_FAIL_INDEX(p_key_idx, at->values.size()); + TKey key = at->values[p_key_idx]; + key.time = p_time; + at->values.remove(p_key_idx); + _insert(p_time, at->values, key); + return; + } + } + + ERR_FAIL(); +} + float Animation::track_get_key_transition(int p_track, int p_key_idx) const { ERR_FAIL_INDEX_V(p_track, tracks.size(), -1); @@ -2691,6 +2763,7 @@ void Animation::_bind_methods() { ClassDB::bind_method(D_METHOD("track_remove_key_at_position", "idx", "position"), &Animation::track_remove_key_at_position); ClassDB::bind_method(D_METHOD("track_set_key_value", "idx", "key", "value"), &Animation::track_set_key_value); ClassDB::bind_method(D_METHOD("track_set_key_transition", "idx", "key_idx", "transition"), &Animation::track_set_key_transition); + ClassDB::bind_method(D_METHOD("track_set_key_time", "idx", "key_idx", "time"), &Animation::track_set_key_time); ClassDB::bind_method(D_METHOD("track_get_key_transition", "idx", "key_idx"), &Animation::track_get_key_transition); ClassDB::bind_method(D_METHOD("track_get_key_count", "idx"), &Animation::track_get_key_count); diff --git a/scene/resources/animation.h b/scene/resources/animation.h index 36ebaa25d5..59f2ae24c7 100644 --- a/scene/resources/animation.h +++ b/scene/resources/animation.h @@ -305,6 +305,7 @@ public: void track_insert_key(int p_track, float p_time, const Variant &p_key, float p_transition = 1); void track_set_key_transition(int p_track, int p_key_idx, float p_transition); void track_set_key_value(int p_track, int p_key_idx, const Variant &p_value); + void track_set_key_time(int p_track, int p_key_idx, float p_time); int track_find_key(int p_track, float p_time, bool p_exact = false) const; void track_remove_key(int p_track, int p_idx); void track_remove_key_at_position(int p_track, float p_pos); -- cgit v1.2.3