mirror of
https://github.com/storytold/AniCraft.git
synced 2026-11-28 00:59:30 +01:00
fix(timeline): F6 and F7 over selected frames key every frame of the range (M1)
With frames 3..5 selected only frame 3 became a keyframe: the commands never read the count the editor sends. Each frame of the range now becomes a keyframe (F6) or a blank keyframe (F7) on every selected layer, in one undo step. Keyframes already inside an F7 range keep their drawings. Fixes #272
This commit is contained in:
1 parent
4ccb7d789b
commit
a95c51ec53
2 files changed
+65
-6
No files matched your search
@@ -11,8 +11,8 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
vec![
|
||||
c("timeline.insert_frame", "Frame", "Insert/Timeline", Some("F5"), "{layer? | layers?: [..] | all_layers?: true (every layer with frames at or after the frame, as F5 with no frame selection; the active layer when none has), frame?, count?, advance?: true (the playhead moves onto the last frame inserted, as the key does in the editor)}", true, insert_frame as crate::RunFn),
|
||||
c("timeline.remove_frame", "Remove Frame", "Insert/Timeline", Some("Shift+F5"), "{layer? | layers?: [..], frame?, count?}", true, remove_frame),
|
||||
c("timeline.insert_keyframe", "Keyframe", "Insert/Timeline", Some("F6"), "{layer? | layers?: [..], frame?, advance?: true (on a keyframe the new key goes on the next frame, and the playhead moves onto it, as the key does in the editor)}", true, insert_keyframe),
|
||||
c("timeline.insert_blank_keyframe", "Blank Keyframe", "Insert/Timeline", Some("F7"), "{layer? | layers?: [..], frame?, advance?: true (on a keyframe the blank key goes on the next frame instead of clearing it, and the playhead moves onto it)}", true, insert_blank_keyframe),
|
||||
c("timeline.insert_keyframe", "Keyframe", "Insert/Timeline", Some("F6"), "{layer? | layers?: [..], frame?, count? (every frame of the range becomes a keyframe), advance?: true (on a keyframe the new key goes on the next frame, and the playhead moves onto it, as the key does in the editor)}", true, insert_keyframe),
|
||||
c("timeline.insert_blank_keyframe", "Blank Keyframe", "Insert/Timeline", Some("F7"), "{layer? | layers?: [..], frame?, count? (every frame of the range becomes a blank keyframe; keyframes already there are kept), advance?: true (on a keyframe the blank key goes on the next frame instead of clearing it, and the playhead moves onto it)}", true, insert_blank_keyframe),
|
||||
c("timeline.clear_keyframe", "Clear Keyframe", "Insert/Timeline", Some("Shift+F6"), "{layer? | layers?: [..], frame?, count?}", true, clear_keyframe),
|
||||
c("timeline.move_keyframes", "Move Keyframes", "", None, "{layer? | layers?: [..], from, to?, by, layer_by? (rows down; negative = up)}", true, move_keyframes),
|
||||
c("timeline.move_spans", "Move Spans", "", None, "{layer? | layers?: [..], from, to?, by, layer_by? (rows down; negative = up), copy?: true (Alt-drag: the frames stay where they were too)}: the spans starting in from..=to move whole, keeping their lengths and tweens (as dragging a tween span in Animate), replacing what they land on; the frames they leave are empty", true, move_spans),
|
||||
@@ -428,26 +428,47 @@ pub(crate) fn insert_keyframe_at(layer: &mut Layer, frame: u32, copy: bool) -> R
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// F6. Over a range (`count`, as with frames selected in the editor) every frame in it becomes a
|
||||
/// keyframe holding what that frame showed, as Animate's Convert to Keyframes does (#272).
|
||||
fn insert_keyframe(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let frame = key_frame(s, p)?;
|
||||
let last = last_key_frame(frame, count_param(p)?);
|
||||
for id in target_layers(s, p)? {
|
||||
let layer = s.layer_mut(Some(id))?;
|
||||
// Inside a motion tween F6 keys every property there; the span stays whole.
|
||||
if !crate::cmds_motion::key_all_at(layer, frame) {
|
||||
insert_keyframe_at(layer, frame, true)?;
|
||||
for f in frame..=last {
|
||||
// Inside a motion tween F6 keys every property there; the span stays whole.
|
||||
if !crate::cmds_motion::key_all_at(layer, f) {
|
||||
insert_keyframe_at(layer, f, true)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
advanced(s, p, frame)
|
||||
}
|
||||
|
||||
/// F7. Over a range (`count`) every frame in it becomes a blank keyframe, ready for
|
||||
/// frame-by-frame drawing (#272). Keyframes already in the range stay as they are: a range edit
|
||||
/// makes the keys that are missing and never erases a drawing (one frame alone, without
|
||||
/// `advance`, still clears the keyframe it is on).
|
||||
fn insert_blank_keyframe(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let frame = key_frame(s, p)?;
|
||||
let last = last_key_frame(frame, count_param(p)?);
|
||||
for id in target_layers(s, p)? {
|
||||
insert_keyframe_at(s.layer_mut(Some(id))?, frame, false)?;
|
||||
let layer = s.layer_mut(Some(id))?;
|
||||
for f in frame..=last {
|
||||
if last > frame && layer.keyframe_starting_at(f).is_some() {
|
||||
continue;
|
||||
}
|
||||
insert_keyframe_at(layer, f, false)?;
|
||||
}
|
||||
}
|
||||
advanced(s, p, frame)
|
||||
}
|
||||
|
||||
/// The last frame of a `count`-frame range starting at `frame`, kept inside the timeline.
|
||||
fn last_key_frame(frame: u32, count: u32) -> u32 {
|
||||
frame.saturating_add(count.saturating_sub(1)).min(MAX_FRAME)
|
||||
}
|
||||
|
||||
/// Where F6 / F7 put the key. With `advance`, a frame that is already a keyframe on every target
|
||||
/// layer means "the next one": pressing F6 again after drawing makes the next drawing's key.
|
||||
fn key_frame(s: &Session, p: &Value) -> Result<u32> {
|
||||
|
||||
@@ -124,6 +124,44 @@ fn f7_on_a_keyframe_makes_a_blank_one_next_instead_of_clearing() {
|
||||
assert_eq!(spans(&s, b), vec![(0, 1), (1, 3)]);
|
||||
}
|
||||
|
||||
/// #272: with frames 3..=5 selected, F7 makes each of them a blank keyframe and F6 makes each a
|
||||
/// keyframe of what it showed, on every selected layer, in one undo step. Keyframes already in
|
||||
/// the range keep their drawings.
|
||||
#[test]
|
||||
fn f6_and_f7_over_a_range_key_every_frame() {
|
||||
let mut s = Session::default();
|
||||
let a = layer_with(&mut s, &[(0, 10)]);
|
||||
let b = layer_with(&mut s, &[(0, 4), (4, 6)]);
|
||||
for (layer, frame) in [(a, 0), (b, 0), (b, 4)] {
|
||||
s.layer = layer;
|
||||
s.set_frame(frame);
|
||||
run(&mut s, "draw.rect", json!({"x": 0, "y": 0, "w": 10, "h": 10}));
|
||||
}
|
||||
let drawings = |s: &Session, id| s.timeline().layer(id).unwrap().keyframes.iter().map(|k| k.elements.len()).collect::<Vec<_>>();
|
||||
let before = s.doc.clone();
|
||||
run(&mut s, "timeline.insert_blank_keyframe", json!({"layers": [a.0, b.0], "frame": 3, "count": 3}));
|
||||
assert_eq!(spans(&s, a), vec![(0, 3), (3, 1), (4, 1), (5, 5)]);
|
||||
assert_eq!(drawings(&s, a), vec![1, 0, 0, 0], "the frames before the range keep the drawing");
|
||||
// Layer b already had a keyframe at 4: it stays, with its drawing.
|
||||
assert_eq!(spans(&s, b), vec![(0, 3), (3, 1), (4, 1), (5, 5)]);
|
||||
assert_eq!(drawings(&s, b), vec![1, 0, 1, 0]);
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert_eq!(s.doc, before, "one undo step for the whole range");
|
||||
|
||||
// F6 over the same range: each frame is a keyframe showing what it showed.
|
||||
run(&mut s, "timeline.insert_keyframe", json!({"layers": [a.0, b.0], "frame": 3, "count": 3}));
|
||||
assert_eq!(spans(&s, a), vec![(0, 3), (3, 1), (4, 1), (5, 5)]);
|
||||
assert_eq!(drawings(&s, a), vec![1, 1, 1, 1]);
|
||||
assert_eq!(spans(&s, b), vec![(0, 3), (3, 1), (4, 1), (5, 5)]);
|
||||
assert_eq!(drawings(&s, b), vec![1, 1, 1, 1]);
|
||||
|
||||
// The range is checked, and stops at the last frame the timeline allows.
|
||||
assert!(s.execute("timeline.insert_blank_keyframe", &json!({"frame": 0, "count": 0})).is_err());
|
||||
assert!(s.execute("timeline.insert_keyframe", &json!({"frame": 0, "count": 10_001})).is_err());
|
||||
let _ = s.execute("timeline.insert_blank_keyframe", &json!({"layer": a.0, "frame": MAX_FRAME - 1, "count": 50}));
|
||||
assert!(s.timeline().layer(a).unwrap().end_frame() <= MAX_FRAME + 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn advance_at_the_last_frame_stays_in_range() {
|
||||
let mut s = Session::default();
|
||||
|
||||
Reference in new issue
Block a user