mirror of
https://github.com/storytold/effectcraft.git
synced 2026-11-19 16:45:28 +00:00
Merge remote-tracking branch 'origin/footage-cache-3271' into cache-defaults-3298
This commit is contained in:
commit
43b0d95ae0
3 files changed
+45
-2
No files matched your search
@@ -553,7 +553,8 @@ fn paste_links(s: &mut Session, clip: LinkClip) -> Result<Value> {
|
||||
let l = super::layer_mut(proj, cid, *lid)?;
|
||||
for (path, e) in &pairs {
|
||||
let path = super::resolve_effect_path(l, path);
|
||||
if let Some(pr) = l.props.prop_mut(&path) {
|
||||
// (a property that can't be animated takes no expression)
|
||||
if let Some(pr) = l.props.prop_mut(&path).filter(|pr| !pr.static_only) {
|
||||
pr.expr = Some(e.clone());
|
||||
n += 1;
|
||||
}
|
||||
|
||||
@@ -694,6 +694,19 @@ fn apply_expr(pr: &mut Property, text: &Option<String>, enabled: Option<bool>, d
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether [`apply_expr`] would leave `pr` with an enabled expression it didn't have (a new one,
|
||||
/// one switched on, or new text).
|
||||
fn adds_expression(pr: &Property, text: &Option<String>, enabled: Option<bool>, def: &str) -> bool {
|
||||
let mut after = pr.clone();
|
||||
apply_expr(&mut after, text, enabled, def);
|
||||
match (&pr.expr, &after.expr) {
|
||||
(_, None) => false,
|
||||
(_, Some(a)) if !a.enabled => false,
|
||||
(Some(b), Some(a)) => !b.enabled || b.text != a.text,
|
||||
(None, Some(_)) => true,
|
||||
}
|
||||
}
|
||||
|
||||
/// `{layer?, path|prop, ...}` for one property, or (Animation > Add Expression) no `path`/`prop`
|
||||
/// for the properties selected in the timeline, all in one undo step.
|
||||
fn set_expr(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
@@ -731,7 +744,9 @@ fn set_expr(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
let mut changed_types = vec![];
|
||||
for (((cid, lid, uid), def), time) in targets.iter().zip(&defs).zip(×) {
|
||||
let pr = layer_mut(proj, *cid, *lid)?.props.find_mut(*uid).ok_or_else(|| bad(C, "property vanished"))?;
|
||||
if pr.static_only && text.as_deref().is_some_and(|t| !t.trim().is_empty()) {
|
||||
// A property that can't be animated takes no expression (one an older document has
|
||||
// may still be disabled or removed).
|
||||
if pr.static_only && adds_expression(pr, &text, enabled, def) {
|
||||
return Err(bad(C, format!("{} can't have an expression", pr.name)));
|
||||
}
|
||||
apply_expr(pr, &text, enabled, def);
|
||||
|
||||
@@ -224,6 +224,9 @@ fn channel_selection_is_static_and_says_what_is_read() {
|
||||
assert!(s.execute_checked("prop.toggleKey", json!({"layer": l, "path": red})).is_err(), "no keyframe");
|
||||
assert!(s.execute_checked("prop.toggleAnimation", json!({"layer": l, "path": red})).is_err(), "no stopwatch");
|
||||
assert!(s.execute_checked("prop.setExpression", json!({"layer": l, "path": red, "expression": "'Z'"})).is_err(), "no expression");
|
||||
// (the forms that add the default expression: a toggle, and switching one on)
|
||||
assert!(s.execute_checked("prop.setExpression", json!({"layer": l, "path": red})).is_err(), "no expression by toggle");
|
||||
assert!(s.execute_checked("prop.setExpression", json!({"layer": l, "path": red, "enabled": true})).is_err(), "no expression switched on");
|
||||
assert!(prop(&s, red).keys.is_empty() && prop(&s, red).expr.is_none());
|
||||
// The value changes; the channels read are exactly those picked.
|
||||
s.execute_checked("prop.set", json!({"layer": l, "path": red, "value": "Z"})).unwrap();
|
||||
@@ -269,3 +272,27 @@ fn a_keyed_channel_selection_opens_static() {
|
||||
assert!(said, "the loss is reported");
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// #3271 review: an expression a channel selection has from an older document (set here by
|
||||
/// hand) can still be switched off and removed.
|
||||
#[test]
|
||||
fn a_channel_selections_old_expression_can_be_removed() {
|
||||
let rec = Arc::new(Recorder::default());
|
||||
let mut s = session(&rec);
|
||||
let item = import(&mut s, "/renders/old-expr.exr");
|
||||
let l = add_layer(&mut s, &item);
|
||||
s.execute_checked("effect.apply", json!({"effect": "EXtractoR", "layers": [l]})).unwrap();
|
||||
let cid = s.active_comp_id().unwrap();
|
||||
let red = "effects/#1/red";
|
||||
{
|
||||
let p = Arc::make_mut(&mut s.project);
|
||||
let pr = p.comp_mut(cid).unwrap().layer_mut(effectcraft_project::LayerId(l)).unwrap().props.prop_mut(red).unwrap();
|
||||
pr.expr = Some(effectcraft_project::Expression { text: "'Z'".into(), enabled: true });
|
||||
}
|
||||
let expr = |s: &Session| s.active_comp().unwrap().layer(effectcraft_project::LayerId(l)).unwrap().props.prop(red).unwrap().expr.clone();
|
||||
s.execute_checked("prop.setExpression", json!({"layer": l, "path": red, "enabled": false})).unwrap();
|
||||
assert!(expr(&s).is_some_and(|e| !e.enabled), "switched off");
|
||||
assert!(s.execute_checked("prop.setExpression", json!({"layer": l, "path": red, "enabled": true})).is_err(), "not on again");
|
||||
s.execute_checked("prop.setExpression", json!({"layer": l, "path": red, "expression": ""})).unwrap();
|
||||
assert!(expr(&s).is_none(), "removed");
|
||||
}
|
||||
Reference in new issue
Block a user