mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-19 16:45:28 +00:00
Expressions: a layer parameter left at None is the layer it sits on (#3601)
Fixes #3601. ### What A layer parameter left at None (a Layer Control, or an effect's layer parameter) now stands for the layer it sits on, as in After Effects (values observed in AE 26.3 are in #3601). Before, its value was `null`. The property was still truthy, so a rig's `L ? L.sourceRectAtTime(t) : 0` went down the wrong branch and stopped with "not a callable function". The change is one line in `Prop.__wrap` (`crates/expr/src/prelude.js`). ### Tested - **`an_empty_layer_control_stands_for_its_own_layer`** in `crates/expr/src/tests.rs`: truthiness, `name`, `index`, the `L ? L.transform.position[0] : -1` pattern, and `sourceRectAtTime`. It fails without the change. - **Suites:** `cargo test -p effectcraft-expr` (167 passed) and `cargo test -p effectcraft-script` pass. clippy and fmt are clean. - **Not covered here:** calling the empty parameter like a layer (`L("ADBE Transform Group")`). That depends on #3554, and works with both applied.
This commit is contained in:
1 parent
981981632c
commit
67942cda7b
2 files changed
+53
-3
No files matched your search
@@ -870,14 +870,18 @@ Prop.prototype = {
|
||||
propertyGroup: function (n) { return __ancestor(this.__c, this.__l, this.__p, n); },
|
||||
__wrap: function (v) {
|
||||
var kind = this.__info[2];
|
||||
if (kind === 'layer') return v === null ? null : __layer(this.__c, v);
|
||||
// A layer parameter set to None is the layer it sits on, as in After Effects.
|
||||
if (kind === 'layer') return __layer(this.__c, v === null ? this.__l : v);
|
||||
if (kind === 'path' && v !== null) return new __Path(v[0], v[1], v[2], v[3]);
|
||||
return v;
|
||||
},
|
||||
get value() { return this.__self ? value : this.valueAtTime(time); },
|
||||
get value() { return this.__self ? this.__selfValue() : this.valueAtTime(time); },
|
||||
// The evaluated property's own value: a layer parameter reads as its layer here too.
|
||||
// (After posterizeTime, `value` may already be the layer.)
|
||||
__selfValue: function () { return this.__info[2] === 'layer' && !value?.__isLayer ? this.__wrap(value) : value; },
|
||||
valueAtTime: function (t) {
|
||||
t = __v(t);
|
||||
if (this.__self && t === time) return value;
|
||||
if (this.__self && t === time) return this.__selfValue();
|
||||
return this.__wrap(__h(__VALUE, this.__c, this.__l, this.__p, t, this.__self));
|
||||
},
|
||||
velocityAtTime: function (t) {
|
||||
|
||||
@@ -1928,6 +1928,52 @@ fn layer_control_property_stands_for_its_layer() {
|
||||
assert_close!(f.num("effect('Map')(1).value.name == 'B' ? 1 : 0", 0.0), 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_layer_control_stands_for_its_own_layer() {
|
||||
// In After Effects a Layer Control set to None gives the layer the effect is on: truthy, named
|
||||
// and callable as that layer. Rigs test it with `L ? … : …` and then read `L.sourceRectAtTime`.
|
||||
let mut f = fx();
|
||||
let spec = effectcraft_effects::find("ec.control.layer").unwrap();
|
||||
let mut map = group_push(&mut f.p, |ids| effectcraft_effects::instantiate(spec, ids, "Map", [20.0, 20.0]));
|
||||
map.prop_mut("layer").unwrap().value = Value::Layer(None);
|
||||
f.p.comp_mut(f.cid).unwrap().layers[0].props.sub_mut("effects").unwrap().children.push(map.into());
|
||||
assert_close!(f.num("effect('Map')(1) ? 1 : 0", 0.0), 1.0);
|
||||
assert_close!(f.num("effect('Map')(1).name == thisLayer.name ? 1 : 0", 0.0), 1.0);
|
||||
assert_close!(f.num("effect('Map')(1).index", 0.0), 1.0);
|
||||
assert_close!(f.num("var L = effect('Map')(1); L ? L.transform.position[0] : -1", 0.0), 50.0);
|
||||
assert_close!(f.num("effect('Map')(1).sourceRectAtTime(time).width == thisLayer.sourceRectAtTime(time).width ? 1 : 0", 0.0), 1.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_layer_parameters_own_expression_reads_its_layer() {
|
||||
// An expression on the layer parameter itself: `thisProperty.value` and
|
||||
// `thisProperty.valueAtTime(time)` give the layer, as reads from other properties do.
|
||||
let mut f = fx();
|
||||
let spec = effectcraft_effects::find("ec.control.layer").unwrap();
|
||||
let mut empty = group_push(&mut f.p, |ids| effectcraft_effects::instantiate(spec, ids, "Empty", [20.0, 20.0]));
|
||||
empty.prop_mut("layer").unwrap().value = Value::Layer(None);
|
||||
let mut set = group_push(&mut f.p, |ids| effectcraft_effects::instantiate(spec, ids, "Set", [20.0, 20.0]));
|
||||
set.prop_mut("layer").unwrap().value = Value::Layer(Some(f.b.0));
|
||||
let fx_group = f.p.comp_mut(f.cid).unwrap().layers[0].props.sub_mut("effects").unwrap();
|
||||
fx_group.children.push(empty.into());
|
||||
fx_group.children.push(set.into());
|
||||
let n = f.p.comp(f.cid).unwrap().layers[0].props.sub("effects").unwrap().children.len();
|
||||
let (empty_path, set_path) = (format!("effects/#{}/layer", n - 1), format!("effects/#{n}/layer"));
|
||||
// Each expression throws unless it reads the right layer's name.
|
||||
for (path, read, want) in [
|
||||
(&empty_path, "thisProperty.value", "A"),
|
||||
(&empty_path, "thisProperty.valueAtTime(time)", "A"),
|
||||
(&set_path, "thisProperty.value", "B"),
|
||||
(&set_path, "thisProperty.valueAtTime(time)", "B"),
|
||||
] {
|
||||
let e = format!("if ({read}.name !== '{want}') throw new Error('read ' + {read}); value");
|
||||
f.ev(f.a, path, &e, 0.0).unwrap_or_else(|err| panic!("{path} {read}: {err}"));
|
||||
// After posterizeTime moves the sample time, `value` already holds the layer.
|
||||
let e = format!("posterizeTime(1); if ({read}.name !== '{want}') throw new Error('read ' + {read}); value");
|
||||
f.ev(f.a, path, &e, 0.5).unwrap_or_else(|err| panic!("posterized {path} {read}: {err}"));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn time_to_frames_rounds_durations_away_from_zero() {
|
||||
let f = fx();
|
||||
|
||||
Reference in new issue
Block a user