EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Clipboard: keyframe text leaves out Transform properties the layer doesn't use (#1908)
tylerjenningsw6b77e6a1a715
diff --git a/crates/engine/src/keyframe_text.rs b/crates/engine/src/keyframe_text.rsindex 8fca3c343..793d0cfb8 100644--- a/crates/engine/src/keyframe_text.rs+++ b/crates/engine/src/keyframe_text.rs@@ -4,7 +4,7 @@//! (frame number in comp time, then the value) and static ones as a single row with no frame.//! Easing and tangents aren't part of the format; EffectCraft's own paste keeps them.-use effectcraft_project::{Comp, LayerId, Project, Uid};+use effectcraft_project::{AutoOrient, Comp, Layer, LayerId, Project, Uid};use crate::KeyRef;@@ -33,7 +33,7 @@ pub(crate) fn text(project: &Project, comp: &Comp, keys: &[KeyRef], statics: &[(let mut blocks = String::new();for (id, unit) in CHANNELS {let Some(pr) = layer.props.prop(&format!("transform/{id}")) else { continue };- if pr.three_d_only && !layer.is_3d() {+ if !active(layer, id) || (pr.three_d_only && !layer.is_3d()) {continue;}let mut times: Vec<_> = keys.iter().filter(|k| k.prop == pr.uid).map(|k| k.time).collect();@@ -76,6 +76,17 @@ pub(crate) fn text(project: &Project, comp: &Comp, keys: &[KeyRef], statics: &[())}+/// Whether the layer uses this Transform property: one-node cameras (and lights not aimed at+/// it) have no Point of Interest, and Separate Dimensions replaces Position with X / Y / Z+/// Position (which this text doesn't cover).+fn active(layer: &Layer, id: &str) -> bool {+ match id {+ "poi" => !(layer.is_camera() || layer.is_light()) || layer.auto_orient == AutoOrient::TowardsPointOfInterest,+ "position" => layer.transform().is_none_or(|tr| tr.get("positionX").is_none()),+ _ => true,+ }+}+/// A number with at most three decimals and no trailing zeros (`23.976`, `960`, `-0.5`).fn num(v: f64) -> String {let s = format!("{:.3}", if v.is_finite() { v } else { 0.0 });diff --git a/crates/engine/src/tests_keyframe_text.rs b/crates/engine/src/tests_keyframe_text.rsindex 34966269b..81ca97bd4 100644--- a/crates/engine/src/tests_keyframe_text.rs+++ b/crates/engine/src/tests_keyframe_text.rs@@ -109,6 +109,35 @@ fn a_copied_transform_group_lists_what_the_layer_shows() {assert!(text.contains("Transform\tOrientation\n\tFrame\tX degrees\n\t\t0\t0\t0\n"), "{text}");}+fn copy_transform(s: &mut Session, lid: LayerId) -> String {+ let transform = s.active_comp().unwrap().layer(lid).unwrap().props.sub("transform").unwrap().uid;+ s.execute("prop.select", json!({"layer": lid.0, "prop": transform, "selectKeys": false})).unwrap();+ s.execute("edit.copy", json!({})).unwrap();+ s.state.keyframe_text.clone().unwrap()+}++fn names(text: &str) -> Vec<&str> {+ text.lines().filter_map(|line| line.strip_prefix("Transform\t")).collect()+}++#[test]+fn properties_the_layer_does_not_use_are_left_out() {+ // Separate Dimensions: the old Position no longer moves the layer.+ let (mut s, l) = session();+ s.execute("prop.set", json!({"layer": l.0, "path": "transform/position", "value": [100, 200]})).unwrap();+ s.execute("prop.separateDimensions", json!({"layer": l.0, "value": true})).unwrap();+ s.execute("prop.set", json!({"layer": l.0, "path": "transform/positionX", "value": 321})).unwrap();+ let text = copy_transform(&mut s, l);+ assert!(!names(&text).contains(&"Position"), "{text}");+ // A one-node camera has no Point of Interest; a two-node one does.+ let cam = LayerId(s.execute("layer.newCamera", json!({"type": "oneNode"})).unwrap()["layer"].as_u64().unwrap());+ let text = copy_transform(&mut s, cam);+ assert!(!names(&text).contains(&"Point of Interest"), "{text}");+ s.execute("layer.cameraSettings", json!({"layer": cam.0, "type": "twoNode"})).unwrap();+ let text = copy_transform(&mut s, cam);+ assert!(names(&text).contains(&"Point of Interest"), "{text}");+}+#[test]fn keys_from_two_layers_have_no_text() {let (mut s, a) = session();