Merge pull request #56087 from zaevi/return_key_index
This commit is contained in:
commit
e8d9191ff0
|
@ -391,13 +391,13 @@
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="track_insert_key">
|
<method name="track_insert_key">
|
||||||
<return type="void" />
|
<return type="int" />
|
||||||
<argument index="0" name="track_idx" type="int" />
|
<argument index="0" name="track_idx" type="int" />
|
||||||
<argument index="1" name="time" type="float" />
|
<argument index="1" name="time" type="float" />
|
||||||
<argument index="2" name="key" type="Variant" />
|
<argument index="2" name="key" type="Variant" />
|
||||||
<argument index="3" name="transition" type="float" default="1" />
|
<argument index="3" name="transition" type="float" default="1" />
|
||||||
<description>
|
<description>
|
||||||
Insert a generic key in a given track.
|
Inserts a generic key in a given track. Returns the key index.
|
||||||
</description>
|
</description>
|
||||||
</method>
|
</method>
|
||||||
<method name="track_is_compressed" qualifiers="const">
|
<method name="track_is_compressed" qualifiers="const">
|
||||||
|
|
|
@ -1563,33 +1563,35 @@ int Animation::track_find_key(int p_track, double p_time, bool p_exact) const {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Animation::track_insert_key(int p_track, double p_time, const Variant &p_key, real_t p_transition) {
|
int Animation::track_insert_key(int p_track, double p_time, const Variant &p_key, real_t p_transition) {
|
||||||
ERR_FAIL_INDEX(p_track, tracks.size());
|
ERR_FAIL_INDEX_V(p_track, tracks.size(), -1);
|
||||||
Track *t = tracks[p_track];
|
Track *t = tracks[p_track];
|
||||||
|
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
switch (t->type) {
|
switch (t->type) {
|
||||||
case TYPE_POSITION_3D: {
|
case TYPE_POSITION_3D: {
|
||||||
ERR_FAIL_COND((p_key.get_type() != Variant::VECTOR3) && (p_key.get_type() != Variant::VECTOR3I));
|
ERR_FAIL_COND_V((p_key.get_type() != Variant::VECTOR3) && (p_key.get_type() != Variant::VECTOR3I), -1);
|
||||||
int idx = position_track_insert_key(p_track, p_time, p_key);
|
ret = position_track_insert_key(p_track, p_time, p_key);
|
||||||
track_set_key_transition(p_track, idx, p_transition);
|
track_set_key_transition(p_track, ret, p_transition);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case TYPE_ROTATION_3D: {
|
case TYPE_ROTATION_3D: {
|
||||||
ERR_FAIL_COND((p_key.get_type() != Variant::QUATERNION) && (p_key.get_type() != Variant::BASIS));
|
ERR_FAIL_COND_V((p_key.get_type() != Variant::QUATERNION) && (p_key.get_type() != Variant::BASIS), -1);
|
||||||
int idx = rotation_track_insert_key(p_track, p_time, p_key);
|
ret = rotation_track_insert_key(p_track, p_time, p_key);
|
||||||
track_set_key_transition(p_track, idx, p_transition);
|
track_set_key_transition(p_track, ret, p_transition);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case TYPE_SCALE_3D: {
|
case TYPE_SCALE_3D: {
|
||||||
ERR_FAIL_COND((p_key.get_type() != Variant::VECTOR3) && (p_key.get_type() != Variant::VECTOR3I));
|
ERR_FAIL_COND_V((p_key.get_type() != Variant::VECTOR3) && (p_key.get_type() != Variant::VECTOR3I), -1);
|
||||||
int idx = scale_track_insert_key(p_track, p_time, p_key);
|
ret = scale_track_insert_key(p_track, p_time, p_key);
|
||||||
track_set_key_transition(p_track, idx, p_transition);
|
track_set_key_transition(p_track, ret, p_transition);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case TYPE_BLEND_SHAPE: {
|
case TYPE_BLEND_SHAPE: {
|
||||||
ERR_FAIL_COND((p_key.get_type() != Variant::FLOAT) && (p_key.get_type() != Variant::INT));
|
ERR_FAIL_COND_V((p_key.get_type() != Variant::FLOAT) && (p_key.get_type() != Variant::INT), -1);
|
||||||
int idx = blend_shape_track_insert_key(p_track, p_time, p_key);
|
ret = blend_shape_track_insert_key(p_track, p_time, p_key);
|
||||||
track_set_key_transition(p_track, idx, p_transition);
|
track_set_key_transition(p_track, ret, p_transition);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case TYPE_VALUE: {
|
case TYPE_VALUE: {
|
||||||
|
@ -1599,17 +1601,17 @@ void Animation::track_insert_key(int p_track, double p_time, const Variant &p_ke
|
||||||
k.time = p_time;
|
k.time = p_time;
|
||||||
k.transition = p_transition;
|
k.transition = p_transition;
|
||||||
k.value = p_key;
|
k.value = p_key;
|
||||||
_insert(p_time, vt->values, k);
|
ret = _insert(p_time, vt->values, k);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case TYPE_METHOD: {
|
case TYPE_METHOD: {
|
||||||
MethodTrack *mt = static_cast<MethodTrack *>(t);
|
MethodTrack *mt = static_cast<MethodTrack *>(t);
|
||||||
|
|
||||||
ERR_FAIL_COND(p_key.get_type() != Variant::DICTIONARY);
|
ERR_FAIL_COND_V(p_key.get_type() != Variant::DICTIONARY, -1);
|
||||||
|
|
||||||
Dictionary d = p_key;
|
Dictionary d = p_key;
|
||||||
ERR_FAIL_COND(!d.has("method") || (d["method"].get_type() != Variant::STRING_NAME && d["method"].get_type() != Variant::STRING));
|
ERR_FAIL_COND_V(!d.has("method") || (d["method"].get_type() != Variant::STRING_NAME && d["method"].get_type() != Variant::STRING), -1);
|
||||||
ERR_FAIL_COND(!d.has("args") || !d["args"].is_array());
|
ERR_FAIL_COND_V(!d.has("args") || !d["args"].is_array(), -1);
|
||||||
|
|
||||||
MethodKey k;
|
MethodKey k;
|
||||||
|
|
||||||
|
@ -1618,14 +1620,14 @@ void Animation::track_insert_key(int p_track, double p_time, const Variant &p_ke
|
||||||
k.method = d["method"];
|
k.method = d["method"];
|
||||||
k.params = d["args"];
|
k.params = d["args"];
|
||||||
|
|
||||||
_insert(p_time, mt->methods, k);
|
ret = _insert(p_time, mt->methods, k);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case TYPE_BEZIER: {
|
case TYPE_BEZIER: {
|
||||||
BezierTrack *bt = static_cast<BezierTrack *>(t);
|
BezierTrack *bt = static_cast<BezierTrack *>(t);
|
||||||
|
|
||||||
Array arr = p_key;
|
Array arr = p_key;
|
||||||
ERR_FAIL_COND(arr.size() != 6);
|
ERR_FAIL_COND_V(arr.size() != 6, -1);
|
||||||
|
|
||||||
TKey<BezierKey> k;
|
TKey<BezierKey> k;
|
||||||
k.time = p_time;
|
k.time = p_time;
|
||||||
|
@ -1635,23 +1637,23 @@ void Animation::track_insert_key(int p_track, double p_time, const Variant &p_ke
|
||||||
k.value.out_handle.x = arr[3];
|
k.value.out_handle.x = arr[3];
|
||||||
k.value.out_handle.y = arr[4];
|
k.value.out_handle.y = arr[4];
|
||||||
k.value.handle_mode = static_cast<HandleMode>((int)arr[5]);
|
k.value.handle_mode = static_cast<HandleMode>((int)arr[5]);
|
||||||
_insert(p_time, bt->values, k);
|
ret = _insert(p_time, bt->values, k);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case TYPE_AUDIO: {
|
case TYPE_AUDIO: {
|
||||||
AudioTrack *at = static_cast<AudioTrack *>(t);
|
AudioTrack *at = static_cast<AudioTrack *>(t);
|
||||||
|
|
||||||
Dictionary k = p_key;
|
Dictionary k = p_key;
|
||||||
ERR_FAIL_COND(!k.has("start_offset"));
|
ERR_FAIL_COND_V(!k.has("start_offset"), -1);
|
||||||
ERR_FAIL_COND(!k.has("end_offset"));
|
ERR_FAIL_COND_V(!k.has("end_offset"), -1);
|
||||||
ERR_FAIL_COND(!k.has("stream"));
|
ERR_FAIL_COND_V(!k.has("stream"), -1);
|
||||||
|
|
||||||
TKey<AudioKey> ak;
|
TKey<AudioKey> ak;
|
||||||
ak.time = p_time;
|
ak.time = p_time;
|
||||||
ak.value.start_offset = k["start_offset"];
|
ak.value.start_offset = k["start_offset"];
|
||||||
ak.value.end_offset = k["end_offset"];
|
ak.value.end_offset = k["end_offset"];
|
||||||
ak.value.stream = k["stream"];
|
ak.value.stream = k["stream"];
|
||||||
_insert(p_time, at->values, ak);
|
ret = _insert(p_time, at->values, ak);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
case TYPE_ANIMATION: {
|
case TYPE_ANIMATION: {
|
||||||
|
@ -1661,12 +1663,14 @@ void Animation::track_insert_key(int p_track, double p_time, const Variant &p_ke
|
||||||
ak.time = p_time;
|
ak.time = p_time;
|
||||||
ak.value = p_key;
|
ak.value = p_key;
|
||||||
|
|
||||||
_insert(p_time, at->values, ak);
|
ret = _insert(p_time, at->values, ak);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
}
|
}
|
||||||
|
|
||||||
emit_changed();
|
emit_changed();
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Animation::track_get_key_count(int p_track) const {
|
int Animation::track_get_key_count(int p_track) const {
|
||||||
|
|
|
@ -392,7 +392,7 @@ public:
|
||||||
void track_set_enabled(int p_track, bool p_enabled);
|
void track_set_enabled(int p_track, bool p_enabled);
|
||||||
bool track_is_enabled(int p_track) const;
|
bool track_is_enabled(int p_track) const;
|
||||||
|
|
||||||
void track_insert_key(int p_track, double p_time, const Variant &p_key, real_t p_transition = 1);
|
int track_insert_key(int p_track, double p_time, const Variant &p_key, real_t p_transition = 1);
|
||||||
void track_set_key_transition(int p_track, int p_key_idx, real_t p_transition);
|
void track_set_key_transition(int p_track, int p_key_idx, real_t p_transition);
|
||||||
void track_set_key_value(int p_track, int p_key_idx, const Variant &p_value);
|
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, double p_time);
|
void track_set_key_time(int p_track, int p_key_idx, double p_time);
|
||||||
|
|
Loading…
Reference in New Issue