Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge main into M13.15

Brandon Thomas56b3917a1471
diff --cc crates/engine/src/commands/essential.rs
index 2c03efbd8,cbffdc21f..eb3441d9f
--- a/crates/engine/src/commands/essential.rs
+++ b/crates/engine/src/commands/essential.rs
@@@ -145,7 -142,93 +154,93 @@@ fn add_property(s: &mut Session, p: &Va
}
Ok(ids)
})?;
- Ok(json!({"controls": ids}))
+ let mirrors: Vec<u64> = ids.iter().zip(&added).filter(|(_, a)| matches!(a.1, EgKind::Mirror { .. })).map(|(i, _)| *i).collect();
+ Ok(json!({"controls": ids, "mirrors": mirrors}))
+ }
+ /// Add a mirror of a property control (the same property shown again, e.g. in another group).
+ fn add_mirror(s: &mut Session, p: &Value) -> Result<Value> {
+ const C: &str = "essential.addMirror";
+ let cid = eg_comp(s, p)?;
- let of = control_p(p, C)?;
++ let of = control_p(s, cid, p, C)?;
+ let eg = s.project.comp(cid).and_then(|c| c.essential.clone()).unwrap_or_default();
+ let master =
+ eg.resolve(of).filter(|c| matches!(c.kind, EgKind::Property { .. })).ok_or_else(|| bad(C, format!("control {of} is not a property control")))?;
+ let (of, master_name) = (master.id, master.name.clone());
+ let name = str_p(p, "name").map(str::to_string).unwrap_or(master_name);
+ let group = p.get("group").and_then(Value::as_u64);
+ let index = p.get("index").and_then(Value::as_u64).map(|i| i as usize);
+ let id = s.edit("Add Mirror to Essential Graphics", None, |proj, _| {
+ let id = proj.alloc();
+ insert(eg_of(proj, cid)?, EgControl { id, name, kind: EgKind::Mirror { of }, as_type: None }, group, index, C)?;
+ Ok(id)
+ })?;
+ Ok(json!({"control": id, "of": of}))
+ }
+
+ /// The property a link command names: `{layer, path|prop}` or the first selected property.
+ fn link_target(s: &Session, p: &Value, cmd: &str) -> Result<(ItemId, LayerId, Uid)> {
+ if p.get("path").is_some() || p.get("prop").is_some() {
+ return super::prop::prop_ref(s, p, cmd);
+ }
+ let cid = comp_id(s, p)?;
+ selected_leaf_props(s)
+ .into_iter()
+ .next()
+ .map(|(l, u)| (cid, l, u))
+ .ok_or_else(|| bad(cmd, "select a property in the timeline (or give `layer` and `path`)"))
+ }
+
+ /// Make a property control drive another property too (same kind of value).
+ fn link_property(s: &mut Session, p: &Value) -> Result<Value> {
+ const C: &str = "essential.linkProperty";
+ let cid = eg_comp(s, p)?;
- let control = control_p(p, C)?;
++ let control = control_p(s, cid, p, C)?;
+ let (pc, lid, uid) = link_target(s, p, C)?;
+ if pc != cid {
+ return Err(bad(C, "the property must be in the Essential Graphics composition"));
+ }
+ let eg = s.project.comp(cid).and_then(|c| c.essential.clone()).unwrap_or_default();
+ let ctl = eg.resolve(control).ok_or_else(|| bad(C, format!("no control {control}")))?.clone();
+ if ctl.as_type == Some(ControlType::Font) {
+ return Err(bad(C, "a Font control can't drive other properties"));
+ }
+ let (main, _) = essential::source_prop(&s.project, cid, &ctl).ok_or_else(|| bad(C, format!("control {control} is not a property control")))?;
+ let main = main.props.find(match ctl.kind {
+ EgKind::Property { prop, .. } => prop,
+ _ => 0,
+ });
+ let target = s.project.comp(cid).and_then(|c| c.layer(lid)).and_then(|l| l.props.find(uid)).ok_or_else(|| bad(C, "no such property"))?;
+ if !main.is_some_and(|m| essential::linkable(m, target)) {
+ return Err(bad(C, format!("`{}` is not the same kind of property as the control", target.name)));
+ }
+ if let Some(d) = eg.driver_of(lid, uid) {
+ return Err(bad(C, format!("`{}` is already driven by control {}", target.name, d.id)));
+ }
+ let id = ctl.id;
+ s.edit("Link Property to Essential Graphics Control", None, |proj, _| {
+ if let Some(EgControl { kind: EgKind::Property { links, .. }, .. }) = eg_of(proj, cid)?.find_mut(id) {
+ links.push(essential::EgLink { layer: lid, prop: uid });
+ }
+ Ok(())
+ })?;
+ Ok(json!({"control": id, "layer": lid.0, "prop": uid}))
+ }
+
+ fn unlink_property(s: &mut Session, p: &Value) -> Result<Value> {
+ const C: &str = "essential.unlinkProperty";
+ let cid = eg_comp(s, p)?;
- let control = control_p(p, C)?;
++ let control = control_p(s, cid, p, C)?;
+ let (_, lid, uid) = link_target(s, p, C)?;
+ let eg = s.project.comp(cid).and_then(|c| c.essential.clone()).unwrap_or_default();
+ let id = eg.resolve(control).map(|c| c.id).ok_or_else(|| bad(C, format!("no control {control}")))?;
+ s.edit("Unlink Property from Essential Graphics Control", None, |proj, _| match eg_of(proj, cid)?.find_mut(id) {
+ Some(EgControl { kind: EgKind::Property { links, .. }, .. }) if links.iter().any(|k| k.layer == lid && k.prop == uid) => {
+ links.retain(|k| !(k.layer == lid && k.prop == uid));
+ Ok(())
+ }
+ _ => Err(bad(C, "the property is not linked to this control")),
+ })?;
+ Ok(json!({"control": id, "layer": lid.0, "prop": uid}))
}
fn control_type(pr: &effectcraft_project::Property) -> Option<ControlType> {
@@@ -260,12 -343,18 +355,18 @@@ fn rename(s: &mut Session, p: &Value) -
fn remove(s: &mut Session, p: &Value) -> Result<Value> {
const C: &str = "essential.remove";
let cid = eg_comp(s, p)?;
- let id = control_p(p, C)?;
+ let id = control_p(s, cid, p, C)?;
+ // A property control's mirrors go with it.
+ let mirrors = s.project.comp(cid).and_then(|c| c.essential.as_ref()).map(|e| e.mirrors_of(id)).unwrap_or_default();
s.edit("Remove Essential Graphics Control", None, |proj, _| {
- eg_of(proj, cid)?.remove(id).ok_or_else(|| bad(C, format!("no control {id}")))?;
+ let eg = eg_of(proj, cid)?;
+ eg.remove(id).ok_or_else(|| bad(C, format!("no control {id}")))?;
+ for m in &mirrors {
+ eg.remove(*m);
+ }
Ok(())
})?;
- Ok(json!({"control": id}))
+ Ok(json!({"control": id, "mirrors": mirrors}))
}
fn move_control(s: &mut Session, p: &Value) -> Result<Value> {