pub struct TemplateLibrary { /* private fields */ }Expand description
Library of built-in pipeline templates
Implementations§
Source§impl TemplateLibrary
impl TemplateLibrary
Sourcepub fn new() -> Self
pub fn new() -> Self
Create new template library with built-in templates
Examples found in repository?
examples/phase2_demo.rs (line 136)
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 // Use built-in template
146 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}More examples
examples/pipeline_templates.rs (line 9)
3fn main() {
4 println!("=== Pipeline Templates Demo ===\n");
5
6 // Demo 1: Using built-in templates
7 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 // Use the simple_dungeon template
18 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 // Demo 2: Custom template with parameters
41 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 // Instantiate with default parameters
65 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 // Instantiate with custom parameters
88 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 // Demo 3: Template with conditional logic
117 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}examples/complete_workflow.rs (line 11)
3fn main() {
4 println!("=== Complete Phase 1 & 2 Feature Demo ===\n");
5
6 // Demo: Complete workflow using all new features
7 println!("🏰 Generating Advanced Multi-Feature Dungeon\n");
8
9 // Step 1: Use pipeline template with custom parameters
10 println!("1. Pipeline Template Generation:");
11 let library = TemplateLibrary::new();
12 let template = library.get_template("simple_dungeon").unwrap();
13
14 let mut custom_params = std::collections::HashMap::new();
15 custom_params.insert("seed".to_string(), "12345".to_string());
16
17 let pipeline = template.instantiate(Some(custom_params));
18
19 let mut grid = Grid::new(40, 30);
20 let mut context = PipelineContext::new();
21 let mut rng = Rng::new(12345);
22
23 let result = pipeline.execute(&mut grid, &mut context, &mut rng);
24 println!(
25 " Template execution: {}",
26 if result.success {
27 "✅ Success"
28 } else {
29 "❌ Failed"
30 }
31 );
32 println!(" Floor tiles: {}", grid.count(|t| t.is_floor()));
33
34 // Step 2: Extract semantic information
35 println!("\n2. Semantic Analysis:");
36 let extractor = SemanticExtractor::for_rooms();
37 let mut semantic = extractor.extract(&grid, &mut rng);
38
39 println!(" Regions found: {}", semantic.regions.len());
40 println!(" Original markers: {}", semantic.markers.len());
41
42 // Step 3: Add hierarchical markers based on regions
43 println!("\n3. Hierarchical Marker Placement:");
44 let mut quest_count = 0;
45 let mut loot_count = 0;
46 let mut encounter_count = 0;
47
48 for (i, region) in semantic.regions.iter().enumerate() {
49 if !region.cells.is_empty() {
50 let (x, y) = region.cells[region.cells.len() / 2]; // Middle of region
51
52 match i % 3 {
53 0 => {
54 // Quest area
55 semantic.markers.push(Marker::new(
56 x,
57 y,
58 MarkerType::QuestObjective {
59 priority: (i % 3 + 1) as u8,
60 },
61 ));
62 quest_count += 1;
63 }
64 1 => {
65 // Loot area
66 semantic.markers.push(Marker::new(
67 x,
68 y,
69 MarkerType::LootTier {
70 tier: (i % 3 + 1) as u8,
71 },
72 ));
73 loot_count += 1;
74 }
75 2 => {
76 // Encounter area
77 if i == 2 {
78 semantic
79 .markers
80 .push(Marker::new(x, y, MarkerType::BossRoom));
81 } else {
82 semantic.markers.push(Marker::new(
83 x,
84 y,
85 MarkerType::EncounterZone {
86 difficulty: (i % 5 + 1) as u8,
87 },
88 ));
89 }
90 encounter_count += 1;
91 }
92 _ => {}
93 }
94 }
95 }
96
97 println!(" Added {} quest markers", quest_count);
98 println!(" Added {} loot markers", loot_count);
99 println!(" Added {} encounter markers", encounter_count);
100
101 // Step 4: Validate with requirements
102 println!("\n4. Requirement Validation:");
103 let mut requirements = SemanticRequirements::none();
104 requirements.min_regions.insert("Hall".to_string(), 1);
105 requirements
106 .required_markers
107 .insert(MarkerType::Custom("PlayerStart".to_string()), 1);
108
109 let validation_result = requirements.validate(&semantic);
110 println!(
111 " Requirements met: {}",
112 if validation_result {
113 "✅ Yes"
114 } else {
115 "❌ No"
116 }
117 );
118
119 // Step 5: Marker constraints analysis
120 println!("\n5. Marker Constraint Analysis:");
121 let quest_constraints = MarkerConstraints::quest_objective();
122 let loot_constraints = MarkerConstraints::loot();
123
124 println!(" Quest marker constraints:");
125 println!(
126 " Min distance (same type): {:?}",
127 quest_constraints.min_distance_same
128 );
129 println!(
130 " Excluded types: {} types",
131 quest_constraints.exclude_types.len()
132 );
133
134 println!(" Loot marker constraints:");
135 println!(
136 " Min distance (same type): {:?}",
137 loot_constraints.min_distance_same
138 );
139 println!(
140 " Min distance (any): {:?}",
141 loot_constraints.min_distance_any
142 );
143
144 // Step 6: Multi-floor connectivity simulation
145 println!("\n6. Multi-Floor Connectivity:");
146
147 // Create a second floor based on the first
148 let mut floor2 = Grid::new(40, 30);
149 // Copy some areas from floor 1 to create overlapping regions
150 for y in 5..25 {
151 for x in 5..35 {
152 if grid.get(x, y).is_some_and(|t| t.is_floor()) && rng.random() < 0.6 {
153 floor2.set(x, y, terrain_forge::Tile::Floor);
154 }
155 }
156 }
157
158 let floors = vec![grid.clone(), floor2];
159 let mut connectivity = VerticalConnectivity::new();
160
161 connectivity.analyze_stair_candidates(&floors, 2);
162 connectivity.place_stairs(3);
163
164 println!(" Floor 1 tiles: {}", floors[0].count(|t| t.is_floor()));
165 println!(" Floor 2 tiles: {}", floors[1].count(|t| t.is_floor()));
166 println!(
167 " Stair candidates: {}",
168 connectivity.stair_candidates.len()
169 );
170 println!(" Stairs placed: {}", connectivity.stairs.len());
171
172 // Step 7: Final summary
173 println!("\n🎯 Generation Summary:");
174 println!(" Grid size: {}x{}", grid.width(), grid.height());
175 println!(" Total floor area: {}", grid.count(|t| t.is_floor()));
176 println!(
177 " Density: {:.1}%",
178 (grid.count(|t| t.is_floor()) as f32 / (grid.width() * grid.height()) as f32) * 100.0
179 );
180 println!(" Regions: {}", semantic.regions.len());
181 println!(" Total markers: {}", semantic.markers.len());
182
183 // Group markers by category
184 let mut categories = std::collections::HashMap::new();
185 for marker in &semantic.markers {
186 *categories.entry(marker.marker_type.category()).or_insert(0) += 1;
187 }
188
189 println!(" Marker distribution:");
190 for (category, count) in categories {
191 println!(" {}: {}", category, count);
192 }
193
194 println!(
195 " Pipeline steps executed: {}",
196 context.execution_history().len()
197 );
198 println!(" Multi-floor stairs: {}", connectivity.stairs.len());
199
200 println!("\n✨ Advanced dungeon generation complete!");
201}Sourcepub fn add_template(&mut self, template: PipelineTemplate)
pub fn add_template(&mut self, template: PipelineTemplate)
Add a template to the library
Sourcepub fn get_template(&self, name: &str) -> Option<&PipelineTemplate>
pub fn get_template(&self, name: &str) -> Option<&PipelineTemplate>
Get template by name
Examples found in repository?
examples/phase2_demo.rs (line 140)
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 // Use built-in template
146 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}More examples
examples/pipeline_templates.rs (line 12)
3fn main() {
4 println!("=== Pipeline Templates Demo ===\n");
5
6 // Demo 1: Using built-in templates
7 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 // Use the simple_dungeon template
18 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 // Demo 2: Custom template with parameters
41 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 // Instantiate with default parameters
65 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 // Instantiate with custom parameters
88 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 // Demo 3: Template with conditional logic
117 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}examples/complete_workflow.rs (line 12)
3fn main() {
4 println!("=== Complete Phase 1 & 2 Feature Demo ===\n");
5
6 // Demo: Complete workflow using all new features
7 println!("🏰 Generating Advanced Multi-Feature Dungeon\n");
8
9 // Step 1: Use pipeline template with custom parameters
10 println!("1. Pipeline Template Generation:");
11 let library = TemplateLibrary::new();
12 let template = library.get_template("simple_dungeon").unwrap();
13
14 let mut custom_params = std::collections::HashMap::new();
15 custom_params.insert("seed".to_string(), "12345".to_string());
16
17 let pipeline = template.instantiate(Some(custom_params));
18
19 let mut grid = Grid::new(40, 30);
20 let mut context = PipelineContext::new();
21 let mut rng = Rng::new(12345);
22
23 let result = pipeline.execute(&mut grid, &mut context, &mut rng);
24 println!(
25 " Template execution: {}",
26 if result.success {
27 "✅ Success"
28 } else {
29 "❌ Failed"
30 }
31 );
32 println!(" Floor tiles: {}", grid.count(|t| t.is_floor()));
33
34 // Step 2: Extract semantic information
35 println!("\n2. Semantic Analysis:");
36 let extractor = SemanticExtractor::for_rooms();
37 let mut semantic = extractor.extract(&grid, &mut rng);
38
39 println!(" Regions found: {}", semantic.regions.len());
40 println!(" Original markers: {}", semantic.markers.len());
41
42 // Step 3: Add hierarchical markers based on regions
43 println!("\n3. Hierarchical Marker Placement:");
44 let mut quest_count = 0;
45 let mut loot_count = 0;
46 let mut encounter_count = 0;
47
48 for (i, region) in semantic.regions.iter().enumerate() {
49 if !region.cells.is_empty() {
50 let (x, y) = region.cells[region.cells.len() / 2]; // Middle of region
51
52 match i % 3 {
53 0 => {
54 // Quest area
55 semantic.markers.push(Marker::new(
56 x,
57 y,
58 MarkerType::QuestObjective {
59 priority: (i % 3 + 1) as u8,
60 },
61 ));
62 quest_count += 1;
63 }
64 1 => {
65 // Loot area
66 semantic.markers.push(Marker::new(
67 x,
68 y,
69 MarkerType::LootTier {
70 tier: (i % 3 + 1) as u8,
71 },
72 ));
73 loot_count += 1;
74 }
75 2 => {
76 // Encounter area
77 if i == 2 {
78 semantic
79 .markers
80 .push(Marker::new(x, y, MarkerType::BossRoom));
81 } else {
82 semantic.markers.push(Marker::new(
83 x,
84 y,
85 MarkerType::EncounterZone {
86 difficulty: (i % 5 + 1) as u8,
87 },
88 ));
89 }
90 encounter_count += 1;
91 }
92 _ => {}
93 }
94 }
95 }
96
97 println!(" Added {} quest markers", quest_count);
98 println!(" Added {} loot markers", loot_count);
99 println!(" Added {} encounter markers", encounter_count);
100
101 // Step 4: Validate with requirements
102 println!("\n4. Requirement Validation:");
103 let mut requirements = SemanticRequirements::none();
104 requirements.min_regions.insert("Hall".to_string(), 1);
105 requirements
106 .required_markers
107 .insert(MarkerType::Custom("PlayerStart".to_string()), 1);
108
109 let validation_result = requirements.validate(&semantic);
110 println!(
111 " Requirements met: {}",
112 if validation_result {
113 "✅ Yes"
114 } else {
115 "❌ No"
116 }
117 );
118
119 // Step 5: Marker constraints analysis
120 println!("\n5. Marker Constraint Analysis:");
121 let quest_constraints = MarkerConstraints::quest_objective();
122 let loot_constraints = MarkerConstraints::loot();
123
124 println!(" Quest marker constraints:");
125 println!(
126 " Min distance (same type): {:?}",
127 quest_constraints.min_distance_same
128 );
129 println!(
130 " Excluded types: {} types",
131 quest_constraints.exclude_types.len()
132 );
133
134 println!(" Loot marker constraints:");
135 println!(
136 " Min distance (same type): {:?}",
137 loot_constraints.min_distance_same
138 );
139 println!(
140 " Min distance (any): {:?}",
141 loot_constraints.min_distance_any
142 );
143
144 // Step 6: Multi-floor connectivity simulation
145 println!("\n6. Multi-Floor Connectivity:");
146
147 // Create a second floor based on the first
148 let mut floor2 = Grid::new(40, 30);
149 // Copy some areas from floor 1 to create overlapping regions
150 for y in 5..25 {
151 for x in 5..35 {
152 if grid.get(x, y).is_some_and(|t| t.is_floor()) && rng.random() < 0.6 {
153 floor2.set(x, y, terrain_forge::Tile::Floor);
154 }
155 }
156 }
157
158 let floors = vec![grid.clone(), floor2];
159 let mut connectivity = VerticalConnectivity::new();
160
161 connectivity.analyze_stair_candidates(&floors, 2);
162 connectivity.place_stairs(3);
163
164 println!(" Floor 1 tiles: {}", floors[0].count(|t| t.is_floor()));
165 println!(" Floor 2 tiles: {}", floors[1].count(|t| t.is_floor()));
166 println!(
167 " Stair candidates: {}",
168 connectivity.stair_candidates.len()
169 );
170 println!(" Stairs placed: {}", connectivity.stairs.len());
171
172 // Step 7: Final summary
173 println!("\n🎯 Generation Summary:");
174 println!(" Grid size: {}x{}", grid.width(), grid.height());
175 println!(" Total floor area: {}", grid.count(|t| t.is_floor()));
176 println!(
177 " Density: {:.1}%",
178 (grid.count(|t| t.is_floor()) as f32 / (grid.width() * grid.height()) as f32) * 100.0
179 );
180 println!(" Regions: {}", semantic.regions.len());
181 println!(" Total markers: {}", semantic.markers.len());
182
183 // Group markers by category
184 let mut categories = std::collections::HashMap::new();
185 for marker in &semantic.markers {
186 *categories.entry(marker.marker_type.category()).or_insert(0) += 1;
187 }
188
189 println!(" Marker distribution:");
190 for (category, count) in categories {
191 println!(" {}: {}", category, count);
192 }
193
194 println!(
195 " Pipeline steps executed: {}",
196 context.execution_history().len()
197 );
198 println!(" Multi-floor stairs: {}", connectivity.stairs.len());
199
200 println!("\n✨ Advanced dungeon generation complete!");
201}Sourcepub fn template_names(&self) -> Vec<&String>
pub fn template_names(&self) -> Vec<&String>
List all template names
Examples found in repository?
examples/phase2_demo.rs (line 139)
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 // Use built-in template
146 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}More examples
examples/pipeline_templates.rs (line 11)
3fn main() {
4 println!("=== Pipeline Templates Demo ===\n");
5
6 // Demo 1: Using built-in templates
7 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 // Use the simple_dungeon template
18 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 // Demo 2: Custom template with parameters
41 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 // Instantiate with default parameters
65 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 // Instantiate with custom parameters
88 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 // Demo 3: Template with conditional logic
117 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}Trait Implementations§
Source§impl Clone for TemplateLibrary
impl Clone for TemplateLibrary
Source§fn clone(&self) -> TemplateLibrary
fn clone(&self) -> TemplateLibrary
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TemplateLibrary
impl Debug for TemplateLibrary
Auto Trait Implementations§
impl Freeze for TemplateLibrary
impl RefUnwindSafe for TemplateLibrary
impl Send for TemplateLibrary
impl Sync for TemplateLibrary
impl Unpin for TemplateLibrary
impl UnwindSafe for TemplateLibrary
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more