EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge branch 'worktree-agent-aaed9f382307fbe0b'
Brandon Thomasb307a562ed9b
diff --cc crates/engine/src/tests.rsindex bea8c2d07,587190f9e..2fdff890a--- a/crates/engine/src/tests.rs+++ b/crates/engine/src/tests.rs@@@ -115,57 -115,75 +115,130 @@@ fn time_navigation()assert_eq!(s.execute("time.step", json!({"frames": 5})).unwrap()["frame"], 50);}+#[test]+fn time_navigation_per_property() {+ let mut s = demo();+ // An animated property and the comp times of its keys.+ let comp = s.active_comp().unwrap().clone();+ let mut found = None;+ for l in &comp.layers {+ l.props.walk("", &mut |_, pr| {+ if found.is_none() && pr.keys.len() >= 2 {+ found = Some((pr.uid, pr.keys.iter().map(|k| l.comp_time(k.time)).collect::<Vec<_>>()));+ }+ });+ }+ let (uid, times) = found.expect("demo has an animated property");+ s.set_time(effectcraft_time::Tick::ZERO);+ let half = comp.frame_duration().0 / 2;+ let expect = times.iter().copied().filter(|t| t.0 > half).min().unwrap();+ s.execute("time.go", json!({"to": "nextKey", "prop": uid})).unwrap();+ let snap = |t| comp.frame_rate.snap(t);+ assert_eq!(s.time(), snap(expect));+ // Going back from past the last key lands on the last key.+ s.set_time(comp.duration);+ s.execute("time.go", json!({"to": "prevKey", "prop": uid})).unwrap();+ assert_eq!(s.time(), snap(*times.iter().max().unwrap()));+}++#[test]+fn set_text_paragraph_fill_and_leading() {+ use effectcraft_keyframe::{Justify, Value as KValue};+ let mut s = demo();+ let t = s.execute("layer.newText", json!({"text": "Hi"})).unwrap()["layer"].as_u64().unwrap();+ let doc = |s: &Session| {+ let l = s.active_comp().unwrap().layer(crate::project::LayerId(t)).unwrap().clone();+ match &l.props.prop("text/sourceText").unwrap().value {+ KValue::Text(d) => (**d).clone(),+ v => panic!("{v:?}"),+ }+ };+ for (key, j) in [+ ("justifyLeft", Justify::JustifyLastLeft),+ ("justifyCenter", Justify::JustifyLastCenter),+ ("justifyRight", Justify::JustifyLastRight),+ ("justifyAll", Justify::JustifyAll),+ ("center", Justify::Center),+ ] {+ s.execute("layer.setText", json!({"layer": t, "justify": key})).unwrap();+ assert_eq!(doc(&s).justify, j, "{key}");+ }+ s.execute("layer.setText", json!({"layer": t, "leading": 50, "applyFill": false, "applyStroke": true})).unwrap();+ let d = doc(&s);+ assert_eq!((d.leading, d.apply_fill, d.apply_stroke), (Some(50.0), false, true));+ s.execute("layer.setText", json!({"layer": t, "leading": "auto"})).unwrap();+ assert_eq!(doc(&s).leading, None);+}+++ #[test]+ fn prop_get_and_render_rgba8() {+ let mut s = Session::default();+ s.execute("comp.new", json!({"name": "T", "width": 320, "height": 180, "duration": 2.0})).unwrap();+ let l = s.execute("layer.newSolid", json!({"color": "#ff0000"})).unwrap()["layer"].as_u64().unwrap();+ s.execute("prop.addKey", json!({"layer": l, "path": "transform/position", "time": 0.0, "value": [0, 0]})).unwrap();+ s.execute("prop.addKey", json!({"layer": l, "path": "transform/position", "time": 1.0, "value": [100, 50]})).unwrap();+ let v = s.execute("prop.get", json!({"layer": l, "path": "transform/position", "time": 1.0})).unwrap();+ assert_eq!(v["animated"], true);+ assert_eq!(v["keys"].as_array().unwrap().len(), 2);+ assert_eq!(v["value"][0].as_f64().unwrap(), 100.0);+ let cid = s.resolve_comp(Some(&json!("T"))).unwrap();+ let (w, h, rgba) = s.render_rgba8(cid, effectcraft_time::Tick::ZERO, 160).unwrap();+ assert_eq!((w, h), (160, 90));+ assert_eq!(rgba.len(), (w * h * 4) as usize);+ }++ #[test]+ fn params_docs_parse() {+ use crate::commands::accepted_params;+ let k = |d: &str| accepted_params(d).unwrap();+ assert_eq!(k("{layers: [id|name|#n], add?, toggle?}"), ["layers", "add", "toggle"]);+ assert_eq!(k("{time? (s) | frame? | timecode?}"), ["time", "frame", "timecode"]);+ assert_eq!(k("{interpolation?|in?|out?: linear|bezier|hold, autoBezier?}"), ["interpolation", "in", "out", "autoBezier"]);+ assert_eq!(k("{keys: [{layer, prop, time}], add?}"), ["keys", "add"]);+ assert_eq!(k("{label: Red|Yellow|Aqua|…, layers?}"), ["label", "layers"]);+ assert_eq!(k("{name?, background? [r,g,b]|#hex, open?}"), ["name", "background", "open"]);+ assert!(k("{}").is_empty());+ assert!(accepted_params("free text").is_none());+ // Every registered command documents its params as a parseable key list.+ for c in crate::command_specs() {+ assert!(accepted_params(c.params).is_some(), "{}: {}", c.id, c.params);+ }+ }++ #[test]+ fn execute_checked_rejects_unknown_params() {+ let mut s = demo();+ let e = s.execute_checked("layer.select", json!({"index": 2})).unwrap_err().to_string();+ assert!(e.contains("`index`") && e.contains("layers, add, toggle"), "{e}");+ s.execute_checked("layer.select", json!({"layers": ["#2"]})).unwrap();+ assert_eq!(s.state.selected_layers.len(), 1);+ // Aliases and always-accepted keys.+ s.execute_checked("layer.select", json!({"layer": "#1", "comp": s.active_comp_id().unwrap().0})).unwrap();+ s.execute_checked("time.set", json!({"frame": 3})).unwrap();+ assert!(s.execute_checked("edit.undo", json!({"steps": 2})).is_err());+ // Non-object params are not validated; the unchecked path stays lenient.+ s.execute("layer.select", json!({"layers": ["#1"], "index": 2})).unwrap();+ }++ #[test]+ fn layer_tree_paths_resolve() {+ let mut s = demo();+ s.execute("effect.apply", json!({"layer": 1, "effect": "Gaussian Blur"})).unwrap();+ let comp = s.execute("comp.info", json!({})).unwrap();+ let mut checked = 0;+ for l in comp["layers"].as_array().unwrap() {+ let tree = s.execute("layer.tree", json!({"layer": l["id"]})).unwrap();+ let mut stack = vec![tree["properties"].clone()];+ while let Some(n) = stack.pop() {+ if let Some(ch) = n["children"].as_array() {+ stack.extend(ch.iter().cloned());+ continue;+ }+ let path = n["path"].as_str().unwrap();+ let got = s.execute("prop.get", json!({"layer": l["id"], "path": path})).unwrap();+ assert_eq!(got["uid"], n["uid"], "path {path} on layer {}", l["name"]);+ checked += 1;+ }+ }+ assert!(checked > 20, "{checked}");+ }