@@ -15,7 +15,7 @@ use graphene_std::GraphicElement;
1515use graphene_std:: any:: { ComposeTypeErased , DowncastBothNode , DynAnyNode , IntoTypeErasedNode } ;
1616use graphene_std:: application_io:: { ImageTexture , TextureFrameTable } ;
1717use graphene_std:: wasm_application_io:: * ;
18- use node_registry_macros:: { async_node, into_node} ;
18+ use node_registry_macros:: { async_node, convert_node , into_node} ;
1919use once_cell:: sync:: Lazy ;
2020use std:: collections:: HashMap ;
2121use std:: sync:: Arc ;
@@ -25,10 +25,7 @@ use wgpu_executor::{WgpuExecutor, WgpuSurface, WindowHandle};
2525
2626// TODO: turn into hashmap
2727fn node_registry ( ) -> HashMap < ProtoNodeIdentifier , HashMap < NodeIOTypes , NodeConstructor > > {
28- let node_types: Vec < ( ProtoNodeIdentifier , NodeConstructor , NodeIOTypes ) > = vec ! [
29- into_node!( from: f64 , to: f64 ) ,
30- into_node!( from: u32 , to: f64 ) ,
31- into_node!( from: u8 , to: u32 ) ,
28+ let mut node_types: Vec < ( ProtoNodeIdentifier , NodeConstructor , NodeIOTypes ) > = vec ! [
3229 into_node!( from: VectorDataTable , to: VectorDataTable ) ,
3330 into_node!( from: VectorDataTable , to: GraphicElement ) ,
3431 into_node!( from: VectorDataTable , to: GraphicGroupTable ) ,
@@ -137,6 +134,22 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
137134 } ,
138135 ) ,
139136 ] ;
137+ node_types. extend (
138+ [
139+ convert_node ! ( from: i8 , to: numbers) ,
140+ convert_node ! ( from: u8 , to: numbers) ,
141+ convert_node ! ( from: u16 , to: numbers) ,
142+ convert_node ! ( from: i16 , to: numbers) ,
143+ convert_node ! ( from: i32 , to: numbers) ,
144+ convert_node ! ( from: u32 , to: numbers) ,
145+ convert_node ! ( from: i64 , to: numbers) ,
146+ convert_node ! ( from: u64 , to: numbers) ,
147+ convert_node ! ( from: f32 , to: numbers) ,
148+ convert_node ! ( from: f64 , to: numbers) ,
149+ ]
150+ . into_iter ( )
151+ . flatten ( ) ,
152+ ) ;
140153
141154 let mut map: HashMap < ProtoNodeIdentifier , HashMap < NodeIOTypes , NodeConstructor > > = HashMap :: new ( ) ;
142155
@@ -152,7 +165,7 @@ fn node_registry() -> HashMap<ProtoNodeIdentifier, HashMap<NodeIOTypes, NodeCons
152165 // This might be caused by the stringify! macro
153166 let mut new_name = id. name . replace ( '\n' , " " ) ;
154167 // Remove struct generics for all nodes except for the IntoNode
155- if !new_name. contains ( "IntoNode" ) {
168+ if !( new_name. contains ( "IntoNode" ) || new_name . contains ( "ConvertNode" ) ) {
156169 if let Some ( ( path, _generics) ) = new_name. split_once ( "<" ) {
157170 new_name = path. to_string ( ) ;
158171 }
@@ -203,9 +216,8 @@ mod node_registry_macros {
203216 ( from: $from: ty, to: $to: ty) => {
204217 (
205218 ProtoNodeIdentifier :: new( concat![ "graphene_core::ops::IntoNode<" , stringify!( $to) , ">" ] ) ,
206- |mut args | {
219+ |_ | {
207220 Box :: pin( async move {
208- args. reverse( ) ;
209221 let node = graphene_core:: ops:: IntoNode :: <$to>:: new( ) ;
210222 let any: DynAnyNode <$from, _, _> = graphene_std:: any:: DynAnyNode :: new( node) ;
211223 Box :: new( any) as TypeErasedBox
@@ -220,7 +232,43 @@ mod node_registry_macros {
220232 )
221233 } ;
222234 }
235+ macro_rules! convert_node {
236+ ( from: $from: ty, to: numbers) => { {
237+ let x: Vec <( ProtoNodeIdentifier , NodeConstructor , NodeIOTypes ) > = vec![
238+ convert_node!( from: $from, to: i8 ) ,
239+ convert_node!( from: $from, to: u8 ) ,
240+ convert_node!( from: $from, to: u16 ) ,
241+ convert_node!( from: $from, to: i16 ) ,
242+ convert_node!( from: $from, to: i32 ) ,
243+ convert_node!( from: $from, to: u32 ) ,
244+ convert_node!( from: $from, to: i64 ) ,
245+ convert_node!( from: $from, to: u64 ) ,
246+ convert_node!( from: $from, to: f32 ) ,
247+ convert_node!( from: $from, to: f64 ) ,
248+ ] ;
249+ x
250+ } } ;
251+ ( from: $from: ty, to: $to: ty) => {
252+ (
253+ ProtoNodeIdentifier :: new( concat![ "graphene_core::ops::ConvertNode<" , stringify!( $to) , ">" ] ) ,
254+ |_| {
255+ Box :: pin( async move {
256+ let node = graphene_core:: ops:: ConvertNode :: <$to>:: new( ) ;
257+ let any: DynAnyNode <$from, _, _> = graphene_std:: any:: DynAnyNode :: new( node) ;
258+ Box :: new( any) as TypeErasedBox
259+ } )
260+ } ,
261+ {
262+ let node = graphene_core:: ops:: ConvertNode :: <$to>:: new( ) ;
263+ let mut node_io = NodeIO :: <' _, $from>:: to_async_node_io( & node, vec![ ] ) ;
264+ node_io. call_argument = future!( <$from as StaticType >:: Static ) ;
265+ node_io
266+ } ,
267+ )
268+ } ;
269+ }
223270
224271 pub ( crate ) use async_node;
272+ pub ( crate ) use convert_node;
225273 pub ( crate ) use into_node;
226274}
0 commit comments