this repo has no description
1use anyhow::{bail, Result};
2
3use crate::{runtime::nodes::RuntimeNodeTree, structs::parameter_types::ParameterType};
4
5pub mod commands;
6pub mod nodes;
7
8// This is horrible. I know, I'm sorry.
9
10// TODO: Variables
11
12pub fn runtime_dry(
13 entry: String,
14 parameters: &Vec<ParameterType>,
15 tab: &mut RuntimeNodeTree,
16) -> Result<()> {
17 let node = tab.nodes.get_mut(&entry);
18 if node.is_none() {
19 bail!("Cannot find node");
20 }
21
22 let node = node.unwrap();
23
24 let output_map = node.outputs();
25 let args = node.execute_dry(parameters);
26
27 if args.is_some() {
28 let args = args.unwrap();
29
30 for i in 0..args.len() {
31 let arg = &args[i];
32
33 for output in &output_map[i] {
34 if output.2 == 5 {
35 break;
36 } // Ignore flow outputs
37
38 let next_node = tab.nodes.get_mut(&output.0);
39 if next_node.is_none() {
40 bail!("Cannot find node {}", output.0)
41 }
42
43 let next_node = next_node.unwrap();
44 let can_update = next_node.update_arg(output.1 as usize, arg.clone());
45
46 if can_update {
47 runtime_dry(output.0.clone(), &vec![], tab)?;
48 }
49 }
50 }
51 }
52
53 Ok(())
54}
55
56pub fn runtime(entry: String, tab: &mut RuntimeNodeTree) -> Result<()> {
57 let node = tab.nodes.get_mut(&entry);
58 if node.is_none() {
59 bail!("Cannot find node");
60 }
61
62 let node = node.unwrap();
63
64 let next = node.execute();
65 if next.is_some() {
66 let next = next.unwrap();
67
68 let outputs = node.outputs();
69
70 for i in 0..next.len() {
71 let arg = &next[i];
72 if i >= outputs.len() {
73 break;
74 }
75
76 for output in &outputs[i] {
77 if let ParameterType::Flow(next) = arg {
78 if *next {
79 // This is a flow output, continue
80 runtime(output.0.clone(), tab)?;
81 }
82 }
83 }
84 }
85 }
86
87 Ok(())
88}