mirror of
https://github.com/storytold/AniCraft.git
synced 2026-11-28 17:19:31 +01:00
fix(engine): Distribute to Layers keeps layer settings and refuses what it can't keep
Review: the new layers now take their layer's settings (camera depth and depth keys, attachment, the layer it follows, sound volume). Refused with a message: the end of a tween (its artwork is what the tween ends on), an instance that goes on from the keyframe before or after (on a layer of its own it would start playing again), a layer below full opacity (it fades as one group), and layers other than ordinary ones. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
465e30c7dd
commit
2c792b93c1
4 files changed
+52
-9
No files matched your search
@@ -47,7 +47,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
reset_transformation_point,
|
||||
),
|
||||
c("modify.remove_transform", "Remove Transform", "Modify/Transform", Some("Ctrl+Shift+Z"), "{}", true, |s, p| s.each_layer(true, |s| remove_transform(s, p))),
|
||||
c("modify.distribute_to_layers", "Distribute to Layers", "Modify/Timeline", Some("Ctrl+Shift+D"), "{} each selected object (symbol instance, group, drawing object, text, bitmap) on the keyframe at the playhead moves to a new layer of its own just above its layer, named after its symbol when it is an instance, for the same frames. Raw shapes stay where they are; a tweened keyframe is refused → {layers: [new layer ids], left_raw}", true, distribute_to_layers),
|
||||
c("modify.distribute_to_layers", "Distribute to Layers", "Modify/Timeline", Some("Ctrl+Shift+D"), "{} each selected object (symbol instance, group, drawing object, text, bitmap) on the keyframe at the playhead moves to a new layer of its own just above its layer, named after its symbol when it is an instance, for the same frames. Each new layer keeps its layer's settings (camera depth, attachment, the layer it follows). Raw shapes stay where they are; refused for a tweened keyframe or the end of a tween, an instance that goes on from the keyframe before or after, a layer below full opacity, and mask, guide and other special layers → {layers: [new layer ids], left_raw}", true, distribute_to_layers),
|
||||
c("align.left", "Left", "Modify/Align", Some("Ctrl+Alt+1"), "{to_stage?}", true, |s, p| align(s, p, Edge::Left)),
|
||||
c("align.hcenter", "Horizontal Center", "Modify/Align", Some("Ctrl+Alt+2"), "{to_stage?}", true, |s, p| align(s, p, Edge::HCenter)),
|
||||
c("align.right", "Right", "Modify/Align", Some("Ctrl+Alt+3"), "{to_stage?}", true, |s, p| align(s, p, Edge::Right)),
|
||||
@@ -573,11 +573,22 @@ fn distribute_to_layers(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
for source in s.selected_layers() {
|
||||
let sel = s.selection.on(source);
|
||||
let Some(layer) = s.timeline().layer(source).cloned() else { continue };
|
||||
if layer.kind != LayerKind::Normal {
|
||||
return Err(EngineError::State(format!("'{}' is not an ordinary layer: Distribute to Layers moves artwork from ordinary layers only", layer.name)));
|
||||
}
|
||||
if layer.opacity < 1.0 {
|
||||
// Its artwork fades as one group; spread over layers it would fade piece by piece.
|
||||
return Err(EngineError::State(format!("'{}' is below full opacity: set it to 100 % first", layer.name)));
|
||||
}
|
||||
let Some(kf) = layer.keyframe_at(frame) else { continue };
|
||||
if kf.tween.is_some() || kf.motion.is_some() {
|
||||
let (start, duration) = (kf.start, kf.duration);
|
||||
// The keyframes either side: a tween into this one ends on its artwork, and an instance
|
||||
// that goes on from one to the next plays on from where it was.
|
||||
let before = layer.keyframes.iter().find(|k| k.start + k.duration == start);
|
||||
let after = layer.keyframes.iter().find(|k| k.start == start + duration);
|
||||
if kf.tween.is_some() || kf.motion.is_some() || before.is_some_and(|k| k.tween.is_some() || k.motion.is_some()) {
|
||||
return Err(EngineError::State(format!("'{}' is tweened at this frame: Distribute to Layers moves still artwork only", layer.name)));
|
||||
}
|
||||
let (start, duration) = (kf.start, kf.duration);
|
||||
// Bottom first, each new layer going in just above the last: the topmost object ends
|
||||
// up on the topmost new layer.
|
||||
let moving: Vec<Arc<Element>> = kf.elements.iter().filter(|e| sel.contains(&e.id)).cloned().collect();
|
||||
@@ -586,6 +597,10 @@ fn distribute_to_layers(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
if moving.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let goes_on = |id: ElementId| [before, after].into_iter().flatten().any(|k| k.elements.iter().any(|e| e.id == id));
|
||||
if moving.iter().any(|e| matches!(e.kind, ElementKind::Symbol { .. }) && goes_on(e.id)) {
|
||||
return Err(EngineError::State("a selected instance goes on from the keyframe before or after: on a layer of its own it would start playing again. Insert a blank keyframe around it first".into()));
|
||||
}
|
||||
if s.timeline().layers.len() + moving.len() > 1000 {
|
||||
return Err(EngineError::State("too many layers (limit 1000)".into()));
|
||||
}
|
||||
@@ -603,9 +618,13 @@ fn distribute_to_layers(s: &mut Session, _: &Value) -> Result<Value> {
|
||||
};
|
||||
let count = s.timeline().layers.len();
|
||||
let id = LayerId(s.doc.alloc_id());
|
||||
let mut new = Layer::new(id, named.unwrap_or_else(|| format!("Layer {}", count + 1)));
|
||||
new.parent = layer.parent;
|
||||
// The source's settings (folder or mask it is in, camera depth and attachment, the
|
||||
// layer it follows, sound volume), with its own name, colour and frames.
|
||||
let mut new = layer.clone();
|
||||
new.id = id;
|
||||
new.name = named.unwrap_or_else(|| format!("Layer {}", count + 1));
|
||||
new.color = crate::cmds_timeline::layer_color(count + 1);
|
||||
new.video = None;
|
||||
let mut keys = Vec::new();
|
||||
if start > 0 {
|
||||
keys.push(Arc::new(anicraft_doc::Keyframe::new(0, start)));
|
||||
|
||||
@@ -318,12 +318,33 @@ fn distribute_to_layers_gives_each_object_its_own_layer() {
|
||||
let tl = s.timeline();
|
||||
assert_eq!(tl.layers.len(), layers_before + 2);
|
||||
let names: Vec<&str> = tl.layers.iter().map(|l| l.name.as_str()).collect();
|
||||
let (front, back, src) = (names.iter().position(|n| *n == "Front"), names.iter().position(|n| *n == "Back"), tl.layers.iter().position(|l| l.id == home));
|
||||
assert!(front < back && back < src, "the front instance on the top layer, both above their old layer: {names:?}");
|
||||
let at = |n: &str| names.iter().position(|x| *x == n).unwrap_or_else(|| panic!("a layer named {n}: {names:?}"));
|
||||
let src = tl.layers.iter().position(|l| l.id == home).expect("the old layer");
|
||||
assert!(at("Front") < at("Back") && at("Back") < src, "the front instance on the top layer, both above their old layer: {names:?}");
|
||||
let left = tl.layer(home).and_then(|l| l.keyframe_at(0)).map(|k| k.elements.len());
|
||||
assert_eq!(left, Some(1), "only the raw square stays");
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert_eq!(s.timeline().layers.len(), layers_before, "one undo step");
|
||||
|
||||
// A layer's camera depth goes with it; a faded layer and the end of a tween are refused.
|
||||
run(&mut s, "layer.set_depth", json!({"layer": home.0, "depth": 40}));
|
||||
run(&mut s, "edit.select_all", json!({}));
|
||||
let v = run(&mut s, "modify.distribute_to_layers", json!({}));
|
||||
let first = anicraft_doc::LayerId(v["layers"][0].as_u64().unwrap_or(0));
|
||||
assert_eq!(s.timeline().layer(first).map(|l| l.depth), Some(40.0));
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
run(&mut s, "layer.set_opacity", json!({"layer": home.0, "opacity": 50}));
|
||||
run(&mut s, "edit.select_all", json!({}));
|
||||
let e = s.execute("modify.distribute_to_layers", &json!({})).expect_err("a faded layer");
|
||||
assert!(e.to_string().contains("opacity"), "{e}");
|
||||
run(&mut s, "layer.set_opacity", json!({"layer": home.0, "opacity": 100}));
|
||||
run(&mut s, "timeline.insert_frame", json!({"layer": home.0, "frame": 0, "count": 9}));
|
||||
run(&mut s, "timeline.insert_keyframe", json!({"layer": home.0, "frame": 10}));
|
||||
run(&mut s, "timeline.create_tween", json!({"layer": home.0, "frame": 0}));
|
||||
run(&mut s, "timeline.goto", json!({"frame": 10}));
|
||||
run(&mut s, "edit.select_all", json!({}));
|
||||
let e = s.execute("modify.distribute_to_layers", &json!({})).expect_err("the end of a tween");
|
||||
assert!(e.to_string().contains("tweened"), "{e}");
|
||||
}
|
||||
|
||||
/// #301, #297: a raw rectangle (one fill and one stroke per side, ADR 0042) aligns, distributes,
|
||||
|
||||
@@ -496,7 +496,10 @@ drawing object into merged drawing.
|
||||
(a symbol instance, group, drawing object, text or bitmap) on a new layer of its own, just
|
||||
above the layer it was on and named after its symbol, for the same frames. Break Apart a
|
||||
symbol instance first (**Ctrl+B**), then Distribute to Layers, to spread its contents over
|
||||
layers. Raw shapes stay where they are, and a tweened keyframe is refused.
|
||||
layers. Each new layer keeps its layer's camera depth and the layer it follows. Raw shapes stay
|
||||
where they are. It is refused, with a message saying why, on a tweened keyframe or the end of a
|
||||
tween, for an instance that goes on from the keyframe before or after, and on a layer below full
|
||||
opacity.
|
||||
|
||||
### Envelope
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ This page is generated from the command registry, so it always matches the versi
|
||||
- **Remove Transform** `modify.remove_transform` · Modify › Transform · **Ctrl+Shift+Z** (macOS **⇧⌘Z**) · changes the document
|
||||
Parameters: `{}`
|
||||
- **Distribute to Layers** `modify.distribute_to_layers` · Modify › Timeline · **Ctrl+Shift+D** (macOS **⇧⌘D**) · changes the document
|
||||
Parameters: `{} each selected object (symbol instance, group, drawing object, text, bitmap) on the keyframe at the playhead moves to a new layer of its own just above its layer, named after its symbol when it is an instance, for the same frames. Raw shapes stay where they are; a tweened keyframe is refused → {layers: [new layer ids], left_raw}`
|
||||
Parameters: `{} each selected object (symbol instance, group, drawing object, text, bitmap) on the keyframe at the playhead moves to a new layer of its own just above its layer, named after its symbol when it is an instance, for the same frames. Each new layer keeps its layer's settings (camera depth, attachment, the layer it follows). Raw shapes stay where they are; refused for a tweened keyframe or the end of a tween, an instance that goes on from the keyframe before or after, a layer below full opacity, and mask, guide and other special layers → {layers: [new layer ids], left_raw}`
|
||||
- **Left** `align.left` · Modify › Align · **Ctrl+Alt+1** (macOS **⌥⌘1**) · changes the document
|
||||
Parameters: `{to_stage?}`
|
||||
- **Horizontal Center** `align.hcenter` · Modify › Align · **Ctrl+Alt+2** (macOS **⌥⌘2**) · changes the document
|
||||
|
||||
Reference in new issue
Block a user