Skip to content

Commit fc7e515

Browse files
committed
Code review
1 parent e3ebaf9 commit fc7e515

File tree

9 files changed

+62
-86
lines changed

9 files changed

+62
-86
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ fn static_nodes() -> Vec<DocumentNodeDefinition> {
19391939
}),
19401940
input_metadata: vec![
19411941
("Vector Data", "The shape to be resampled and converted into a polyline.").into(),
1942-
(("Spacing", node_properties::SAMPLE_POLYLINE_TOOLTIP_SPACING)).into(),
1942+
("Spacing", node_properties::SAMPLE_POLYLINE_TOOLTIP_SPACING).into(),
19431943
InputMetadata::with_name_description_override(
19441944
"Separation",
19451945
node_properties::SAMPLE_POLYLINE_TOOLTIP_SEPARATION,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::DocumentNodeDefinition;
2-
use crate::messages::portfolio::document::utility_types::network_interface::InputMetadata;
3-
use crate::messages::portfolio::document::utility_types::network_interface::{DocumentNodePersistentMetadata, NodeTemplate, WidgetOverride};
2+
use crate::messages::portfolio::document::utility_types::network_interface::{DocumentNodePersistentMetadata, InputMetadata, NodeTemplate, WidgetOverride};
43
use graph_craft::ProtoNodeIdentifier;
54
use graph_craft::document::*;
65
use graphene_std::registry::*;

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::messages::portfolio::document::utility_types::misc::GroupFolderType;
1212
use crate::messages::portfolio::document::utility_types::network_interface::{
1313
self, InputConnector, NodeNetworkInterface, NodeTemplate, NodeTypePersistentMetadata, OutputConnector, Previewing, TypeSource,
1414
};
15-
use crate::messages::portfolio::document::utility_types::nodes::{CollapsedLayers, LayerPanelEntry, WirePath, WireUpdate};
15+
use crate::messages::portfolio::document::utility_types::nodes::{CollapsedLayers, LayerPanelEntry, WirePath, WireUpdate, build_wire_path};
1616
use crate::messages::prelude::*;
1717
use crate::messages::tool::common_functionality::auto_panning::AutoPanning;
1818
use crate::messages::tool::common_functionality::graph_modification_utils::get_clip_mode;
@@ -913,12 +913,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
913913
}
914914
});
915915
let wire_path = WirePath {
916-
path_string: crate::messages::portfolio::document::utility_types::nodes::build_wire_path(
917-
wire_in_progress_from_connector,
918-
wire_in_progress_to_connector,
919-
from_connector_is_layer,
920-
to_connector_is_layer,
921-
),
916+
path_string: build_wire_path(wire_in_progress_from_connector, wire_in_progress_to_connector, from_connector_is_layer, to_connector_is_layer),
922917
data_type: self.wire_in_progress_type,
923918
thick: false,
924919
dashed: false,
@@ -1379,7 +1374,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphHandlerData<'a>> for NodeGrap
13791374
let document_bbox = viewport_bbox.map(|p| network_metadata.persistent_metadata.navigation_metadata.node_graph_to_viewport.inverse().transform_point2(p));
13801375
self.current_nodes = Vec::new();
13811376
for node_id in &self.all_nodes {
1382-
let Some(node_bbox) = network_interface.node_bounding_box(&node_id, breadcrumb_network_path) else {
1377+
let Some(node_bbox) = network_interface.node_bounding_box(node_id, breadcrumb_network_path) else {
13831378
log::error!("Could not get bbox for node: {:?}", node_id);
13841379
continue;
13851380
};

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

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,9 +2053,7 @@ impl NodeNetworkInterface {
20532053
};
20542054
input_connectors.extend(outward_wires_for_import);
20552055
}
2056-
let Some(network) = self.nested_network(network_path) else {
2057-
return;
2058-
};
2056+
let Some(network) = self.nested_network(network_path) else { return };
20592057
for export_index in 0..network.exports.len() {
20602058
input_connectors.push(InputConnector::Export(export_index));
20612059
}
@@ -2506,7 +2504,7 @@ impl NodeNetworkInterface {
25062504
}
25072505
}
25082506

2509-
pub fn try_get_input_dom_rect(&mut self, input: &InputConnector, network_path: &[NodeId]) -> Option<(f64, f64, f64, f64)> {
2507+
pub fn try_get_input_rect(&mut self, input: &InputConnector, network_path: &[NodeId]) -> Option<(f64, f64, f64, f64)> {
25102508
let (ports, index) = match input {
25112509
InputConnector::Node { node_id, input_index } => {
25122510
let node_click_target = self.node_click_targets(node_id, network_path)?;
@@ -2520,10 +2518,10 @@ impl NodeNetworkInterface {
25202518
ports
25212519
.input_ports
25222520
.iter()
2523-
.find_map(|(input_index, click_target)| if index == input_index { click_target.to_dom_rect() } else { None })
2521+
.find_map(|(input_index, click_target)| if index == input_index { click_target.to_rect() } else { None })
25242522
}
25252523

2526-
pub fn try_get_output_dom_rect(&mut self, output: &OutputConnector, network_path: &[NodeId]) -> Option<(f64, f64, f64, f64)> {
2524+
pub fn try_get_output_rect(&mut self, output: &OutputConnector, network_path: &[NodeId]) -> Option<(f64, f64, f64, f64)> {
25272525
let (ports, index) = match output {
25282526
OutputConnector::Node { node_id, output_index } => {
25292527
let node_click_target = self.node_click_targets(node_id, network_path)?;
@@ -2537,18 +2535,21 @@ impl NodeNetworkInterface {
25372535
ports
25382536
.output_ports
25392537
.iter()
2540-
.find_map(|(input_index, click_target)| if index == input_index { click_target.to_dom_rect() } else { None })
2538+
.find_map(|(input_index, click_target)| if index == input_index { click_target.to_rect() } else { None })
25412539
}
25422540

25432541
pub fn newly_loaded_input_wire(&mut self, input: &InputConnector, network_path: &[NodeId]) -> Option<WireUpdate> {
2542+
#[allow(clippy::question_mark)]
25442543
if self.upstream_output_connector(input, network_path).is_none() {
25452544
return None;
25462545
}
2546+
25472547
if !self.wire_is_loaded(input, network_path) {
25482548
self.load_wire(input, network_path);
25492549
} else {
25502550
return None;
25512551
}
2552+
25522553
let wire = match input {
25532554
InputConnector::Node { node_id, input_index } => {
25542555
let input_metadata = self.transient_input_metadata(node_id, *input_index, network_path)?;
@@ -2608,25 +2609,19 @@ impl NodeNetworkInterface {
26082609
Previewing::No => false,
26092610
};
26102611

2611-
let Some(wire) = self.wire_path_from_input(input, dashed, network_path) else {
2612-
return;
2613-
};
2612+
let Some(wire) = self.wire_path_from_input(input, dashed, network_path) else { return };
26142613

26152614
match input {
26162615
InputConnector::Node { node_id, input_index } => {
2617-
let Some(node_metadata) = self.node_metadata_mut(node_id, network_path) else {
2618-
return;
2619-
};
2616+
let Some(node_metadata) = self.node_metadata_mut(node_id, network_path) else { return };
26202617
let Some(input_metadata) = node_metadata.persistent_metadata.input_metadata.get_mut(*input_index) else {
26212618
log::error!("Node metadata must exist on node: {input:?}");
26222619
return;
26232620
};
26242621
input_metadata.transient_metadata.wire = TransientMetadata::Loaded(wire);
26252622
}
26262623
InputConnector::Export(export_index) => {
2627-
let Some(network_metadata) = self.network_metadata_mut(network_path) else {
2628-
return;
2629-
};
2624+
let Some(network_metadata) = self.network_metadata_mut(network_path) else { return };
26302625
if *export_index >= network_metadata.transient_metadata.wires.len() {
26312626
network_metadata.transient_metadata.wires.resize(export_index + 1, TransientMetadata::Unloaded);
26322627
}
@@ -2640,9 +2635,7 @@ impl NodeNetworkInterface {
26402635

26412636
pub fn unload_all_wires(&mut self, network_path: &[NodeId]) {
26422637
let mut input_connectors = Vec::new();
2643-
let Some(network) = self.nested_network(network_path) else {
2644-
return;
2645-
};
2638+
let Some(network) = self.nested_network(network_path) else { return };
26462639
for export_index in 0..network.exports.len() {
26472640
input_connectors.push(InputConnector::Export(export_index));
26482641
}
@@ -2702,6 +2695,7 @@ impl NodeNetworkInterface {
27022695
}
27032696
}
27042697
}
2698+
27052699
// When previewing, there may be a second path to the root node
27062700
pub fn wire_to_root(&mut self, network_path: &[NodeId]) -> Option<WireUpdate> {
27072701
let current_export = self.upstream_output_connector(&InputConnector::Export(0), network_path)?;
@@ -2724,18 +2718,17 @@ impl NodeNetworkInterface {
27242718
}
27252719

27262720
pub fn wire_path_from_input(&mut self, input: &InputConnector, dashed: bool, network_path: &[NodeId]) -> Option<WirePath> {
2727-
let Some(end) = self.try_get_input_dom_rect(input, network_path) else {
2721+
let Some(end) = self.try_get_input_rect(input, network_path) else {
27282722
log::error!("Could not get dom rect for wire end: {:?}", input);
27292723
return None;
27302724
};
27312725
let input_position = DVec2 {
27322726
x: end.0 + end.2 / 2.,
27332727
y: end.1 + end.3 / 2.,
27342728
};
2735-
let Some(upstream_output) = self.upstream_output_connector(input, network_path) else {
2736-
return None;
2737-
};
2738-
let Some(start) = self.try_get_output_dom_rect(&upstream_output, network_path) else {
2729+
2730+
let upstream_output = self.upstream_output_connector(input, network_path)?;
2731+
let Some(start) = self.try_get_output_rect(&upstream_output, network_path) else {
27392732
log::error!("Could not get dom rect for wire start: {:?}", upstream_output);
27402733
return None;
27412734
};
@@ -6446,15 +6439,15 @@ pub enum WidgetOverride {
64466439
// TODO: Custom deserialization/serialization to ensure number of properties row matches number of node inputs
64476440
#[derive(Debug, Clone, Default, PartialEq, serde::Serialize, serde::Deserialize)]
64486441
pub struct InputPersistentMetadata {
6449-
/// A general datastore than can store key value pairs of any types for any input
6450-
/// Each instance of the input node needs to store its own data, since it can
6442+
/// A general datastore that can store key-value pairs of any types for any input.
6443+
/// Each instance of the input node needs to store its own data, since it can lose the reference to its node definition if the node signature is modified by the user.
64516444
pub input_data: HashMap<String, Value>,
64526445
// An input can override a widget, which would otherwise be automatically generated from the type
64536446
// The string is the identifier to the widget override function stored in INPUT_OVERRIDES
64546447
pub widget_override: Option<String>,
6455-
// An empty input name means to use the type as the name
6448+
/// An empty input name means to use the type as the name.
64566449
pub input_name: String,
6457-
// Tooltip
6450+
/// Displayed as the tooltip.
64586451
pub input_description: String,
64596452
}
64606453

@@ -6662,15 +6655,8 @@ pub struct DocumentNodePersistentMetadataInputNames {
66626655
impl From<DocumentNodePersistentMetadataInputNames> for DocumentNodePersistentMetadata {
66636656
fn from(old: DocumentNodePersistentMetadataInputNames) -> Self {
66646657
DocumentNodePersistentMetadata {
6665-
reference: old.reference,
6666-
display_name: old.display_name,
66676658
input_metadata: Vec::new(),
6668-
output_names: old.output_names,
6669-
has_primary_output: old.has_primary_output,
6670-
locked: old.locked,
6671-
pinned: old.pinned,
6672-
node_type_metadata: old.node_type_metadata,
6673-
network_metadata: old.network_metadata,
6659+
..old.into()
66746660
}
66756661
}
66766662
}
@@ -6717,10 +6703,11 @@ impl From<DocumentNodePersistentMetadataPropertiesRow> for DocumentNodePersisten
67176703
..Default::default()
67186704
})
67196705
}
6706+
67206707
DocumentNodePersistentMetadata {
6708+
input_metadata: Vec::new(),
67216709
reference: old.reference,
67226710
display_name: old.display_name,
6723-
input_metadata: Vec::new(),
67246711
output_names: old.output_names,
67256712
has_primary_output: old.has_primary_output,
67266713
locked: old.locked,
@@ -6745,16 +6732,14 @@ where
67456732
use serde::Deserialize;
67466733

67476734
let value = Value::deserialize(deserializer)?;
6748-
match serde_json::from_value::<DocumentNodePersistentMetadata>(value.clone()) {
6749-
Ok(document) => return Ok(document),
6750-
Err(_) => {}
6735+
if let Ok(document) = serde_json::from_value::<DocumentNodePersistentMetadata>(value.clone()) {
6736+
return Ok(document);
67516737
};
6752-
match serde_json::from_value::<DocumentNodePersistentMetadataPropertiesRow>(value.clone()) {
6753-
Ok(document) => return Ok(document.into()),
6754-
Err(_) => {}
6738+
if let Ok(document) = serde_json::from_value::<DocumentNodePersistentMetadataPropertiesRow>(value.clone()) {
6739+
return Ok(document.into());
67556740
};
67566741
match serde_json::from_value::<DocumentNodePersistentMetadataInputNames>(value.clone()) {
6757-
Ok(document) => return Ok(document.into()),
6742+
Ok(document) => Ok(document.into()),
67586743
Err(e) => Err(serde::de::Error::custom(e)),
67596744
}
67606745
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
use crate::messages::portfolio::document::node_graph::utility_types::FrontendGraphDataType;
2-
31
use super::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
42
use super::network_interface::NodeNetworkInterface;
3+
use crate::messages::portfolio::document::node_graph::utility_types::FrontendGraphDataType;
54
use glam::DVec2;
65
use graph_craft::document::{NodeId, NodeNetwork};
76
use serde::ser::SerializeStruct;
@@ -194,7 +193,7 @@ pub fn build_wire_path(output_position: DVec2, input_position: DVec2, vertical_o
194193
let horizontal_curve = horizontal_curve_amount * curve_length;
195194
let vertical_curve = vertical_curve_amount * curve_length;
196195

197-
let locations = vec![
196+
let locations = [
198197
output_position,
199198
DVec2::new(
200199
if vertical_out { output_position.x } else { output_position.x + horizontal_curve },

editor/src/messages/portfolio/document_migration.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,9 @@ pub fn document_migration_upgrades(document: &mut DocumentMessageHandler, reset_
161161
.network_interface
162162
.document_network()
163163
.recursive_nodes()
164-
.map(|(node_id, node, path)| (node_id.clone(), node.clone(), path))
164+
.map(|(node_id, node, path)| (*node_id, node.clone(), path))
165165
.collect::<Vec<(NodeId, graph_craft::document::DocumentNode, Vec<NodeId>)>>();
166+
166167
for (node_id, node, network_path) in &nodes {
167168
if reset_node_definitions_on_open {
168169
if let Some(Some(reference)) = document.network_interface.reference(node_id, network_path) {

0 commit comments

Comments
 (0)