mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-29 02:18:11 +08:00
Migrate short-arity async source document nodes to the hidden inputs
This commit is contained in:
@@ -919,7 +919,12 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
|||||||
exports: vec![NodeInput::node(NodeId(1), 0)],
|
exports: vec![NodeInput::node(NodeId(1), 0)],
|
||||||
nodes: [
|
nodes: [
|
||||||
DocumentNode {
|
DocumentNode {
|
||||||
inputs: vec![NodeInput::value(TaggedValue::None, false), NodeInput::import(concrete!(String), 1)],
|
inputs: vec![
|
||||||
|
NodeInput::value(TaggedValue::None, false),
|
||||||
|
NodeInput::import(concrete!(String), 1),
|
||||||
|
NodeInput::scope("graphene_std::runtime::RuntimeNode"),
|
||||||
|
NodeInput::Reflection(graph_craft::document::DocumentNodeMetadata::SourceId),
|
||||||
|
],
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(platform_application_io::load_resource::IDENTIFIER),
|
implementation: DocumentNodeImplementation::ProtoNode(platform_application_io::load_resource::IDENTIFIER),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
@@ -994,7 +999,13 @@ fn document_node_definitions() -> HashMap<DefinitionIdentifier, DocumentNodeDefi
|
|||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
DocumentNode {
|
DocumentNode {
|
||||||
inputs: vec![NodeInput::import(generic!(T), 0), NodeInput::import(concrete!(Footprint), 1), NodeInput::node(NodeId(1), 0)],
|
inputs: vec![
|
||||||
|
NodeInput::import(generic!(T), 0),
|
||||||
|
NodeInput::import(concrete!(Footprint), 1),
|
||||||
|
NodeInput::node(NodeId(1), 0),
|
||||||
|
NodeInput::scope("graphene_std::runtime::RuntimeNode"),
|
||||||
|
NodeInput::Reflection(graph_craft::document::DocumentNodeMetadata::SourceId),
|
||||||
|
],
|
||||||
implementation: DocumentNodeImplementation::ProtoNode(platform_application_io::rasterize::IDENTIFIER),
|
implementation: DocumentNodeImplementation::ProtoNode(platform_application_io::rasterize::IDENTIFIER),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -95,6 +95,34 @@ impl NodeNetworkInterface {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Append the hidden runtime and source-id inputs to async-source protonodes saved before their injection.
|
||||||
|
/// Runs after the identifier replacement pass, so it matches only current identifier spellings.
|
||||||
|
pub fn migrate_async_source_inputs(&mut self) {
|
||||||
|
const PRE_INJECTION_ARITIES: [(&str, usize); 5] = [
|
||||||
|
("graphene_std::platform_application_io::GetRequestNode", 4),
|
||||||
|
("graphene_std::platform_application_io::PostRequestNode", 5),
|
||||||
|
("graphene_std::platform_application_io::LoadResourceNode", 2),
|
||||||
|
("graphene_std::platform_application_io::RasterizeNode", 3),
|
||||||
|
("graphene_std::platform_application_io::ResourceNode", 2),
|
||||||
|
];
|
||||||
|
fix_network(self.document_network_mut());
|
||||||
|
fn fix_network(network: &mut NodeNetwork) {
|
||||||
|
for node in network.nodes.values_mut() {
|
||||||
|
if let Some(network) = node.implementation.get_network_mut() {
|
||||||
|
fix_network(network);
|
||||||
|
}
|
||||||
|
if let DocumentNodeImplementation::ProtoNode(protonode) = &node.implementation
|
||||||
|
&& let Some(base) = protonode.as_str().split('<').next()
|
||||||
|
&& let Some((_, arity)) = PRE_INJECTION_ARITIES.iter().find(|(identifier, _)| *identifier == base)
|
||||||
|
&& node.inputs.len() == *arity
|
||||||
|
{
|
||||||
|
node.inputs.push(NodeInput::scope("graphene_std::runtime::RuntimeNode"));
|
||||||
|
node.inputs.push(NodeInput::Reflection(graph_craft::document::DocumentNodeMetadata::SourceId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Public immutable getters for the network interface
|
// Public immutable getters for the network interface
|
||||||
|
|||||||
@@ -1148,6 +1148,8 @@ pub fn document_migration_upgrades(document: &mut DocumentMessageHandler, reset_
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.network_interface.migrate_async_source_inputs();
|
||||||
|
|
||||||
// The "Brush" wrapper network was replaced with the `brush` proto node directly. Convert old `Network("Brush")` instances to the proto node, forwarding all 3 inputs (Background, Trace, Cache) one-to-one.
|
// The "Brush" wrapper network was replaced with the `brush` proto node directly. Convert old `Network("Brush")` instances to the proto node, forwarding all 3 inputs (Background, Trace, Cache) one-to-one.
|
||||||
// This must run as a pre-pass before the recursive iteration below: replacing the outer Brush's network impl orphans its child paths, and the recursive iteration would log errors for those stale paths.
|
// This must run as a pre-pass before the recursive iteration below: replacing the outer Brush's network impl orphans its child paths, and the recursive iteration would log errors for those stale paths.
|
||||||
let brush_layers: Vec<(NodeId, Vec<NodeId>)> = document
|
let brush_layers: Vec<(NodeId, Vec<NodeId>)> = document
|
||||||
|
|||||||
Reference in New Issue
Block a user