Skip to main content

oxihuman_export/
compositor_export.rs

1// Copyright (C) 2026 COOLJAPAN OU (Team KitaSan)
2// SPDX-License-Identifier: Apache-2.0
3#![allow(dead_code)]
4
5//! Compositor node tree export settings.
6
7/* ── legacy API (kept) ── */
8
9pub struct CompositorExport {
10    pub use_compositor: bool,
11    pub use_sequencer: bool,
12    pub use_nodes: bool,
13    pub node_count: u32,
14}
15
16pub fn default_compositor_export() -> CompositorExport {
17    CompositorExport {
18        use_compositor: true,
19        use_sequencer: false,
20        use_nodes: true,
21        node_count: 0,
22    }
23}
24
25pub fn export_compositor_to_json(c: &CompositorExport) -> String {
26    format!(
27        r#"{{"use_compositor":{},"use_sequencer":{},"use_nodes":{},"node_count":{}}}"#,
28        c.use_compositor, c.use_sequencer, c.use_nodes, c.node_count
29    )
30}
31
32/* ── spec functions (wave 150B) ── */
33
34/// Spec-style compositor node.
35#[derive(Debug, Clone)]
36pub struct CompositorNode {
37    pub name: String,
38    pub node_type: String,
39    pub inputs: Vec<String>,
40    pub outputs: Vec<String>,
41    pub is_output: bool,
42}
43
44/// Create a new `CompositorNode`.
45pub fn new_compositor_node(name: &str, node_type: &str) -> CompositorNode {
46    CompositorNode {
47        name: name.to_string(),
48        node_type: node_type.to_string(),
49        inputs: Vec::new(),
50        outputs: Vec::new(),
51        is_output: false,
52    }
53}
54
55/// Add an input socket name.
56pub fn comp_push_input(node: &mut CompositorNode, input: &str) {
57    node.inputs.push(input.to_string());
58}
59
60/// Add an output socket name.
61pub fn comp_push_output(node: &mut CompositorNode, output: &str) {
62    node.outputs.push(output.to_string());
63}
64
65/// Serialize a single node to JSON.
66pub fn comp_node_to_json(n: &CompositorNode) -> String {
67    format!(
68        "{{\"name\":\"{}\",\"type\":\"{}\",\"inputs\":{},\"outputs\":{},\"is_output\":{}}}",
69        n.name,
70        n.node_type,
71        n.inputs.len(),
72        n.outputs.len(),
73        n.is_output
74    )
75}
76
77/// Serialize multiple nodes to a JSON array.
78pub fn comp_nodes_to_json(nodes: &[CompositorNode]) -> String {
79    let inner: Vec<String> = nodes.iter().map(comp_node_to_json).collect();
80    format!("[{}]", inner.join(","))
81}
82
83/// Returns true if the node is an output node.
84pub fn comp_node_is_output(n: &CompositorNode) -> bool {
85    n.is_output
86}
87
88#[cfg(test)]
89mod tests {
90    use super::*;
91
92    #[test]
93    fn test_new_compositor_node() {
94        let n = new_compositor_node("output", "CompositorNodeComposite");
95        assert_eq!(n.name, "output");
96    }
97
98    #[test]
99    fn test_comp_push_input() {
100        let mut n = new_compositor_node("n", "T");
101        comp_push_input(&mut n, "Image");
102        assert_eq!(n.inputs.len(), 1);
103    }
104
105    #[test]
106    fn test_comp_push_output() {
107        let mut n = new_compositor_node("n", "T");
108        comp_push_output(&mut n, "Value");
109        assert_eq!(n.outputs.len(), 1);
110    }
111
112    #[test]
113    fn test_comp_node_to_json() {
114        let n = new_compositor_node("blur", "Blur");
115        let j = comp_node_to_json(&n);
116        assert!(j.contains("blur"));
117    }
118
119    #[test]
120    fn test_comp_node_is_output() {
121        let mut n = new_compositor_node("out", "Composite");
122        n.is_output = true;
123        assert!(comp_node_is_output(&n));
124    }
125}