|
1 use super::{ |
|
2 outline::OutlinePoints, outline_template::OutlineTemplate}; |
|
3 use crate::{LandGenerationParameters, |
|
4 LandGenerator, |
|
5 }; |
|
6 use land2d::Land2D; |
|
7 |
|
8 pub struct TemplatedLandGenerator { |
|
9 outline_template: OutlineTemplate, |
|
10 } |
|
11 |
|
12 impl TemplatedLandGenerator { |
|
13 pub fn new(outline_template: OutlineTemplate) -> Self { |
|
14 Self { outline_template } |
|
15 } |
|
16 } |
|
17 |
|
18 impl LandGenerator for TemplatedLandGenerator { |
|
19 fn generate_land<T: Copy + PartialEq + Default, I: Iterator<Item = u32>>( |
|
20 &self, |
|
21 parameters: &LandGenerationParameters<T>, |
|
22 random_numbers: &mut I, |
|
23 ) -> Land2D<T> { |
|
24 let mut land = Land2D::new(&self.outline_template.size, parameters.basic); |
|
25 |
|
26 let mut points = OutlinePoints::from_outline_template( |
|
27 &self.outline_template, |
|
28 land.play_box(), |
|
29 land.size().size(), |
|
30 random_numbers, |
|
31 ); |
|
32 |
|
33 // mirror |
|
34 if self.outline_template.can_mirror { |
|
35 if let Some(b) = random_numbers.next() { |
|
36 if b & 1 != 0 { |
|
37 points.mirror(); |
|
38 } |
|
39 } |
|
40 } |
|
41 |
|
42 // flip |
|
43 if self.outline_template.can_flip { |
|
44 if let Some(b) = random_numbers.next() { |
|
45 if b & 1 != 0 { |
|
46 points.flip(); |
|
47 } |
|
48 } |
|
49 } |
|
50 |
|
51 if !parameters.skip_distort { |
|
52 points.distort(parameters.distance_divisor, random_numbers); |
|
53 } |
|
54 |
|
55 if !parameters.skip_bezier { |
|
56 points.bezierize(5); |
|
57 } |
|
58 |
|
59 points.draw(&mut land, parameters.zero); |
|
60 |
|
61 for p in &points.fill_points { |
|
62 land.fill(*p, parameters.zero, parameters.zero) |
|
63 } |
|
64 |
|
65 points.draw(&mut land, parameters.basic); |
|
66 |
|
67 land |
|
68 } |
|
69 } |