Files
materialcraft/crates/engine/tests/exposed_inputs.rs
T
Belligerently 3be36016d2 Let a parameter be exposed as a graph input on more than one node
The properties panel's "Expose as graph input" sent the bare parameter
id as the new input's id, so exposing Opacity on a second Blend node
failed with "an input is already called `opacity`". graph.exposed.add
now accepts a bound input without an id and names it after the
parameter, kept unique (opacity, opacity_1, ...), and the menu relies on
that. An explicit id must still be free.
2026-11-06 23:42:57 -05:00

29 lines
1.3 KiB
Rust

use materialcraft_engine::{core::NodeId, execute, new_session};
use serde_json::json;
#[test]
fn exposing_the_same_parameter_on_two_nodes_gives_each_its_own_input() {
let mut s = new_session();
let nodes: Vec<NodeId> = (0..3).map(|_| NodeId(execute(&mut s, "graph.node.add", &json!({"def": "blend"})).unwrap()["id"].as_u64().unwrap())).collect();
// The properties panel's "Expose as graph input" sends no `id`
let ids: Vec<String> = nodes
.iter()
.map(|node| {
let reply = execute(&mut s, "graph.exposed.add", &json!({"label": "Opacity", "bind": {"node": node.0, "param": "opacity"}})).unwrap();
reply["id"].as_str().unwrap().to_string()
})
.collect();
assert_eq!(ids, ["opacity", "opacity_1", "opacity_2"]);
let graph = s.graph().unwrap();
assert_eq!(graph.exposed.iter().map(|e| e.id.as_str()).collect::<Vec<_>>(), ids);
for (node, id) in nodes.iter().zip(&ids) {
assert_eq!(graph.node(*node).unwrap().bindings.get("opacity"), Some(id));
}
// An explicit id still has to be free, and an unbound input still needs one
assert!(execute(&mut s, "graph.exposed.add", &json!({"id": "opacity_1", "bind": {"node": nodes[0].0, "param": "opacity"}})).is_err());
assert!(execute(&mut s, "graph.exposed.add", &json!({"default": 0.5})).is_err());
}