Squash of #1060 by @RavoxX, without the docs/images screenshots (kept out of the repo). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
committed by
Brandon Thomas
co-authored by
Claude Opus 5.5
parent
9aabb5da4f
commit
1765dc53df
@@ -147,6 +147,100 @@ fn reset_keys_animated_params_at_the_cti() {
|
||||
assert_eq!(pr.keys[1].value, KV::Scalar(0.0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tint_swaps_only_its_colors_in_one_undo_step() {
|
||||
let (mut s, a, b) = comp_with_two_solids();
|
||||
let first = apply(&mut s, a, "Tint");
|
||||
let target = apply(&mut s, a, "Tint");
|
||||
let other = apply(&mut s, b, "Tint");
|
||||
for (path, value) in [("black", json!([1.0, 0.0, 0.0, 1.0])), ("white", json!([0.0, 0.25, 1.0, 1.0])), ("amount", json!(45.0))] {
|
||||
s.execute("prop.set", json!({"layer": a, "path": format!("effects/#2/{path}"), "value": value})).unwrap();
|
||||
}
|
||||
let before_a = layer(&s, a);
|
||||
let before_b = layer(&s, b);
|
||||
let n = s.history.undo.len();
|
||||
s.execute("effect.swapTintColors", json!({"layer": a, "effect": target})).unwrap();
|
||||
let swapped = layer(&s, a);
|
||||
let g = swapped.props.find_group(target).unwrap();
|
||||
assert_eq!(g.prop("black").unwrap().value, KV::Color([0.0, 0.25, 1.0, 1.0]));
|
||||
assert_eq!(g.prop("white").unwrap().value, KV::Color([1.0, 0.0, 0.0, 1.0]));
|
||||
assert_eq!(g.prop("amount").unwrap().value, KV::Scalar(45.0));
|
||||
assert_eq!(swapped.props.find_group(first), before_a.props.find_group(first));
|
||||
assert_eq!(layer(&s, b).props.find_group(other), before_b.props.find_group(other));
|
||||
assert_eq!(s.history.undo.len(), n + 1);
|
||||
assert!(s.undo());
|
||||
assert_eq!(layer(&s, a).props, before_a.props);
|
||||
assert!(s.redo());
|
||||
assert_eq!(layer(&s, a).props, swapped.props);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tint_swap_keys_animated_colors_at_layer_time() {
|
||||
let (mut s, a, _) = comp_with_two_solids();
|
||||
let target = apply(&mut s, a, "Tint");
|
||||
s.execute("prop.set", json!({"layer": a, "path": "effects/#1/black", "value": [1.0, 0.0, 0.0, 1.0]})).unwrap();
|
||||
s.execute("prop.set", json!({"layer": a, "path": "effects/#1/white", "value": [0.0, 0.0, 1.0, 1.0]})).unwrap();
|
||||
s.execute("prop.toggleAnimation", json!({"layer": a, "path": "effects/#1/black"})).unwrap();
|
||||
s.execute("time.set", json!({"time": 2.0})).unwrap();
|
||||
s.execute("prop.set", json!({"layer": a, "path": "effects/#1/black", "value": [0.0, 1.0, 0.0, 1.0]})).unwrap();
|
||||
s.execute("layer.timeStretch", json!({"layers": [a], "percent": 200.0})).unwrap();
|
||||
// At comp time 2s the stretched layer is at 1s, between its unchanged 0s and 2s keys.
|
||||
let before = layer(&s, a);
|
||||
let g = before.props.find_group(target).unwrap();
|
||||
let lt = before.layer_time(s.time());
|
||||
let expected = g.prop("black").unwrap().value_at(lt);
|
||||
let keys = g.prop("black").unwrap().keys.clone();
|
||||
select_effect(&mut s, a, target);
|
||||
s.execute("effect.swapTintColors", json!({})).unwrap();
|
||||
let after = layer(&s, a);
|
||||
let g = after.props.find_group(target).unwrap();
|
||||
let black = g.prop("black").unwrap();
|
||||
assert_eq!(black.keys.len(), 3);
|
||||
assert_eq!(black.keys[0], keys[0]);
|
||||
assert_eq!(black.keys[2], keys[1]);
|
||||
assert_eq!(black.keys[1].time, lt);
|
||||
assert_eq!(black.keys[1].value, KV::Color([0.0, 0.0, 1.0, 1.0]));
|
||||
assert_eq!(g.prop("white").unwrap().value, expected);
|
||||
assert!(g.prop("white").unwrap().keys.is_empty());
|
||||
assert!(s.undo());
|
||||
assert_eq!(layer(&s, a).props, before.props);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tint_swap_rejects_invalid_targets_without_editing() {
|
||||
let mut empty = Session::default();
|
||||
assert!(empty.execute("effect.swapTintColors", json!({})).is_err());
|
||||
let (mut s, a, _) = comp_with_two_solids();
|
||||
let blur = apply(&mut s, a, "Gaussian Blur");
|
||||
let tint = apply(&mut s, a, "Tint");
|
||||
for params in [
|
||||
json!({"layer": a, "effect": blur}),
|
||||
json!({"layer": a, "effect": "missing"}),
|
||||
json!({"layer": a, "effect": []}),
|
||||
json!({"layer": a, "effect": 1.5}),
|
||||
json!({"layer": a, "effect": 0}),
|
||||
json!(false),
|
||||
] {
|
||||
let before = layer(&s, a);
|
||||
let n = s.history.undo.len();
|
||||
assert!(s.execute("effect.swapTintColors", params).is_err());
|
||||
assert_eq!(layer(&s, a).props, before.props);
|
||||
assert_eq!(s.history.undo.len(), n);
|
||||
}
|
||||
// A damaged project's colour parameter must also fail atomically.
|
||||
let cid = s.active_comp_id().unwrap();
|
||||
s.edit("Break Tint", None, |p, _| {
|
||||
p.comp_mut(cid).unwrap().layer_mut(LayerId(a)).unwrap().props.find_group_mut(tint).unwrap().prop_mut("white").unwrap().value = KV::Scalar(1.0);
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
let before = layer(&s, a);
|
||||
let n = s.history.undo.len();
|
||||
assert!(s.execute("effect.swapTintColors", json!({"layer": a, "effect": tint})).is_err());
|
||||
assert_eq!(layer(&s, a).props, before.props);
|
||||
assert_eq!(s.history.undo.len(), n);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn copy_layers_clears_effect_clipboard() {
|
||||
let (mut s, a, b) = comp_with_two_solids();
|
||||
|
||||
Reference in New Issue
Block a user