rust/mapgen/src/lib.rs
branchtransitional_engine
changeset 16061 31cc1e450273
parent 16060 1b1d5729ff3e
child 16062 1860852892c0
--- a/rust/mapgen/src/lib.rs	Wed Sep 04 14:54:34 2024 +0200
+++ b/rust/mapgen/src/lib.rs	Tue Sep 10 13:56:51 2024 +0200
@@ -14,6 +14,7 @@
     wavefront_collapse::generator::{
         TemplateDescription as WfcTemplate, WavefrontCollapseLandGenerator,
     },
+    maze::{MazeTemplate, MazeLandGenerator},
     LandGenerationParameters, LandGenerator,
 };
 use rand::{seq::SliceRandom, Rng};
@@ -176,6 +177,27 @@
     }
 }
 
+impl MapGenerator<MazeTemplate> {
+    pub fn import_yaml_templates(&mut self, text: &str) {
+        let mut desc: MazeTemplateCollectionDesc = serde_yaml::from_str(text).unwrap();
+        let templates = std::mem::take(&mut desc.templates);
+        self.templates = desc
+            .template_types
+            .into_iter()
+            .map(|(size, indices)| {
+                (
+                    TemplateType(size),
+                    indices.iter().map(|i| (&templates[*i]).into()).collect(),
+                )
+            })
+            .collect();
+    }
+
+    pub fn build_generator(&self, template: MazeTemplate) -> impl LandGenerator {
+        MazeLandGenerator::new(template)
+    }
+}
+
 #[derive(Debug, Clone, Copy, PartialEq, Eq)]
 struct Color(u32);