mirror of
https://github.com/storytold/AniCraft.git
synced 2026-12-01 02:24:23 +01:00
fix(engine): camera.set on a held frame says which keyframe it edited
camera.set edits the keyframe that holds the requested frame when the frame has no keyframe of its own (as editing a held frame on the stage does), but reported plain success. It now adds `keyframe` (the edited keyframe's start) and a `note` on how to key the requested frame instead. Fixes #673. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c6b7a95c12
commit
c2d04d2fe0
2 files changed
+37
-1
No files matched your search
@@ -139,6 +139,9 @@ fn set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
return Err(EngineError::Param("param 'zoom_by' must be above 0".into()));
|
||||
}
|
||||
let stage = s.doc.stage;
|
||||
// On a held frame (inside a keyframe's span, no tween) the edit lands on that keyframe, as
|
||||
// any edit does: say so, so a caller keying the camera over time sees it was not keyed here.
|
||||
let held = s.timeline().layer(id).and_then(|l| l.keyframe_at(frame)).filter(|k| k.start != frame && k.tween.is_none() && k.motion.is_none()).map(|k| (k.start, k.start + k.duration.max(1) - 1));
|
||||
// A camera is created on a keyframe that has none (a blank camera keyframe is at rest).
|
||||
// (Its id is taken only when it is used, so a no-op leaves the document unchanged.)
|
||||
let fresh = ElementId(s.doc.next_id.max(1));
|
||||
@@ -184,7 +187,22 @@ fn set(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
if used {
|
||||
s.doc.alloc_id();
|
||||
}
|
||||
Ok(camera_json(&c, &stage))
|
||||
let mut out = camera_json(&c, &stage);
|
||||
if let (Some((start, end)), Some(o)) = (held, out.as_object_mut()) {
|
||||
o.insert("keyframe".into(), json!(start));
|
||||
o.insert(
|
||||
"note".into(),
|
||||
json!(format!(
|
||||
"frame {} has no camera keyframe of its own: the keyframe on frame {} (frames {}–{}) was edited. To key the camera on frame {}, insert a keyframe there first or tween the camera layer",
|
||||
frame + 1,
|
||||
start + 1,
|
||||
start + 1,
|
||||
end + 1,
|
||||
frame + 1
|
||||
)),
|
||||
);
|
||||
}
|
||||
Ok(out)
|
||||
}
|
||||
|
||||
fn camera_json(c: &Camera, stage: &anicraft_doc::Stage) -> Value {
|
||||
|
||||
@@ -425,3 +425,21 @@ fn picking_through_the_camera_finds_what_the_movie_shows() {
|
||||
let d = v.inverse().unwrap().apply_vector(anicraft_geom::Vec2::new(10.0, 0.0));
|
||||
assert!((d.x - 5.0).abs() < 1e-4, "{d:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_on_a_held_frame_reports_the_keyframe_it_edited() {
|
||||
let mut s = stage_with(&[(95.0, 45.0, 10.0, 10.0)]);
|
||||
run(&mut s, "camera.add", json!({}));
|
||||
// Frame 10 is held by the camera's one keyframe (frames 1–20): the edit lands on that keyframe.
|
||||
let v = run(&mut s, "camera.set", json!({"zoom": 200, "frame": 10}));
|
||||
assert_eq!(v["keyframe"], 0, "{v}");
|
||||
assert!(v["note"].as_str().is_some_and(|n| n.contains("frame 11") && n.contains("frame 1 ")), "{v}");
|
||||
assert_eq!(s.doc.timeline(0).layers[0].keyframes.len(), 1, "no keyframe was added");
|
||||
let zoom = |s: &mut Session, f: u32| run(s, "camera.info", json!({"frame": f}))["zoom"].as_f64().unwrap();
|
||||
assert!((zoom(&mut s, 0) - zoom(&mut s, 19)).abs() < 1e-6, "the whole span changed together");
|
||||
// On a keyframe of its own there is nothing to report.
|
||||
run(&mut s, "timeline.insert_keyframe", json!({"frame": 10}));
|
||||
let v = run(&mut s, "camera.set", json!({"zoom": 300, "frame": 10}));
|
||||
assert!(v.get("note").is_none() && v.get("keyframe").is_none(), "{v}");
|
||||
assert!(zoom(&mut s, 10) > zoom(&mut s, 0), "the new keyframe holds its own zoom");
|
||||
}
|
||||
Reference in new issue
Block a user