diff --git a/editor/src/messages/portfolio/document_migration.rs b/editor/src/messages/portfolio/document_migration.rs index fc8f42ff7..fc93f2a93 100644 --- a/editor/src/messages/portfolio/document_migration.rs +++ b/editor/src/messages/portfolio/document_migration.rs @@ -834,6 +834,44 @@ pub fn document_migration_upgrades(document: &mut DocumentMessageHandler, reset_ } } } + + // Replace "To u32" and "To u64" nodes with "Floor" nodes + if reference == "To u32" || reference == "To u64" { + let node_definition = resolve_document_node_type("Floor").unwrap(); + let new_node_template = node_definition.default_node_template(); + let document_node = new_node_template.document_node; + document.network_interface.replace_implementation(node_id, network_path, document_node.implementation.clone()); + document + .network_interface + .replace_implementation_metadata(node_id, network_path, new_node_template.persistent_node_metadata); + + let old_inputs = document.network_interface.replace_inputs(node_id, document_node.inputs.clone(), network_path); + + document.network_interface.set_input(&InputConnector::node(*node_id, 0), old_inputs[0].clone(), network_path); + + document.network_interface.replace_reference_name(node_id, network_path, "Floor".to_string()); + document + .network_interface + .set_manual_compostion(node_id, network_path, graph_craft::concrete!(graphene_std::Context).into()); + } + + // Replace the "To f64" node with the "Identity" node + if reference == "To f64" { + let node_definition = resolve_document_node_type("Identity").unwrap(); + let new_node_template = node_definition.default_node_template(); + let document_node = new_node_template.document_node; + document.network_interface.replace_implementation(node_id, network_path, document_node.implementation.clone()); + document + .network_interface + .replace_implementation_metadata(node_id, network_path, new_node_template.persistent_node_metadata); + + let old_inputs = document.network_interface.replace_inputs(node_id, document_node.inputs.clone(), network_path); + + document.network_interface.set_input(&InputConnector::node(*node_id, 0), old_inputs[0].clone(), network_path); + + document.network_interface.replace_reference_name(node_id, network_path, "Identity".to_string()); + document.network_interface.set_manual_compostion(node_id, network_path, None); + } } // Ensure layers are positioned as stacks if they are upstream siblings of another layer diff --git a/node-graph/gmath-nodes/src/lib.rs b/node-graph/gmath-nodes/src/lib.rs index b47b9c0ee..4d7787a98 100644 --- a/node-graph/gmath-nodes/src/lib.rs +++ b/node-graph/gmath-nodes/src/lib.rs @@ -346,26 +346,6 @@ fn random( result * (max - min) + min } -/// Convert a number to an integer of the type u32, which may be the required type for certain node inputs. This will be removed in the future when automatic type conversion is implemented. -#[node_macro::node(name("To u32"), category("Math: Numeric"))] -fn to_u32(_: impl Ctx, #[implementations(f64, f32)] value: U) -> u32 { - let value = U::clamp(value, U::from(0.).unwrap(), U::from(u32::MAX as f64).unwrap()); - value.to_u32().unwrap() -} - -/// Convert a number to an integer of the type u64, which may be the required type for certain node inputs. This will be removed in the future when automatic type conversion is implemented. -#[node_macro::node(name("To u64"), category("Math: Numeric"))] -fn to_u64(_: impl Ctx, #[implementations(f64, f32)] value: U) -> u64 { - let value = U::clamp(value, U::from(0.).unwrap(), U::from(u64::MAX as f64).unwrap()); - value.to_u64().unwrap() -} - -/// Convert an integer to a decimal number of the type f64, which may be the required type for certain node inputs. This will be removed in the future when automatic type conversion is implemented. -#[node_macro::node(name("To f64"), category("Math: Numeric"))] -fn to_f64(_: impl Ctx, #[implementations(u32, u64)] value: U) -> f64 { - value.to_f64().unwrap() -} - /// The rounding function (round) maps an input value to its nearest whole number. Halfway values are rounded away from zero. #[node_macro::node(category("Math: Numeric"))] fn round(