PhotoCraft: An open-source, photo editor written by scratch in pure Rust
document.inspect reports video layers (frames, fps, source) for agents
Brandon Thomasaf3cdfd05cca
diff --git a/crates/engine/src/inspect.rs b/crates/engine/src/inspect.rsindex 2dd093c08..79fdf3b31 100644--- a/crates/engine/src/inspect.rs+++ b/crates/engine/src/inspect.rs@@ -112,5 +112,13 @@ fn layer_sel(l: &Layer, selected: &[photocraft_doc::LayerId]) -> Value {"items": l.effects.items.iter().map(|e| json!({"kind": e.label(), "enabled": e.enabled()})).collect::<Vec<_>>(),});}+ // Video layer (Layer › Video Layers): the frame stack behind the displayed content.+ if let Some(vid) = &l.video {+ let source = match &vid.source {+ photocraft_doc::VideoSource::Blank => Value::String("blank".into()),+ photocraft_doc::VideoSource::File { path } => json!({ "file": path }),+ };+ v["video"] = json!({"frames": vid.frames.len(), "fps": vid.fps, "showAltered": vid.show_altered, "source": source});+ }v}diff --git a/crates/engine/src/video_cmds/tests.rs b/crates/engine/src/video_cmds/tests.rsindex ccab39201..f2f8bb13c 100644--- a/crates/engine/src/video_cmds/tests.rs+++ b/crates/engine/src/video_cmds/tests.rs@@ -115,3 +115,24 @@ fn render_video_to_animated_gif() {assert_eq!(&gif[..6], b"GIF89a");assert_eq!(gif.iter().filter(|&&b| b == 0x2C).count(), 3); // 3 frames}++#[test]+fn inspect_reports_video_layer() {+ let dir = tmpdir("vinsp");+ write_png(&format!("{dir}/a.png"), 6, 4, "#ff0000");+ write_png(&format!("{dir}/b.png"), 6, 4, "#00ff00");+ let mut s = session();+ s.execute("layer.videoLayers.newVideoLayerFromFile", json!({"path": dir})).unwrap();+ let r = s.execute("document.inspect", json!({})).unwrap();+ // Find any layer node carrying a "video" block.+ fn find_video(v: &serde_json::Value) -> Option<serde_json::Value> {+ if let Some(vid) = v.get("video") {+ return Some(vid.clone());+ }+ v.get("children").and_then(|c| c.as_array()).and_then(|a| a.iter().find_map(find_video))+ }+ let layers = r["layers"].as_array().expect("layers array");+ let vid = layers.iter().find_map(find_video).expect("a video layer is reported");+ assert_eq!(vid["frames"], 2);+ assert_eq!(vid["source"]["file"].as_str(), Some(dir.as_str()));+}