Skip to content

Commit 93429ab

Browse files
committed
Code cleanup
1 parent b96f610 commit 93429ab

File tree

17 files changed

+57
-151
lines changed

17 files changed

+57
-151
lines changed

editor/src/messages/layout/layout_message_handler.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ impl LayoutMessageHandler {
186186
let callback_message = (number_input.on_update.callback)(number_input);
187187
responses.add(callback_message);
188188
}
189-
//TODO: This crashes when the cursor is in a text box, such as in the Text node, and the transform node is clicked (https://github.com/GraphiteEditor/Graphite/issues/1761)
189+
// TODO: This crashes when the cursor is in a text box, such as in the Text node, and the transform node is clicked (https://github.com/GraphiteEditor/Graphite/issues/1761)
190190
Value::String(str) => match str.as_str() {
191191
"Increment" => responses.add((number_input.increment_callback_increase.callback)(number_input)),
192192
"Decrement" => responses.add((number_input.increment_callback_decrease.callback)(number_input)),

editor/src/messages/portfolio/document/document_message_handler.rs

Lines changed: 21 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
317317

318318
responses.add_front(BroadcastEvent::SelectionChanged);
319319
for path in self.metadata().shallowest_unique_layers(self.selected_nodes.selected_layers(self.metadata())) {
320-
//Path will never include ROOT_PARENT, so this is safe
320+
// Path will never include ROOT_PARENT, so this is safe
321321
responses.add_front(DocumentMessage::DeleteLayer { layer: *path.last().unwrap() });
322322
}
323323
}
@@ -455,7 +455,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
455455
});
456456

457457
// Insert node right above the folder
458-
//TODO: downstream node can be none if it is the root node
458+
// TODO: downstream node can be none if it is the root node
459459
let (folder_downstream_node_id, folder_downstream_input_index) =
460460
DocumentMessageHandler::get_downstream_node(&self.network, &self.metadata, first_unselected_parent_folder).unwrap_or((self.network.exports_metadata.0, 0));
461461

@@ -481,12 +481,12 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
481481
responses.add(GraphOperationMessage::NewCustomLayer {
482482
id: folder_id,
483483
nodes: HashMap::new(),
484-
parent: parent,
484+
parent,
485485
insert_index: calculated_insert_index,
486486
alias: String::new(),
487487
});
488488

489-
let parent: LayerNodeIdentifier = LayerNodeIdentifier::new_unchecked(folder_id);
489+
let parent = LayerNodeIdentifier::new_unchecked(folder_id);
490490
responses.add(GraphOperationMessage::MoveSelectedSiblingsToChild { new_parent: parent });
491491

492492
responses.add(NodeGraphMessage::SelectedNodesSet { nodes: vec![folder_id] });
@@ -539,7 +539,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
539539
if selected_layers.iter().any(|&layer| parent.ancestors(self.metadata()).any(|ancestor| ancestor == layer)) {
540540
return;
541541
}
542-
// Artboards can only have None as the parent.
542+
// Artboards can only have ROOT_PARENT as the parent.
543543
if selected_layers.iter().any(|&layer| self.metadata.is_artboard(layer)) && parent != LayerNodeIdentifier::ROOT_PARENT {
544544
return;
545545
}
@@ -985,7 +985,7 @@ impl MessageHandler<DocumentMessage, DocumentMessageData<'_>> for DocumentMessag
985985
});
986986

987987
// Set the primary input for the node downstream of folder to the first layer node
988-
//TODO: downstream node can be none if it is the root node
988+
// TODO: downstream node can be none if it is the root node. A layer group connected directly to the export cannot be ungrouped
989989
let Some((downstream_node_id, downstream_input_index)) = DocumentMessageHandler::get_downstream_node(&self.network, &self.metadata, folder) else {
990990
log::error!("Downstream node should always exist when moving layer");
991991
continue;
@@ -1219,20 +1219,20 @@ impl DocumentMessageHandler {
12191219
}
12201220

12211221
pub fn deserialize_document(serialized_content: &str) -> Result<Self, EditorError> {
1222-
// serde_json::from_str(serialized_content).map_err(|e| EditorError::DocumentDeserialization(e.to_string()))
1223-
// TODO: Comment out after upgrading demo artwork
1224-
match serde_json::from_str::<Self>(serialized_content).map_err(|e| EditorError::DocumentDeserialization(e.to_string())) {
1225-
Ok(mut document) => {
1226-
for (_, node) in &mut document.network.nodes {
1227-
let node_definition = crate::messages::portfolio::document::node_graph::document_node_types::resolve_document_node_type(&node.name).unwrap();
1228-
let default_definition_node = node_definition.default_document_node();
1229-
1230-
node.implementation = default_definition_node.implementation.clone();
1231-
}
1232-
Ok(document)
1233-
}
1234-
Err(e) => Err(e),
1235-
}
1222+
serde_json::from_str(serialized_content).map_err(|e| EditorError::DocumentDeserialization(e.to_string()))
1223+
// Used for upgrading old internal networks for demo artwork nodes. Will reset all node internals for any opened file
1224+
// match serde_json::from_str::<Self>(serialized_content).map_err(|e| EditorError::DocumentDeserialization(e.to_string())) {
1225+
// Ok(mut document) => {
1226+
// for (_, node) in &mut document.network.nodes {
1227+
// let node_definition = crate::messages::portfolio::document::node_graph::document_node_types::resolve_document_node_type(&node.name).unwrap();
1228+
// let default_definition_node = node_definition.default_document_node();
1229+
1230+
// node.implementation = default_definition_node.implementation.clone();
1231+
// }
1232+
// Ok(document)
1233+
// }
1234+
// Err(e) => Err(e),
1235+
// }
12361236
}
12371237

12381238
pub fn with_name(name: String, ipp: &InputPreprocessorMessageHandler, responses: &mut VecDeque<Message>) -> Self {
@@ -1253,7 +1253,6 @@ impl DocumentMessageHandler {
12531253
/// Called recursively by the entry function [`serialize_root`].
12541254
fn serialize_structure(&self, folder: LayerNodeIdentifier, structure_section: &mut Vec<u64>, data_section: &mut Vec<u64>, path: &mut Vec<LayerNodeIdentifier>) {
12551255
let mut space = 0;
1256-
12571256
for layer_node in folder.children(self.metadata()) {
12581257
data_section.push(layer_node.to_node().0);
12591258
space += 1;
@@ -1307,7 +1306,7 @@ impl DocumentMessageHandler {
13071306
pub fn serialize_root(&self) -> RawBuffer {
13081307
let mut structure_section = vec![NodeId(0).0];
13091308
let mut data_section = Vec::new();
1310-
self.serialize_structure(self.metadata().root(), &mut structure_section, &mut data_section, &mut vec![]);
1309+
self.serialize_structure(LayerNodeIdentifier::ROOT_PARENT, &mut structure_section, &mut data_section, &mut vec![]);
13111310

13121311
// Remove the ROOT element. Prepend `L`, the length (excluding the ROOT) of the structure section (which happens to be where the ROOT element was).
13131312
structure_section[0] = structure_section.len() as u64 - 1;
@@ -1458,15 +1457,6 @@ impl DocumentMessageHandler {
14581457
})
14591458
}
14601459

1461-
/// When working with an insert index, deleting the layers may cause the insert index to point to a different location (if the layer being deleted was located before the insert index).
1462-
///
1463-
/// This function updates the insert index so that it points to the same place after the specified `layers` are deleted.
1464-
// fn update_insert_index(&self, layers: &[LayerNodeIdentifier], parent: LayerNodeIdentifier, insert_index: isize) -> usize {
1465-
// let take_amount = if insert_index < 0 { usize::MAX } else { insert_index as usize };
1466-
// let layer_ids_above = parent.children(self.metadata()).take(take_amount);
1467-
// layer_ids_above.filter(|layer_id| !layers.contains(layer_id)).count() as usize
1468-
// }
1469-
14701460
/// Finds the parent folder which, based on the current selections, should be the container of any newly added layers.
14711461
pub fn new_layer_parent(&self, include_self: bool) -> LayerNodeIdentifier {
14721462
self.metadata()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageData<'_>> for Gr
158158
return;
159159
};
160160

161-
let tagged_value = ModifyInputsContext::get_input_tagged_value(document_network, &Vec::new(), node_id, &node_graph.resolved_types, input_index);
161+
let tagged_value = TaggedValue::from_type(&ModifyInputsContext::get_input_type(document_network, &Vec::new(), node_id, &node_graph.resolved_types, input_index));
162162

163163
let mut input = NodeInput::value(tagged_value, true);
164164
if let NodeInput::Value { exposed, .. } = &mut input {

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

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
use std::hash::{DefaultHasher, Hash, Hasher};
2-
31
use crate::messages::portfolio::document::node_graph::document_node_types::resolve_document_node_type;
42
use crate::messages::portfolio::document::utility_types::document_metadata::{DocumentMetadata, LayerNodeIdentifier};
3+
use crate::messages::portfolio::document::utility_types::nodes::SelectedNodes;
54
use crate::messages::prelude::*;
65

7-
use crate::messages::portfolio::document::utility_types::nodes::SelectedNodes;
8-
use bezier_rs::Subpath;
96
use graph_craft::concrete;
107
use graph_craft::document::value::TaggedValue;
11-
use graph_craft::document::Previewing;
12-
use graph_craft::document::{generate_uuid, DocumentNode, DocumentNodeImplementation, NodeId, NodeInput, NodeNetwork};
8+
use graph_craft::document::{generate_uuid, DocumentNode, DocumentNodeImplementation, NodeId, NodeInput, NodeNetwork, Previewing};
139
use graphene_core::raster::{BlendMode, ImageFrame};
1410
use graphene_core::text::Font;
1511
use graphene_core::uuid::ManipulatorGroupId;
@@ -19,9 +15,11 @@ use graphene_core::Type;
1915
use graphene_core::{Artboard, Color};
2016
use graphene_std::vector::ManipulatorPointId;
2117
use interpreted_executor::dynamic_executor::ResolvedDocumentNodeTypes;
18+
use interpreted_executor::node_registry::NODE_REGISTRY;
2219

20+
use bezier_rs::Subpath;
2321
use glam::{DAffine2, DVec2, IVec2};
24-
use interpreted_executor::node_registry::NODE_REGISTRY;
22+
use std::hash::{DefaultHasher, Hash, Hasher};
2523

2624
use super::transform_utils::{self, LayerBounds};
2725

@@ -48,8 +46,7 @@ pub enum VectorDataModification {
4846
UpdateSubpaths { subpaths: Vec<Subpath<ManipulatorGroupId>> },
4947
}
5048

51-
// TODO: Generalize for any network, rewrite as static functions since there only a few fields are used for each function, so when calling only the necessary data will
52-
// be provided
49+
// TODO: Generalize for any network, rewrite as static functions since there only a few fields are used for each function, so when calling only the necessary data will be provided
5350
/// NodeGraphMessage or GraphOperationMessage cannot be added in ModifyInputsContext, since the functions are called by both messages handlers
5451
pub struct ModifyInputsContext<'a> {
5552
pub document_metadata: &'a mut DocumentMetadata,
@@ -139,7 +136,7 @@ impl<'a> ModifyInputsContext<'a> {
139136
assert!(!document_network.nodes.contains_key(&id), "Creating already existing node");
140137
if let Some(root_node) = document_network.get_root_node() {
141138
let previous_root_node = document_network.nodes.get_mut(&root_node.id).expect("Root node should always exist");
142-
//Insert whatever non artboard node previously fed into export as a child of the new node
139+
// Insert whatever non artboard node previously fed into export as a child of the new node
143140
let node_input_index = if new_node.is_artboard() && !previous_root_node.is_artboard() { 1 } else { 0 };
144141
new_node.inputs[node_input_index] = NodeInput::node(root_node.id, root_node.output_index);
145142
ModifyInputsContext::shift_upstream(document_network, root_node.id, IVec2::new(8, 0), true);
@@ -278,7 +275,7 @@ impl<'a> ModifyInputsContext<'a> {
278275
self.insert_node_before(new_id, post_node_id, post_node_input_index, new_layer_node, offset);
279276
};
280277
} else {
281-
//If post_node does not exist, then network is empty
278+
// If post_node does not exist, then network is empty
282279
ModifyInputsContext::insert_node_as_primary_export(self.document_network, new_id, new_layer_node);
283280
}
284281

@@ -462,7 +459,6 @@ impl<'a> ModifyInputsContext<'a> {
462459
self.modify_new_node(name, update_input);
463460
}
464461

465-
//self.node_graph.network.clear();
466462
self.responses.add(PropertiesPanelMessage::Refresh);
467463

468464
if !skip_rerender {
@@ -503,7 +499,7 @@ impl<'a> ModifyInputsContext<'a> {
503499
}
504500
}
505501

506-
/// Returns a true if the network structure is updated
502+
/// Returns true if the network structure is updated
507503
pub fn set_input(network: &mut NodeNetwork, node_id: NodeId, input_index: usize, input: NodeInput, is_document_network: bool) -> bool {
508504
let mut load_network_structure = false;
509505
if let Some(node) = network.nodes.get_mut(&node_id) {
@@ -888,7 +884,7 @@ impl<'a> ModifyInputsContext<'a> {
888884
can_reconnect = false;
889885
} else {
890886
//Disconnect input
891-
let tagged_value = ModifyInputsContext::get_input_tagged_value(document_network, network_path, node_id, resolved_types, input_index);
887+
let tagged_value = TaggedValue::from_type(&ModifyInputsContext::get_input_type(document_network, network_path, node_id, resolved_types, input_index));
892888
let value_input = NodeInput::value(tagged_value, true);
893889
nodes_to_set_input.push((node_id, input_index, Some(value_input)));
894890
}
@@ -943,12 +939,13 @@ impl<'a> ModifyInputsContext<'a> {
943939
true
944940
}
945941

942+
/// Get the Type for any node id and input index. Network path is the path to the encapsulating node (including the encapsulating node), node_id is the selected node
946943
pub fn get_input_type(document_network: &NodeNetwork, network_path: &Vec<NodeId>, node_id: NodeId, resolved_types: &ResolvedDocumentNodeTypes, input_index: usize) -> Type {
947944
let Some(network) = document_network.nested_network(&network_path) else {
948945
log::error!("Could not get network in get_tagged_value");
949946
return concrete!(());
950947
};
951-
//TODO: Store types for all document nodes, not just the compiled proto nodes, which currently skips isolated nodes
948+
// TODO: Store types for all document nodes, not just the compiled proto nodes, which currently skips isolated nodes
952949
let node_id_path = &[&network_path[..], &[node_id]].concat();
953950
let input_type = resolved_types.inputs.get(&graph_craft::document::Source {
954951
node: node_id_path.clone(),
@@ -1037,8 +1034,4 @@ impl<'a> ModifyInputsContext<'a> {
10371034
get_type_from_node(node, input_index)
10381035
}
10391036
}
1040-
/// Get the tagged_value for any node id and input index. Network path is the path to the encapsulating node (including the encapsulating node), node_id is the selected node
1041-
pub fn get_input_tagged_value(document_network: &NodeNetwork, network_path: &Vec<NodeId>, node_id: NodeId, resolved_types: &ResolvedDocumentNodeTypes, input_index: usize) -> TaggedValue {
1042-
TaggedValue::from_type(&ModifyInputsContext::get_input_type(document_network, network_path, node_id, resolved_types, input_index))
1043-
}
10441037
}

0 commit comments

Comments
 (0)