Skip to content

Commit c0d60b7

Browse files
committed
fix:
- replace hardcoded primary input/output indices with named constants - adds PRIMARY_INPUT_INDEX and PRIMARY_OUTPUT_INDEX constants to InputConnector, OutputConnector, and NodeInput, replaces hardcoded 0 indices with these constants.
1 parent 8ea25ac commit c0d60b7

File tree

16 files changed

+99
-86
lines changed

16 files changed

+99
-86
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
200200
const LAYER_SECONDARY_INPUT_INDEX: usize = 1;
201201
responses.add(NodeGraphMessage::SetInput {
202202
input_connector: InputConnector::node(layer.to_node(), LAYER_SECONDARY_INPUT_INDEX),
203-
input: NodeInput::node(first_new_node_id, 0),
203+
input: NodeInput::node(first_new_node_id, NodeInput::PRIMARY_OUTPUT_INDEX),
204204
});
205205
}
206206
// Move the layer and all nodes to the correct position in the network
@@ -260,10 +260,10 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
260260
artboard_data.insert(
261261
artboard.to_node(),
262262
ArtboardInfo {
263-
input_node: NodeInput::node(document_node.inputs[ARTBOARD_CONTENT_INDEX].as_node().unwrap_or_default(), 0),
263+
input_node: NodeInput::node(document_node.inputs[ARTBOARD_CONTENT_INDEX].as_node().unwrap_or_default(), NodeInput::PRIMARY_OUTPUT_INDEX),
264264
output_nodes: network_interface
265265
.outward_wires(&[])
266-
.and_then(|outward_wires| outward_wires.get(&OutputConnector::node(artboard.to_node(), 0)))
266+
.and_then(|outward_wires| outward_wires.get(&OutputConnector::node(artboard.to_node(), OutputConnector::PRIMARY_OUTPUT_INDEX)))
267267
.cloned()
268268
.unwrap_or_default(),
269269
merge_node: node_id,
@@ -290,12 +290,12 @@ impl MessageHandler<GraphOperationMessage, GraphOperationMessageContext<'_>> for
290290
const MERGE_CONTENT_INDEX: usize = 1;
291291
responses.add(NodeGraphMessage::SetInput {
292292
input_connector: InputConnector::node(artboard.1.merge_node, MERGE_CONTENT_INDEX),
293-
input: NodeInput::node(artboard.1.input_node.as_node().unwrap_or_default(), 0),
293+
input: NodeInput::node(artboard.1.input_node.as_node().unwrap_or_default(), NodeInput::PRIMARY_OUTPUT_INDEX),
294294
});
295295

296296
// Modify upstream connections
297297
for outward_wire in &artboard.1.output_nodes {
298-
let input = NodeInput::node(artboard_data[artboard.0].merge_node, 0);
298+
let input = NodeInput::node(artboard_data[artboard.0].merge_node, NodeInput::PRIMARY_OUTPUT_INDEX);
299299
let input_connector = match artboard_data.get(&outward_wire.node_id().unwrap_or_default()) {
300300
Some(artboard_info) => InputConnector::node(artboard_info.merge_node, outward_wire.input_index()),
301301
_ => *outward_wire,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'a> ModifyInputsContext<'a> {
9292
current_index += 1;
9393
}
9494
// Input as a sibling to the Layer node above
95-
post_node_input_connector = InputConnector::node(*next_node_in_stack_id, 0);
95+
post_node_input_connector = InputConnector::node(*next_node_in_stack_id, InputConnector::PRIMARY_INPUT_INDEX);
9696
} else {
9797
log::error!("Error getting post node: insert_index out of bounds");
9898
break;
@@ -108,7 +108,7 @@ impl<'a> ModifyInputsContext<'a> {
108108
match pre_node_output_connector {
109109
Some(OutputConnector::Node { node_id: pre_node_id, .. }) if !network_interface.is_layer(&pre_node_id, &[]) => {
110110
// Update post_node_input_connector for the next iteration
111-
post_node_input_connector = InputConnector::node(pre_node_id, 0);
111+
post_node_input_connector = InputConnector::node(pre_node_id, InputConnector::PRIMARY_INPUT_INDEX);
112112
// Insert directly under layer if moving to the end of a layer stack that ends with a non layer node that does not have an exposed primary input
113113
let primary_is_exposed = network_interface.input_from_connector(&post_node_input_connector, &[]).is_some_and(|input| input.is_exposed());
114114
if !primary_is_exposed {

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

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
223223
x: (mid_point.x / 24.) as i32,
224224
y: (mid_point.y / 24.) as i32,
225225
});
226-
let node_input_connector = InputConnector::node(node_id, 0);
227-
let node_output_connector = OutputConnector::node(node_id, 0);
226+
let node_input_connector = InputConnector::node(node_id, InputConnector::PRIMARY_INPUT_INDEX);
227+
let node_output_connector = OutputConnector::node(node_id, OutputConnector::PRIMARY_OUTPUT_INDEX);
228228
responses.add(NodeGraphMessage::CreateWire {
229229
output_connector,
230230
input_connector: node_input_connector,
@@ -473,7 +473,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
473473
return;
474474
};
475475

476-
let encapsulating_connector = InputConnector::node(*node_id, 0);
476+
let encapsulating_connector = InputConnector::node(*node_id, InputConnector::PRIMARY_INPUT_INDEX);
477477
if !exposed {
478478
network_interface.disconnect_input(&encapsulating_connector, network_path);
479479
}
@@ -527,7 +527,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
527527
log::error!("Could not get outward wires in remove_import");
528528
return;
529529
};
530-
let Some(downstream_connections) = outward_wires.get(&OutputConnector::node(*encapsulating_node, 0)).cloned() else {
530+
let Some(downstream_connections) = outward_wires.get(&OutputConnector::node(*encapsulating_node, OutputConnector::PRIMARY_OUTPUT_INDEX)).cloned() else {
531531
log::error!("Could not get outward wires for import in remove_import");
532532
return;
533533
};
@@ -1338,7 +1338,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
13381338
let selected_node_id = selected_nodes.selected_nodes_ref()[0];
13391339
let has_primary_output_connection = network_interface
13401340
.outward_wires(selection_network_path)
1341-
.is_some_and(|outward_wires| outward_wires.get(&OutputConnector::node(selected_node_id, 0)).is_some_and(|outward_wires| !outward_wires.is_empty()));
1341+
.is_some_and(|outward_wires| outward_wires.get(&OutputConnector::node(selected_node_id, OutputConnector::PRIMARY_OUTPUT_INDEX)).is_some_and(|outward_wires| !outward_wires.is_empty()));
13421342
if !has_primary_output_connection {
13431343
let Some(network) = network_interface.nested_network(selection_network_path) else {
13441344
return;
@@ -1532,13 +1532,13 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
15321532
}
15331533

15341534
let number_of_outputs = network_interface.number_of_outputs(selected_node, selection_network_path);
1535-
let mut first_deselected_upstream_output = network_interface.upstream_output_connector(&InputConnector::node(*selected_node, 0), selection_network_path);
1535+
let mut first_deselected_upstream_output = network_interface.upstream_output_connector(&InputConnector::node(*selected_node, InputConnector::PRIMARY_INPUT_INDEX), selection_network_path);
15361536
while let Some(OutputConnector::Node { node_id, .. }) = &first_deselected_upstream_output {
15371537
if !all_selected_nodes.contains(node_id) {
15381538
break;
15391539
}
15401540

1541-
first_deselected_upstream_output = network_interface.upstream_output_connector(&InputConnector::node(*node_id, 0), selection_network_path);
1541+
first_deselected_upstream_output = network_interface.upstream_output_connector(&InputConnector::node(*node_id, InputConnector::PRIMARY_INPUT_INDEX), selection_network_path);
15421542
}
15431543

15441544
let Some(outward_wires) = network_interface.outward_wires(selection_network_path) else {
@@ -1561,7 +1561,7 @@ impl<'a> MessageHandler<NodeGraphMessage, NodeGraphMessageContext<'a>> for NodeG
15611561
// Handle reconnection
15621562
// Find first non selected upstream node by primary flow
15631563
if let Some(first_deselected_upstream_output) = first_deselected_upstream_output {
1564-
let Some(downstream_connections_to_first_output) = outward_wires.get(&OutputConnector::node(*selected_node, 0)).cloned() else {
1564+
let Some(downstream_connections_to_first_output) = outward_wires.get(&OutputConnector::node(*selected_node, OutputConnector::PRIMARY_OUTPUT_INDEX)).cloned() else {
15651565
log::error!("Could not get downstream_connections_to_first_output in shake node");
15661566
return;
15671567
};
@@ -2597,7 +2597,7 @@ impl NodeGraphMessageHandler {
25972597
};
25982598
let mut nodes = Vec::new();
25992599
for (node_id, visible) in network.nodes.iter().map(|(node_id, node)| (*node_id, node.visible)).collect::<Vec<_>>() {
2600-
let primary_input_connector = InputConnector::node(node_id, 0);
2600+
let primary_input_connector = InputConnector::node(node_id, InputConnector::PRIMARY_INPUT_INDEX);
26012601

26022602
let primary_input = if network_interface
26032603
.input_from_connector(&primary_input_connector, breadcrumb_network_path)
@@ -2611,7 +2611,7 @@ impl NodeGraphMessageHandler {
26112611
.filter_map(|input_index| network_interface.frontend_input_from_connector(&InputConnector::node(node_id, input_index), breadcrumb_network_path))
26122612
.collect();
26132613

2614-
let primary_output = network_interface.frontend_output_from_connector(&OutputConnector::node(node_id, 0), breadcrumb_network_path);
2614+
let primary_output = network_interface.frontend_output_from_connector(&OutputConnector::node(node_id, OutputConnector::PRIMARY_OUTPUT_INDEX), breadcrumb_network_path);
26152615

26162616
let exposed_outputs = (1..network_interface.number_of_outputs(&node_id, breadcrumb_network_path))
26172617
.filter_map(|output_index| network_interface.frontend_output_from_connector(&OutputConnector::node(node_id, output_index), breadcrumb_network_path))

0 commit comments

Comments
 (0)