phase2_demo/
phase2_demo.rs1use terrain_forge::{pipeline::*, Grid, Rng};
2
3fn main() {
4 println!("=== TerrainForge v0.4.0 Phase 2 Demo ===\n");
5
6 demo_conditional_pipeline();
8
9 demo_pipeline_templates();
11
12 demo_template_library();
14}
15
16fn demo_conditional_pipeline() {
17 println!("🔀 Demo 1: Conditional Pipeline Operations");
18
19 let mut grid = Grid::new(30, 20);
20 let mut context = PipelineContext::new();
21 let mut rng = Rng::new(12345);
22
23 let mut pipeline = ConditionalPipeline::new();
25
26 pipeline.add_operation(ConditionalOperation::simple(PipelineOperation::Algorithm {
28 name: "bsp".to_string(),
29 seed: Some(12345),
30 }));
31
32 pipeline.add_operation(ConditionalOperation::conditional(
34 PipelineOperation::Log {
35 message: "Evaluating floor density".to_string(),
36 },
37 PipelineCondition::Density {
38 min: Some(0.2),
39 max: Some(0.6),
40 },
41 vec![ConditionalOperation::simple(
42 PipelineOperation::SetParameter {
43 key: "density_status".to_string(),
44 value: "acceptable".to_string(),
45 },
46 )],
47 vec![ConditionalOperation::simple(
48 PipelineOperation::SetParameter {
49 key: "density_status".to_string(),
50 value: "out_of_range".to_string(),
51 },
52 )],
53 ));
54
55 let result = pipeline.execute(&mut grid, &mut context, &mut rng);
57
58 println!(
59 " Pipeline execution: {}",
60 if result.success {
61 "✅ Success"
62 } else {
63 "❌ Failed"
64 }
65 );
66 if let Some(msg) = result.message {
67 println!(" Message: {}", msg);
68 }
69
70 println!(" Floor tiles: {}", grid.count(|t| t.is_floor()));
71 println!(
72 " Density status: {}",
73 context
74 .get_parameter("density_status")
75 .unwrap_or(&"unknown".to_string())
76 );
77 println!(" Execution log: {:?}", context.execution_history());
78 println!();
79}
80
81fn demo_pipeline_templates() {
82 println!("📋 Demo 2: Pipeline Templates");
83
84 let template = PipelineTemplate::new("custom_dungeon", "Customizable dungeon template")
86 .with_parameter("algorithm", "cellular")
87 .with_parameter("seed", "54321")
88 .with_parameter("type", "dungeon")
89 .with_operation(ConditionalOperation::simple(PipelineOperation::Algorithm {
90 name: "{algorithm}".to_string(),
91 seed: Some(54321),
92 }))
93 .with_operation(ConditionalOperation::simple(
94 PipelineOperation::SetParameter {
95 key: "generation_type".to_string(),
96 value: "{type}".to_string(),
97 },
98 ));
99
100 let mut custom_params = std::collections::HashMap::new();
102 custom_params.insert("algorithm".to_string(), "bsp".to_string());
103 custom_params.insert("type".to_string(), "fortress".to_string());
104
105 let pipeline = template.instantiate(Some(custom_params));
106
107 let mut grid = Grid::new(25, 25);
108 let mut context = PipelineContext::new();
109 let mut rng = Rng::new(98765);
110
111 let result = pipeline.execute(&mut grid, &mut context, &mut rng);
112
113 println!(" Template: {}", template.name);
114 println!(" Description: {}", template.description);
115 println!(
116 " Execution: {}",
117 if result.success {
118 "✅ Success"
119 } else {
120 "❌ Failed"
121 }
122 );
123 println!(
124 " Generation type: {}",
125 context
126 .get_parameter("generation_type")
127 .unwrap_or(&"unknown".to_string())
128 );
129 println!(" Floor tiles: {}", grid.count(|t| t.is_floor()));
130 println!();
131}
132
133fn demo_template_library() {
134 println!("📚 Demo 3: Template Library");
135
136 let library = TemplateLibrary::new();
137
138 println!(" Available templates:");
139 for name in library.template_names() {
140 if let Some(template) = library.get_template(name) {
141 println!(" - {}: {}", name, template.description);
142 }
143 }
144
145 if let Some(template) = library.get_template("simple_dungeon") {
147 let pipeline = template.instantiate(None);
148
149 let mut grid = Grid::new(40, 30);
150 let mut context = PipelineContext::new();
151 let mut rng = Rng::new(11111);
152
153 let result = pipeline.execute(&mut grid, &mut context, &mut rng);
154
155 println!("\n Executed 'simple_dungeon' template:");
156 println!(
157 " Result: {}",
158 if result.success {
159 "✅ Success"
160 } else {
161 "❌ Failed"
162 }
163 );
164 println!(" Floor tiles: {}", grid.count(|t| t.is_floor()));
165 println!(" Steps executed: {}", context.execution_history().len());
166 }
167 println!();
168}