pipeline_templates/
pipeline_templates.rs1use terrain_forge::{pipeline::*, Grid, Rng};
2
3fn main() {
4 println!("=== Pipeline Templates Demo ===\n");
5
6 println!("1. Built-in Template Library:");
8
9 let library = TemplateLibrary::new();
10 println!(" Available templates:");
11 for name in library.template_names() {
12 if let Some(template) = library.get_template(name) {
13 println!(" - {}: {}", name, template.description);
14 }
15 }
16
17 if let Some(template) = library.get_template("simple_dungeon") {
19 let pipeline = template.instantiate(None);
20
21 let mut grid = Grid::new(40, 30);
22 let mut context = PipelineContext::new();
23 let mut rng = Rng::new(11111);
24
25 let result = pipeline.execute(&mut grid, &mut context, &mut rng);
26
27 println!("\n Executed 'simple_dungeon' template:");
28 println!(
29 " Result: {}",
30 if result.success {
31 "✅ Success"
32 } else {
33 "❌ Failed"
34 }
35 );
36 println!(" Floor tiles: {}", grid.count(|t| t.is_floor()));
37 println!(" Steps executed: {}", context.execution_history().len());
38 }
39
40 println!("\n2. Custom Parameterized Template:");
42
43 let custom_template = PipelineTemplate::new(
44 "adaptive_dungeon",
45 "Dungeon that adapts based on size parameter",
46 )
47 .with_parameter("size", "medium")
48 .with_parameter("algorithm", "bsp")
49 .with_parameter("complexity", "normal")
50 .with_operation(ConditionalOperation::simple(PipelineOperation::Log {
51 message: "Generating {size} dungeon with {algorithm}".to_string(),
52 }))
53 .with_operation(ConditionalOperation::simple(PipelineOperation::Algorithm {
54 name: "{algorithm}".to_string(),
55 seed: Some(22222),
56 }))
57 .with_operation(ConditionalOperation::simple(
58 PipelineOperation::SetParameter {
59 key: "dungeon_type".to_string(),
60 value: "{size}_{complexity}".to_string(),
61 },
62 ));
63
64 println!(" Default parameters:");
66 let pipeline1 = custom_template.instantiate(None);
67 let mut grid1 = Grid::new(30, 20);
68 let mut context1 = PipelineContext::new();
69 let mut rng1 = Rng::new(22222);
70
71 let result1 = pipeline1.execute(&mut grid1, &mut context1, &mut rng1);
72 println!(
73 " Result: {}",
74 if result1.success {
75 "✅ Success"
76 } else {
77 "❌ Failed"
78 }
79 );
80 println!(
81 " Dungeon type: {}",
82 context1
83 .get_parameter("dungeon_type")
84 .unwrap_or(&"unknown".to_string())
85 );
86
87 println!(" Custom parameters:");
89 let mut custom_params = std::collections::HashMap::new();
90 custom_params.insert("size".to_string(), "large".to_string());
91 custom_params.insert("algorithm".to_string(), "cellular".to_string());
92 custom_params.insert("complexity".to_string(), "high".to_string());
93
94 let pipeline2 = custom_template.instantiate(Some(custom_params));
95 let mut grid2 = Grid::new(50, 40);
96 let mut context2 = PipelineContext::new();
97 let mut rng2 = Rng::new(33333);
98
99 let result2 = pipeline2.execute(&mut grid2, &mut context2, &mut rng2);
100 println!(
101 " Result: {}",
102 if result2.success {
103 "✅ Success"
104 } else {
105 "❌ Failed"
106 }
107 );
108 println!(
109 " Dungeon type: {}",
110 context2
111 .get_parameter("dungeon_type")
112 .unwrap_or(&"unknown".to_string())
113 );
114 println!(" Floor tiles: {}", grid2.count(|t| t.is_floor()));
115
116 println!("\n3. Template with Conditional Logic:");
118
119 let smart_template = PipelineTemplate::new(
120 "smart_generator",
121 "Generator that chooses algorithm based on size",
122 )
123 .with_parameter("width", "40")
124 .with_parameter("height", "30")
125 .with_operation(ConditionalOperation::simple(PipelineOperation::Algorithm {
126 name: "bsp".to_string(),
127 seed: Some(44444),
128 }))
129 .with_operation(ConditionalOperation::conditional(
130 PipelineOperation::Log {
131 message: "Analyzing generated map".to_string(),
132 },
133 PipelineCondition::Density {
134 min: Some(0.2),
135 max: Some(0.6),
136 },
137 vec![ConditionalOperation::simple(
138 PipelineOperation::SetParameter {
139 key: "analysis".to_string(),
140 value: "optimal_density".to_string(),
141 },
142 )],
143 vec![ConditionalOperation::simple(
144 PipelineOperation::SetParameter {
145 key: "analysis".to_string(),
146 value: "suboptimal_density".to_string(),
147 },
148 )],
149 ));
150
151 let pipeline3 = smart_template.instantiate(None);
152 let mut grid3 = Grid::new(40, 30);
153 let mut context3 = PipelineContext::new();
154 let mut rng3 = Rng::new(44444);
155
156 let result3 = pipeline3.execute(&mut grid3, &mut context3, &mut rng3);
157 println!(
158 " Result: {}",
159 if result3.success {
160 "✅ Success"
161 } else {
162 "❌ Failed"
163 }
164 );
165 println!(
166 " Analysis: {}",
167 context3
168 .get_parameter("analysis")
169 .unwrap_or(&"unknown".to_string())
170 );
171 println!(
172 " Density: {:.2}",
173 grid3.count(|t| t.is_floor()) as f32 / (grid3.width() * grid3.height()) as f32
174 );
175}