Skip to content

Commit 03206d6

Browse files
committed
Bug fixes and code review
1 parent 4d120e5 commit 03206d6

File tree

9 files changed

+363
-375
lines changed

9 files changed

+363
-375
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -366,23 +366,23 @@ impl<'a> ModifyInputsContext<'a> {
366366
}
367367

368368
pub fn blend_mode_set(&mut self, blend_mode: BlendMode) {
369-
let Some(blend_node_id) = self.existing_node_id(&DefinitionIdentifier::ProtoNode(graphene_std::raster_nodes::blending_nodes::blend::IDENTIFIER), true) else {
369+
let Some(blend_node_id) = self.existing_node_id(&DefinitionIdentifier::ProtoNode(graphene_std::blending_nodes::blending::IDENTIFIER), true) else {
370370
return;
371371
};
372372
let input_connector = InputConnector::node(blend_node_id, 1);
373373
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::BlendMode(blend_mode), false), false);
374374
}
375375

376376
pub fn opacity_set(&mut self, opacity: f64) {
377-
let Some(blend_node_id) = self.existing_node_id(&DefinitionIdentifier::ProtoNode(graphene_std::raster_nodes::blending_nodes::blend::IDENTIFIER), true) else {
377+
let Some(blend_node_id) = self.existing_node_id(&DefinitionIdentifier::ProtoNode(graphene_std::blending_nodes::blending::IDENTIFIER), true) else {
378378
return;
379379
};
380380
let input_connector = InputConnector::node(blend_node_id, 2);
381381
self.set_input_with_refresh(input_connector, NodeInput::value(TaggedValue::F64(opacity * 100.), false), false);
382382
}
383383

384384
pub fn blending_fill_set(&mut self, fill: f64) {
385-
let Some(blend_node_id) = self.existing_node_id(&DefinitionIdentifier::ProtoNode(graphene_std::raster_nodes::blending_nodes::blend::IDENTIFIER), true) else {
385+
let Some(blend_node_id) = self.existing_node_id(&DefinitionIdentifier::ProtoNode(graphene_std::blending_nodes::blending::IDENTIFIER), true) else {
386386
return;
387387
};
388388
let input_connector = InputConnector::node(blend_node_id, 3);
@@ -391,7 +391,7 @@ impl<'a> ModifyInputsContext<'a> {
391391

392392
pub fn clip_mode_toggle(&mut self, clip_mode: Option<bool>) {
393393
let clip = !clip_mode.unwrap_or(false);
394-
let Some(clip_node_id) = self.existing_node_id(&DefinitionIdentifier::ProtoNode(graphene_std::raster_nodes::blending_nodes::blend::IDENTIFIER), true) else {
394+
let Some(clip_node_id) = self.existing_node_id(&DefinitionIdentifier::ProtoNode(graphene_std::blending_nodes::blending::IDENTIFIER), true) else {
395395
return;
396396
};
397397
let input_connector = InputConnector::node(clip_node_id, 4);

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl From<Value> for DefinitionIdentifier {
9595
/// TODO: Use this to prevent storing a copy of the implementation, if the document node is unchanged from the definition.
9696
#[derive(Debug, Clone)]
9797
pub struct DocumentNodeDefinition {
98-
/// Used to create the DefinitionIdentifier::Network identifer
98+
/// Used to create the DefinitionIdentifier::Network identifier
9999
pub identifier: &'static str,
100100

101101
/// All data required to construct a [`DocumentNode`] and [`DocumentNodeMetadata`]
@@ -113,12 +113,13 @@ pub struct DocumentNodeDefinition {
113113
pub properties: Option<&'static str>,
114114
}
115115

116-
// We use the once cell to use the document node definitions through the editor without passing a reference
116+
// We use the once cell to use the document node definitions throughout the editor without passing a reference
117117
// TODO: If dynamic node library is required, use a Mutex as well
118118
static DOCUMENT_NODE_TYPES: once_cell::sync::Lazy<HashMap<DefinitionIdentifier, DocumentNodeDefinition>> = once_cell::sync::Lazy::new(node_definitions);
119119

120120
/// Defines the "signature" or "header file"-like metadata for the document nodes, but not the implementation (which is defined in the node registry).
121121
/// The [`DocumentNode`] is the instance while these [`DocumentNodeDefinition`]s are the "classes" or "blueprints" from which the instances are built.
122+
/// Only the position can be set for protonodes within a definition. The rest of the metadata comes from the node macro in NODE_METADATA
122123
fn node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefinition> {
123124
let custom = vec![
124125
// TODO: Auto-generate this from its proto node macro
@@ -2636,15 +2637,19 @@ pub fn resolve_document_node_type(identifier: &DefinitionIdentifier) -> Option<&
26362637
DOCUMENT_NODE_TYPES.get(identifier)
26372638
}
26382639

2639-
pub fn default_display_name(identifier: &DefinitionIdentifier) -> String {
2640+
pub fn implementation_name_from_identifier(identifier: &DefinitionIdentifier) -> String {
26402641
match identifier {
26412642
DefinitionIdentifier::Network(name) => name.clone(),
26422643
DefinitionIdentifier::ProtoNode(proto_node_identifier) => registry::NODE_METADATA
26432644
.lock()
26442645
.unwrap()
26452646
.get(proto_node_identifier)
26462647
.map(|metadata| metadata.display_name.to_string())
2647-
.unwrap_or_default(),
2648+
.unwrap_or_else(|| {
2649+
let mut last_segment = proto_node_identifier.name.split("::").last().unwrap_or_default().to_string();
2650+
last_segment = last_segment.strip_suffix("Node").unwrap_or(&last_segment).to_string();
2651+
last_segment
2652+
}),
26482653
}
26492654
}
26502655

@@ -2660,10 +2665,13 @@ pub fn collect_node_types() -> Vec<FrontendNodeType> {
26602665
.iter()
26612666
.map(|node_input| node_input.as_value().map(|node_value| node_value.ty().nested_type().to_string()).unwrap_or_default())
26622667
.collect::<Vec<String>>();
2663-
2668+
let mut name = definition.node_template.persistent_node_metadata.display_name.clone();
2669+
if name.is_empty() {
2670+
name = implementation_name_from_identifier(identifier)
2671+
}
26642672
FrontendNodeType {
26652673
identifier: identifier.clone(),
2666-
name: default_display_name(identifier),
2674+
name,
26672675
category: definition.category.to_string(),
26682676
input_types,
26692677
}

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ pub(super) fn post_process_nodes(custom: Vec<DocumentNodeDefinition>) -> HashMap
2525
// Add the rest of the protonodes from the macro
2626
let node_registry = NODE_REGISTRY.lock().unwrap();
2727
for (id, metadata) in NODE_METADATA.lock().unwrap().iter() {
28+
let identifier = DefinitionIdentifier::ProtoNode(id.clone());
29+
if definitions_map.contains_key(&identifier) {
30+
continue;
31+
};
2832
let NodeMetadata {
2933
display_name,
3034
category,
@@ -43,7 +47,7 @@ pub(super) fn post_process_nodes(custom: Vec<DocumentNodeDefinition>) -> HashMap
4347

4448
let inputs = preprocessor::node_inputs(fields, first_node_io);
4549
definitions_map.insert(
46-
DefinitionIdentifier::ProtoNode(id.clone()),
50+
identifier,
4751
DocumentNodeDefinition {
4852
identifier: display_name,
4953
node_template: NodeTemplate {
@@ -78,6 +82,16 @@ pub(super) fn post_process_nodes(custom: Vec<DocumentNodeDefinition>) -> HashMap
7882
);
7983
}
8084

85+
// If any protonode does not have metadata then set its display name to its identifier string
86+
for definition in definitions_map.values_mut() {
87+
let metadata = NODE_METADATA.lock().unwrap();
88+
if let DocumentNodeImplementation::ProtoNode(id) = &definition.node_template.document_node.implementation {
89+
if !metadata.contains_key(id) {
90+
definition.node_template.persistent_node_metadata.display_name = definition.identifier.to_string();
91+
}
92+
}
93+
}
94+
8195
// Add the rest of the network nodes to the map and add the metadata for their internal protonodes
8296
for mut network_node in network_nodes {
8397
traverse_node(&network_node.node_template.document_node, &mut network_node.node_template.persistent_node_metadata, &definitions_map);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2578,6 +2578,7 @@ impl NodeGraphMessageHandler {
25782578
can_be_layer: network_interface.is_eligible_to_be_layer(&node_id, breadcrumb_network_path),
25792579
reference: network_interface.reference(&node_id, breadcrumb_network_path),
25802580
display_name: network_interface.display_name(&node_id, breadcrumb_network_path),
2581+
implementation_name: network_interface.implementation_name(&node_id, breadcrumb_network_path),
25812582
primary_input,
25822583
exposed_inputs,
25832584
primary_output,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ pub struct FrontendNode {
8383
pub reference: Option<DefinitionIdentifier>,
8484
#[serde(rename = "displayName")]
8585
pub display_name: String,
86+
#[serde(rename = "implementationName")]
87+
pub implementation_name: String,
8688
#[serde(rename = "primaryInput")]
8789
pub primary_input: Option<FrontendGraphInput>,
8890
#[serde(rename = "exposedInputs")]

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

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use super::misc::PTZ;
77
use super::nodes::SelectedNodes;
88
use crate::consts::{EXPORTS_TO_RIGHT_EDGE_PIXEL_GAP, EXPORTS_TO_TOP_EDGE_PIXEL_GAP, GRID_SIZE, IMPORTS_TO_LEFT_EDGE_PIXEL_GAP, IMPORTS_TO_TOP_EDGE_PIXEL_GAP};
99
use crate::messages::portfolio::document::graph_operation::utility_types::ModifyInputsContext;
10-
use crate::messages::portfolio::document::node_graph::document_node_definitions::{DefinitionIdentifier, DocumentNodeDefinition, default_display_name, resolve_document_node_type};
10+
use crate::messages::portfolio::document::node_graph::document_node_definitions::{DefinitionIdentifier, implementation_name_from_identifier, resolve_document_node_type};
1111
use crate::messages::portfolio::document::node_graph::utility_types::{Direction, FrontendClickTargets, FrontendGraphDataType, FrontendGraphInput, FrontendGraphOutput};
1212
use crate::messages::portfolio::document::utility_types::network_interface::resolved_types::ResolvedDocumentNodeTypes;
1313
use crate::messages::portfolio::document::utility_types::wires::{GraphWireStyle, WirePath, WirePathUpdate, build_vector_wire};
@@ -18,7 +18,6 @@ use glam::{DAffine2, DVec2, IVec2};
1818
use graph_craft::Type;
1919
use graph_craft::document::value::TaggedValue;
2020
use graph_craft::document::{DocumentNode, DocumentNodeImplementation, NodeId, NodeInput, NodeNetwork, OldDocumentNodeImplementation, OldNodeNetwork};
21-
use graph_craft::proto::NODE_METADATA;
2221
use graphene_std::ContextDependencies;
2322
use graphene_std::math::quad::Quad;
2423
use graphene_std::subpath::Subpath;
@@ -470,33 +469,6 @@ impl NodeNetworkInterface {
470469
node_template
471470
}
472471

473-
/// Try and get the [`DocumentNodeDefinition`] for a node
474-
pub fn node_definition(&self, node_id: &NodeId, network_path: &[NodeId]) -> Option<&DocumentNodeDefinition> {
475-
let implementation = self.implementation(node_id, network_path)?;
476-
match implementation {
477-
DocumentNodeImplementation::Network(_) => {
478-
let metadata = self.node_metadata(node_id, network_path)?;
479-
let metadata = metadata.persistent_metadata.network_metadata.as_ref()?;
480-
let reference = metadata.persistent_metadata.reference.clone()?;
481-
let identifier = DefinitionIdentifier::Network(reference.clone());
482-
let Some(definition) = resolve_document_node_type(&identifier) else {
483-
log::error!("Could not get definition for node id {node_id} with reference {reference}");
484-
return None;
485-
};
486-
Some(definition)
487-
}
488-
DocumentNodeImplementation::ProtoNode(proto_node_identifier) => {
489-
let identifier = DefinitionIdentifier::ProtoNode(proto_node_identifier.clone());
490-
let Some(definition) = resolve_document_node_type(&identifier) else {
491-
log::error!("Could not get definition for node id {node_id} with proto_node_identifier {proto_node_identifier}");
492-
return None;
493-
};
494-
Some(definition)
495-
}
496-
DocumentNodeImplementation::Extract => None,
497-
}
498-
}
499-
500472
pub fn input_from_connector(&self, input_connector: &InputConnector, network_path: &[NodeId]) -> Option<&NodeInput> {
501473
let Some(network) = self.nested_network(network_path) else {
502474
log::error!("Could not get network in input_from_connector");
@@ -956,7 +928,7 @@ impl NodeNetworkInterface {
956928
.persistent_metadata
957929
.reference
958930
.clone()
959-
.map(|reference| DefinitionIdentifier::Network(reference))
931+
.map(DefinitionIdentifier::Network)
960932
}
961933
DocumentNodeImplementation::ProtoNode(protonode_id) => Some(DefinitionIdentifier::ProtoNode(protonode_id.clone())),
962934
_ => None,
@@ -1044,7 +1016,7 @@ impl NodeNetworkInterface {
10441016
/// The uneditable name in the properties panel which represents the function name of the node implementation
10451017
pub fn implementation_name(&self, node_id: &NodeId, network_path: &[NodeId]) -> String {
10461018
self.reference(&node_id, network_path)
1047-
.map(|identifier| default_display_name(&identifier))
1019+
.map(|identifier| implementation_name_from_identifier(&identifier))
10481020
.unwrap_or("Custom Node".to_string())
10491021
}
10501022

@@ -3795,7 +3767,9 @@ impl NodeNetworkInterface {
37953767
let Some(metadata) = self.node_metadata_mut(node_id, network_path) else { return };
37963768
for added_input_index in metadata.persistent_metadata.input_metadata.len()..number_of_inputs {
37973769
let input_metadata = self
3798-
.node_definition(node_id, network_path)
3770+
.reference(node_id, network_path)
3771+
.as_ref()
3772+
.and_then(resolve_document_node_type)
37993773
.and_then(|definition| definition.node_template.persistent_node_metadata.input_metadata.get(added_input_index))
38003774
.cloned();
38013775
let Some(metadata) = self.node_metadata_mut(node_id, network_path) else { return };
@@ -6277,7 +6251,8 @@ struct InputTransientMetadata {
62776251
/// Persistent metadata for each node in the network, which must be included when creating, serializing, and deserializing saving a node.
62786252
#[derive(Default, Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)]
62796253
pub struct DocumentNodePersistentMetadata {
6280-
/// A name chosen by the user for this instance of the node. Empty indicates no given name, in which case the reference name is displayed to the user in italics.
6254+
/// A name chosen by the user for this instance of the node. Empty indicates no given name, in which case the implementation name is displayed to the user in italics.
6255+
/// This is empty for all newly created nodes, except protonodes with #[skip_impl]
62816256
#[serde(default)]
62826257
pub display_name: String,
62836258
/// Stores metadata to override the properties in the properties panel for each input. These can either be generated automatically based on the type, or with a custom function.

0 commit comments

Comments
 (0)