author | unC0Rr |
Mon, 13 Feb 2023 12:31:30 +0100 | |
branch | transitional_engine |
changeset 15922 | da6b67f13c12 |
child 15923 | d46ad15c6dec |
permissions | -rw-r--r-- |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
1 |
use integral_geometry::{Point, Rect, Size}; |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
2 |
use land2d::Land2D; |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
3 |
use landgen::{ |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
4 |
outline_template_based::outline_template::OutlineTemplate, LandGenerationParameters, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
5 |
}; |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
6 |
use serde_derive::Deserialize; |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
7 |
use serde_yaml; |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
8 |
use std::{borrow::Borrow, collections::hash_map::HashMap, mem::replace}; |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
9 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
10 |
#[derive(Deserialize)] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
11 |
pub struct PointDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
12 |
x: u32, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
13 |
y: u32, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
14 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
15 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
16 |
#[derive(Deserialize)] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
17 |
pub struct RectDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
18 |
x: u32, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
19 |
y: u32, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
20 |
w: u32, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
21 |
h: u32, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
22 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
23 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
24 |
#[derive(Deserialize)] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
25 |
pub struct TemplateDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
26 |
width: usize, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
27 |
height: usize, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
28 |
can_flip: bool, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
29 |
can_invert: bool, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
30 |
can_mirror: bool, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
31 |
is_negative: bool, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
32 |
put_girders: bool, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
33 |
max_hedgehogs: u8, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
34 |
outline_points: Vec<Vec<RectDesc>>, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
35 |
fill_points: Vec<PointDesc>, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
36 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
37 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
38 |
#[derive(Deserialize)] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
39 |
pub struct TemplateCollectionDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
40 |
pub templates: Vec<TemplateDesc>, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
41 |
pub template_types: HashMap<String, Vec<usize>>, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
42 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
43 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
44 |
impl From<&TemplateDesc> for OutlineTemplate { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
45 |
fn from(desc: &TemplateDesc) -> Self { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
46 |
OutlineTemplate { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
47 |
islands: desc |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
48 |
.outline_points |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
49 |
.iter() |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
50 |
.map(|v| { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
51 |
v.iter() |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
52 |
.map(|r| { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
53 |
Rect::from_size( |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
54 |
Point::new(r.x as i32, r.y as i32), |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
55 |
Size::new(r.w as usize, r.h as usize), |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
56 |
) |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
57 |
}) |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
58 |
.collect() |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
59 |
}) |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
60 |
.collect(), |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
61 |
fill_points: desc |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
62 |
.fill_points |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
63 |
.iter() |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
64 |
.map(|p| Point::new(p.x as i32, p.y as i32)) |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
65 |
.collect(), |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
66 |
size: Size::new(desc.width, desc.height), |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
67 |
can_flip: desc.can_flip, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
68 |
can_invert: desc.can_invert, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
69 |
can_mirror: desc.can_mirror, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
70 |
is_negative: desc.is_negative, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
71 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
72 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
73 |
} |