Skip to content

Commit 69372a6

Browse files
committed
Code review
1 parent a0e58b9 commit 69372a6

2 files changed

Lines changed: 17 additions & 18 deletions

File tree

editor/src/messages/portfolio/document/node_graph/document_node_definitions.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ mod document_node_derive;
22

33
use super::node_properties::choice::enum_choice;
44
use super::node_properties::{self, ParameterWidgetsInfo};
5-
use super::utility_types::{FrontendNodeType, FrontendTypeConstraintForInput};
5+
use super::utility_types::{FrontendNodeType, InputTypeConstraint};
66
use crate::messages::layout::utility_types::widget_prelude::*;
77
use crate::messages::portfolio::document::utility_types::network_interface::{
88
DocumentNodeMetadata, DocumentNodePersistentMetadata, InputMetadata, NodeNetworkInterface, NodeNetworkMetadata, NodeNetworkPersistentMetadata, NodeTemplate, NodeTypePersistentMetadata,
@@ -2017,7 +2017,7 @@ pub fn resolve_document_node_type(identifier: &DefinitionIdentifier) -> Option<&
20172017
DOCUMENT_NODE_TYPES.get(identifier)
20182018
}
20192019

2020-
impl FrontendTypeConstraintForInput {
2020+
impl InputTypeConstraint {
20212021
#[must_use]
20222022
fn type_name(ty: &Type) -> String {
20232023
ty.nested_type().to_string()
@@ -2071,10 +2071,10 @@ impl FrontendTypeConstraintForInput {
20712071
// TODO: This does not consider the constrains by nodes not directly connected to the import
20722072
DocumentNodeImplementation::Network(nested_network) => {
20732073
// Find all inputs connected to the relevant import
2074-
fn valid_types_from_node(child_node: &DocumentNode, name: &str, input_index: usize) -> impl Iterator<Item = FrontendTypeConstraintForInput> {
2074+
fn valid_types_from_node(child_node: &DocumentNode, name: &str, input_index: usize) -> impl Iterator<Item = InputTypeConstraint> {
20752075
let all_inputs = child_node.inputs.iter().enumerate();
20762076
let input_for_import = all_inputs.filter(move |(_, child_input)| matches!(child_input, NodeInput::Import { import_index, .. } if *import_index == input_index));
2077-
input_for_import.map(move |(index, _)| FrontendTypeConstraintForInput::compute_constraint_for_input(child_node, name, index))
2077+
input_for_import.map(move |(index, _)| InputTypeConstraint::compute_constraint_for_input(child_node, name, index))
20782078
}
20792079
let all_type_constraints = nested_network.nodes.values().flat_map(|node| valid_types_from_node(node, name, input_index));
20802080
// The type fed to the network must satisfy all protonodes it is connected to
@@ -2142,7 +2142,7 @@ pub fn collect_node_types() -> Vec<FrontendNodeType> {
21422142
}
21432143
FrontendNodeType {
21442144
identifier: identifier.serialized(),
2145-
input_types: FrontendTypeConstraintForInput::constraints_for_all_inputs(&definition.node_template.document_node, &name),
2145+
input_types: InputTypeConstraint::constraints_for_all_inputs(&definition.node_template.document_node, &name),
21462146
name,
21472147
category: definition.category.to_string(),
21482148
}
@@ -2273,9 +2273,9 @@ mod test {
22732273
}
22742274

22752275
#[cfg(test)]
2276-
mod test_frontend_type_constraints {
2276+
mod test_type_constraints {
22772277
use crate::messages::portfolio::document::node_graph::document_node_definitions::resolve_proto_node_type;
2278-
use crate::messages::portfolio::document::node_graph::utility_types::FrontendTypeConstraintForInput;
2278+
use crate::messages::portfolio::document::node_graph::utility_types::InputTypeConstraint;
22792279
use crate::test_utils::test_prelude::*;
22802280
use graph_craft::NodeNetwork;
22812281
use graph_craft::document::{DocumentNodeImplementation, NodeId, NodeInput};
@@ -2284,27 +2284,27 @@ mod test_frontend_type_constraints {
22842284
#[test]
22852285
fn passthrough() {
22862286
let node_type = resolve_proto_node_type(graphene_std::ops::passthrough::IDENTIFIER).expect("passthrough node");
2287-
let constraint = FrontendTypeConstraintForInput::constraints_for_all_inputs(&node_type.node_template.document_node, "name");
2288-
assert_eq!(constraint, vec![FrontendTypeConstraintForInput::All]);
2287+
let constraint = InputTypeConstraint::constraints_for_all_inputs(&node_type.node_template.document_node, "name");
2288+
assert_eq!(constraint, vec![InputTypeConstraint::All]);
22892289
}
22902290

22912291
#[test]
22922292
fn tangent_inverse() {
22932293
let node_type = resolve_proto_node_type(graphene_std::math_nodes::tangent_inverse::IDENTIFIER).expect("tangent inverse node");
2294-
let constraint = FrontendTypeConstraintForInput::constraints_for_all_inputs(&node_type.node_template.document_node, "name");
2294+
let constraint = InputTypeConstraint::constraints_for_all_inputs(&node_type.node_template.document_node, "name");
22952295
assert_eq!(
22962296
constraint,
22972297
vec![
2298-
FrontendTypeConstraintForInput::new(&[concrete!(glam::DVec2), concrete!(f32), concrete!(f64)]),
2299-
FrontendTypeConstraintForInput::new(&[concrete!(bool)])
2298+
InputTypeConstraint::new(&[concrete!(glam::DVec2), concrete!(f32), concrete!(f64)]),
2299+
InputTypeConstraint::new(&[concrete!(bool)])
23002300
]
23012301
);
23022302
}
23032303

23042304
#[test]
23052305
fn fill() {
23062306
let node_type = resolve_proto_node_type(graphene_std::graphic_nodes::index_elements::IDENTIFIER).expect("Index Elements node");
2307-
let constraint = FrontendTypeConstraintForInput::compute_constraint_for_input(&node_type.node_template.document_node, "name", 0);
2307+
let constraint = InputTypeConstraint::compute_constraint_for_input(&node_type.node_template.document_node, "name", 0);
23082308
assert!(constraint.satisfies(&concrete!(graphene_std::list::List<String>)));
23092309
assert!(constraint.satisfies(&concrete!(graphene_std::list::List<f64>)));
23102310
assert!(!constraint.satisfies(&concrete!(f64)));
@@ -2327,7 +2327,7 @@ mod test_frontend_type_constraints {
23272327
implementation: DocumentNodeImplementation::Network(inner_network),
23282328
..Default::default()
23292329
};
2330-
let constraint = FrontendTypeConstraintForInput::compute_constraint_for_input(&node, "name", 0);
2331-
assert_eq!(constraint, FrontendTypeConstraintForInput::new(&[concrete!(f32), concrete!(f64)]),);
2330+
let constraint = InputTypeConstraint::compute_constraint_for_input(&node, "name", 0);
2331+
assert_eq!(constraint, InputTypeConstraint::new(&[concrete!(f32), concrete!(f64)]),);
23322332
}
23332333
}

editor/src/messages/portfolio/document/node_graph/utility_types.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ pub struct FrontendNode {
104104

105105
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
106106
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
107-
/// Each input may accept many types
108-
pub enum FrontendTypeConstraintForInput {
107+
pub enum InputTypeConstraint {
109108
Limited(std::collections::BTreeSet<String>),
110109
All,
111110
}
@@ -117,7 +116,7 @@ pub struct FrontendNodeType {
117116
pub name: String,
118117
pub category: String,
119118
#[serde(rename = "inputTypes")]
120-
pub input_types: Vec<FrontendTypeConstraintForInput>,
119+
pub input_types: Vec<InputTypeConstraint>,
121120
}
122121

123122
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]

0 commit comments

Comments
 (0)