author | unC0Rr |
Tue, 28 Jan 2025 15:49:45 +0100 | |
changeset 16073 | 5d302b12d837 |
parent 16064 | 07cb6dbc8444 |
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}; |
15923
d46ad15c6dec
Get wavefront collapse generator to work in engine
unC0Rr
parents:
15922
diff
changeset
|
2 |
|
15924 | 3 |
use landgen::outline_template_based::outline_template::OutlineTemplate; |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
4 |
use serde_derive::Deserialize; |
15923
d46ad15c6dec
Get wavefront collapse generator to work in engine
unC0Rr
parents:
15922
diff
changeset
|
5 |
|
15924 | 6 |
use std::collections::hash_map::HashMap; |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
7 |
|
16044
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
8 |
#[derive(Deserialize, Clone)] |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
9 |
pub struct PointDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
10 |
x: u32, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
11 |
y: u32, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
12 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
13 |
|
16044
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
14 |
#[derive(Deserialize, Clone)] |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
15 |
pub struct RectDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
16 |
x: u32, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
17 |
y: u32, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
18 |
w: u32, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
19 |
h: u32, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
20 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
21 |
|
16044
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
22 |
#[derive(Deserialize, Clone)] |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
23 |
pub struct TemplateDesc { |
16073 | 24 |
width: u32, |
25 |
height: u32, |
|
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
26 |
can_flip: bool, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
27 |
can_invert: bool, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
28 |
can_mirror: bool, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
29 |
is_negative: bool, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
30 |
put_girders: bool, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
31 |
max_hedgehogs: u8, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
32 |
outline_points: Vec<Vec<RectDesc>>, |
16044
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
33 |
walls: Option<Vec<Vec<RectDesc>>>, |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
34 |
fill_points: Vec<PointDesc>, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
35 |
} |
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 |
#[derive(Deserialize)] |
16029 | 38 |
pub struct TemplateTypeDesc { |
39 |
pub indices: Vec<usize>, |
|
40 |
pub force_invert: Option<bool>, |
|
41 |
} |
|
42 |
||
43 |
#[derive(Deserialize)] |
|
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
44 |
pub struct TemplateCollectionDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
45 |
pub templates: Vec<TemplateDesc>, |
16029 | 46 |
pub template_types: HashMap<String, TemplateTypeDesc>, |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
47 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
48 |
|
16044
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
49 |
impl From<TemplateDesc> for OutlineTemplate { |
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
50 |
fn from(desc: TemplateDesc) -> Self { |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
51 |
OutlineTemplate { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
52 |
islands: desc |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
53 |
.outline_points |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
54 |
.iter() |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
55 |
.map(|v| { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
56 |
v.iter() |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
57 |
.map(|r| { |
16073 | 58 |
Rect::from_size(Point::new(r.x as i32, r.y as i32), Size::new(r.w, r.h)) |
15922
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 |
}) |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
62 |
.collect(), |
16044
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
63 |
walls: desc |
16064 | 64 |
.walls |
65 |
.unwrap_or_default() |
|
16044
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
66 |
.iter() |
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
67 |
.map(|v| { |
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
68 |
v.iter() |
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
69 |
.map(|r| { |
16073 | 70 |
Rect::from_size(Point::new(r.x as i32, r.y as i32), Size::new(r.w, r.h)) |
16044
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
71 |
}) |
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
72 |
.collect() |
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
73 |
}) |
5c941f5deeec
* Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents:
16029
diff
changeset
|
74 |
.collect(), |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
75 |
fill_points: desc |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
76 |
.fill_points |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
77 |
.iter() |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
78 |
.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
|
79 |
.collect(), |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
80 |
size: Size::new(desc.width, desc.height), |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
81 |
can_flip: desc.can_flip, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
82 |
can_invert: desc.can_invert, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
83 |
can_mirror: desc.can_mirror, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
84 |
is_negative: desc.is_negative, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
85 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
86 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
87 |
} |