mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-22 06:08:11 +08:00
Clean up code for optional node inputs/outputs
This removes the unused Split Channels node's primary output
This commit is contained in:
@@ -58,14 +58,14 @@ impl FrontendGraphDataType {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub struct NodeGraphInput {
|
||||
pub struct FrontendGraphInput {
|
||||
#[serde(rename = "dataType")]
|
||||
data_type: FrontendGraphDataType,
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize, specta::Type)]
|
||||
pub struct NodeGraphOutput {
|
||||
pub struct FrontendGraphOutput {
|
||||
#[serde(rename = "dataType")]
|
||||
data_type: FrontendGraphDataType,
|
||||
name: String,
|
||||
@@ -77,13 +77,13 @@ pub struct FrontendNode {
|
||||
#[serde(rename = "displayName")]
|
||||
pub display_name: String,
|
||||
#[serde(rename = "primaryInput")]
|
||||
pub primary_input: Option<FrontendGraphDataType>,
|
||||
pub primary_input: Option<FrontendGraphInput>,
|
||||
#[serde(rename = "exposedInputs")]
|
||||
pub exposed_inputs: Vec<NodeGraphInput>,
|
||||
pub exposed_inputs: Vec<FrontendGraphInput>,
|
||||
#[serde(rename = "primaryOutput")]
|
||||
pub primary_output: Option<NodeGraphOutput>,
|
||||
pub primary_output: Option<FrontendGraphOutput>,
|
||||
#[serde(rename = "exposedOutputs")]
|
||||
pub exposed_outputs: Vec<NodeGraphOutput>,
|
||||
pub exposed_outputs: Vec<FrontendGraphOutput>,
|
||||
pub position: (i32, i32),
|
||||
pub disabled: bool,
|
||||
pub previewed: bool,
|
||||
@@ -291,34 +291,26 @@ impl NodeGraphMessageHandler {
|
||||
|
||||
let mut nodes = Vec::new();
|
||||
for (id, node) in &network.nodes {
|
||||
// TODO: This should be based on the graph runtime type inference system in order to change the colors of node connectors to match the data type in use
|
||||
let Some(node_type) = document_node_types::resolve_document_node_type(&node.name) else {
|
||||
warn!("Node '{}' does not exist in library", node.name);
|
||||
continue;
|
||||
};
|
||||
|
||||
let primary_input = node
|
||||
.inputs
|
||||
.first()
|
||||
.filter(|input| input.is_exposed())
|
||||
.and_then(|_| node_type.inputs.get(0))
|
||||
.map(|input_type| input_type.data_type);
|
||||
let exposed_inputs = node
|
||||
.inputs
|
||||
.iter()
|
||||
.zip(node_type.inputs.iter())
|
||||
.skip(1)
|
||||
.filter(|(input, _)| input.is_exposed())
|
||||
.map(|(_, input_type)| NodeGraphInput {
|
||||
data_type: input_type.data_type,
|
||||
name: input_type.name.to_string(),
|
||||
})
|
||||
.collect();
|
||||
// Inputs
|
||||
let mut inputs = node.inputs.iter().zip(node_type.inputs.iter().map(|input_type| FrontendGraphInput {
|
||||
data_type: input_type.data_type,
|
||||
name: input_type.name.to_string(),
|
||||
}));
|
||||
let primary_input = inputs.next().filter(|(input, _)| input.is_exposed()).map(|(_, input_type)| input_type);
|
||||
let exposed_inputs = inputs.filter(|(input, _)| input.is_exposed()).map(|(_, input_type)| input_type).collect();
|
||||
|
||||
let mut outputs = node_type.outputs.iter().map(|output_type| NodeGraphOutput {
|
||||
// Outputs
|
||||
let mut outputs = node_type.outputs.iter().map(|output_type| FrontendGraphOutput {
|
||||
data_type: output_type.data_type,
|
||||
name: output_type.name.to_string(),
|
||||
});
|
||||
let primary_output = outputs.next();
|
||||
let primary_output = if node.has_primary_output { outputs.next() } else { None };
|
||||
|
||||
let _graph_identifier = GraphIdentifier::new(layer_id);
|
||||
|
||||
|
||||
+4
-10
@@ -101,7 +101,7 @@ pub struct DocumentNodeType {
|
||||
pub identifier: NodeImplementation,
|
||||
pub inputs: Vec<DocumentInputType>,
|
||||
pub outputs: Vec<DocumentOutputType>,
|
||||
pub primary_output: bool,
|
||||
pub has_primary_output: bool,
|
||||
pub properties: fn(&DocumentNode, NodeId, &mut NodePropertiesContext) -> Vec<LayoutGroup>,
|
||||
pub manual_composition: Option<graphene_core::Type>,
|
||||
}
|
||||
@@ -114,7 +114,7 @@ impl Default for DocumentNodeType {
|
||||
identifier: Default::default(),
|
||||
inputs: Default::default(),
|
||||
outputs: Default::default(),
|
||||
primary_output: Default::default(),
|
||||
has_primary_output: true,
|
||||
properties: node_properties::no_properties,
|
||||
manual_composition: Default::default(),
|
||||
}
|
||||
@@ -836,12 +836,6 @@ fn static_nodes() -> Vec<DocumentNodeType> {
|
||||
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::raster::ExtractAlphaNode<>")),
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNode {
|
||||
name: "EmptyOutput".to_string(),
|
||||
inputs: vec![NodeInput::value(TaggedValue::ImageFrame(ImageFrame::empty()), false)],
|
||||
implementation: DocumentNodeImplementation::Unresolved(NodeIdentifier::new("graphene_core::ops::IdNode")),
|
||||
..Default::default()
|
||||
},
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
@@ -852,13 +846,12 @@ fn static_nodes() -> Vec<DocumentNodeType> {
|
||||
}),
|
||||
inputs: vec![DocumentInputType::value("Image", TaggedValue::ImageFrame(ImageFrame::empty()), true)],
|
||||
outputs: vec![
|
||||
DocumentOutputType::new("Empty", FrontendGraphDataType::Raster),
|
||||
DocumentOutputType::new("Red", FrontendGraphDataType::Raster),
|
||||
DocumentOutputType::new("Green", FrontendGraphDataType::Raster),
|
||||
DocumentOutputType::new("Blue", FrontendGraphDataType::Raster),
|
||||
DocumentOutputType::new("Alpha", FrontendGraphDataType::Raster),
|
||||
],
|
||||
primary_output: false,
|
||||
has_primary_output: false,
|
||||
..Default::default()
|
||||
},
|
||||
DocumentNodeType {
|
||||
@@ -2468,6 +2461,7 @@ impl DocumentNodeType {
|
||||
DocumentNode {
|
||||
name: self.name.to_string(),
|
||||
inputs,
|
||||
has_primary_output: self.has_primary_output,
|
||||
implementation: self.generate_implementation(),
|
||||
metadata,
|
||||
manual_composition: self.manual_composition.clone(),
|
||||
|
||||
Reference in New Issue
Block a user