rust/landgen/src/template_based.rs
changeset 14054 3185fb34f3b5
parent 14052 9c817b2eedae
child 14066 649ccb9f8cfd
--- a/rust/landgen/src/template_based.rs	Thu Nov 01 01:07:26 2018 +0100
+++ b/rust/landgen/src/template_based.rs	Thu Nov 01 03:38:13 2018 +0300
@@ -46,7 +46,7 @@
     }
 }
 
-struct OutlineTemplate {
+pub struct OutlineTemplate {
     islands: Vec<Vec<Rect>>,
     fill_points: Vec<Point>,
     size: Size,
@@ -56,7 +56,54 @@
     is_negative: bool,
 }
 
-struct TemplatedLandGenerator {
+impl OutlineTemplate {
+    pub fn new(size: Size) -> Self {
+        OutlineTemplate {
+            size,
+            islands: Vec::new(),
+            fill_points: Vec::new(),
+            can_flip: false,
+            can_invert: false,
+            can_mirror: false,
+            is_negative: false
+        }
+    }
+
+    pub fn flippable(self) -> Self {
+        Self { can_flip: true, ..self }
+    }
+
+    pub fn mirrorable(self) -> Self {
+        Self { can_mirror: true, ..self }
+    }
+
+    pub fn invertable(self) -> Self {
+        Self { can_invert: true, ..self }
+    }
+
+    pub fn negative(self) -> Self {
+        Self { is_negative: true, ..self }
+    }
+
+    pub fn with_fill_points(self, fill_points: Vec<Point>) -> Self
+    {
+        Self { fill_points, ..self }
+    }
+
+    pub fn with_islands(mut self, islands: Vec<Vec<Rect>>) -> Self {
+        Self { islands, ..self }
+    }
+
+    pub fn add_fill_points(mut self, points: &[Point]) -> Self {
+        self.fill_points.extend_from_slice(points); self
+    }
+
+    pub fn add_island(mut self, island: &[Rect]) -> Self {
+        self.islands.push(island.into()); self
+    }
+}
+
+pub struct TemplatedLandGenerator {
     outline_template: OutlineTemplate,
 }