this repo has no description
at main 2.8 kB view raw
1use std::{ 2 collections::HashMap, 3 sync::{Arc, Mutex}, 4}; 5 6// #[cfg(target_os = "windows")] 7use enigo::Enigo; 8 9use crate::{ 10 runtime::nodes::{ 11 conditional::{ 12 ifequal::ConditionalIfEqual, iffalse::ConditionalIfFalse, iftrue::ConditionalIfTrue, 13 }, debug::Debug, oscactions::sendchatbox::OSCActionsSendChatbox, osctrigger::OSCTrigger, shell::ShellCommand, statics::{float::StaticFloat, int::StaticInt, string::StaticString} 14 }, 15 structs::{nodes::Node, parameter_types::ParameterType}, 16}; 17 18// #[cfg(target_os = "windows")] 19use crate::runtime::nodes::press_key::PressKey; 20 21mod conditional; 22mod debug; 23mod oscactions; 24mod osctrigger; 25mod statics; 26mod shell; 27 28// #[cfg(target_os = "windows")] 29mod press_key; 30 31pub struct RuntimeNodeTree { 32 pub nodes: HashMap<String, Box<dyn RuntimeNode>>, 33} 34 35unsafe impl Send for RuntimeNodeTree {} 36 37impl RuntimeNodeTree { 38 pub fn from(tree: Vec<Node>, /*#[cfg(target_os = "windows")]*/ enigo: Arc<Mutex<Enigo>>) -> Self { 39 let mut runtime_nodes: HashMap<String, Box<dyn RuntimeNode>> = HashMap::new(); 40 for node in tree { 41 match node.type_id.as_str() { 42 "osctrigger" => { 43 runtime_nodes.insert(node.id.clone(), OSCTrigger::new(node)); 44 } 45 46 "staticstring" => { 47 runtime_nodes.insert(node.id.clone(), StaticString::new(node)); 48 } 49 "staticint" => { 50 runtime_nodes.insert(node.id.clone(), StaticInt::new(node)); 51 } 52 "staticfloat" => { 53 runtime_nodes.insert(node.id.clone(), StaticFloat::new(node)); 54 } 55 56 "iftrue" => { 57 runtime_nodes.insert(node.id.clone(), ConditionalIfTrue::new(node)); 58 } 59 "iffalse" => { 60 runtime_nodes.insert(node.id.clone(), ConditionalIfFalse::new(node)); 61 } 62 "ifequal" => { 63 runtime_nodes.insert(node.id.clone(), ConditionalIfEqual::new(node)); 64 } 65 66 "oscsendchatbox" => { 67 runtime_nodes.insert(node.id.clone(), OSCActionsSendChatbox::new(node)); 68 } 69 70 "debug" => { 71 runtime_nodes.insert(node.id.clone(), Debug::new(node)); 72 } 73 74 // #[cfg(target_os = "windows")] 75 "presskey" => { 76 runtime_nodes.insert(node.id.clone(), PressKey::new(node, enigo.clone())); 77 } 78 79 "shellcommand" => { 80 runtime_nodes.insert(node.id.clone(), ShellCommand::new(node)); 81 } 82 83 _ => {} 84 } 85 } 86 87 Self { 88 nodes: runtime_nodes, 89 } 90 } 91} 92 93pub trait RuntimeNode { 94 fn outputs(&self) -> Vec<Vec<(String, isize, isize)>>; // Node ID, input index, output value type 95 fn inputs(&self) -> Vec<Option<(String, isize, isize)>>; // Node ID, input index, output value type 96 97 fn execute(&mut self, args: Vec<ParameterType>) -> Vec<ParameterType>; // Then call functions on the second loop 98 fn is_entrypoint(&self) -> bool; 99}