Skip to content

Commit

Permalink
Adds macro to convert RadiantNode to NodeType
Browse files Browse the repository at this point in the history
  • Loading branch information
codeneix committed Nov 5, 2023
1 parent 61981ec commit 5800549
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
16 changes: 16 additions & 0 deletions crates/macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,14 @@ fn derive_node_internal(item: TokenStream2) -> syn::Result<TokenStream2> {
.iter()
.map(|variant| variant.ident.clone())
.collect::<Vec<_>>();
let nodes = item.variants.iter().map(|variant| {
let fields = variant
.fields
.iter();
quote! {
#(#fields)*
}
});

let res = quote! {
impl RadiantNode for #name {
Expand Down Expand Up @@ -92,6 +100,14 @@ fn derive_node_internal(item: TokenStream2) -> syn::Result<TokenStream2> {
}
}
}

#(
impl From<#nodes> for #name {
fn from(node: #nodes) -> Self {
Self::#node_names(node)
}
}
)*
};
Ok(res)
}
Expand Down
10 changes: 5 additions & 5 deletions examples/basic/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use radiant_runtime::{
run_native, RadiantNodeType, RadiantPathNode, RadiantRectangleNode, RadiantResponse,
run_native, RadiantPathNode, RadiantRectangleNode, RadiantResponse,
RadiantRuntime, Runtime,
};

Expand All @@ -17,17 +17,17 @@ async fn run() {
let mut runtime = RadiantRuntime::new().await;
runtime
.scene()
.add(RadiantNodeType::Rectangle(RadiantRectangleNode::new(
.add(RadiantRectangleNode::new(
1,
[100.0, 100.0],
[200.0, 200.0],
)));
).into());
runtime
.scene()
.add(RadiantNodeType::Path(RadiantPathNode::new(
.add(RadiantPathNode::new(
2,
[400.0, 400.0],
)));
).into());

run_native(runtime, handler);
}
Expand Down

0 comments on commit 5800549

Please sign in to comment.