From 3e0178a032f096337f70098edd82799dca9806ad Mon Sep 17 00:00:00 2001 From: Dennis Kobert Date: Sat, 26 Oct 2024 01:30:02 +0200 Subject: [PATCH] Add switch node and fix log to console node (#2064) * Add switch node and fix log to console node * Formatting --------- Co-authored-by: Keavon Chambers --- node-graph/gcore/src/logic.rs | 53 +++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 6 deletions(-) diff --git a/node-graph/gcore/src/logic.rs b/node-graph/gcore/src/logic.rs index cfa2e1eb..814a3ff5 100644 --- a/node-graph/gcore/src/logic.rs +++ b/node-graph/gcore/src/logic.rs @@ -1,15 +1,56 @@ +use crate::transform::Footprint; use crate::vector::VectorData; use glam::{DAffine2, DVec2}; #[node_macro::node(category("Debug"))] -fn log_to_console( - _: (), - #[default("Not connected to value yet")] - #[implementations(String, bool, f64, f64, u32, u64, DVec2, VectorData, DAffine2)] - value: T, +async fn log_to_console( + #[implementations((), (), (), (), (), (), (), (), Footprint)] footprint: F, + #[implementations( + () -> String, () -> bool, () -> f64, () -> u32, () -> u64, () -> DVec2, () -> VectorData, () -> DAffine2, + Footprint -> String, Footprint -> bool, Footprint -> f64, Footprint -> u32, Footprint -> u64, Footprint -> DVec2, Footprint -> VectorData, Footprint -> DAffine2, + )] + value: impl Node, ) -> T { #[cfg(not(target_arch = "spirv"))] // KEEP THIS `debug!()` - It acts as the output for the debug node itself - debug!("{value:#?}"); + let value = value.eval(footprint).await; + debug!("{:#?}", value); value } + +#[node_macro::node(category("Debug"))] +async fn to_string( + #[implementations((), (), (), (), (), (), Footprint)] footprint: F, + #[implementations( + () -> String, () -> bool, () -> f64, () -> u32, () -> u64, () -> DVec2, + Footprint -> String, Footprint -> bool, Footprint -> f64, Footprint -> u32, Footprint -> u64, Footprint -> DVec2, + )] + value: impl Node, +) -> String { + let value = value.eval(footprint).await; + format!("{:?}", value) +} + +#[node_macro::node(category("Debug"))] +async fn switch( + #[implementations((), (), (), (), (), (), (), (), Footprint)] footprint: F, + condition: bool, + #[expose] + #[implementations( + () -> String, () -> bool, () -> f64, () -> u32, () -> u64, () -> DVec2, () -> VectorData, () -> DAffine2, + Footprint -> String, Footprint -> bool, Footprint -> f64, Footprint -> u32, Footprint -> u64, Footprint -> DVec2, Footprint -> VectorData, Footprint -> DAffine2 + )] + if_true: impl Node, + #[expose] + #[implementations( + () -> String, () -> bool, () -> f64, () -> u32, () -> u64, () -> DVec2, () -> VectorData, () -> DAffine2, + Footprint -> String, Footprint -> bool, Footprint -> f64, Footprint -> u32, Footprint -> u64, Footprint -> DVec2, Footprint -> VectorData, Footprint -> DAffine2 + )] + if_false: impl Node, +) -> T { + if condition { + if_true.eval(footprint).await + } else { + if_false.eval(footprint).await + } +}