author | unC0Rr |
Tue, 10 Sep 2024 13:56:51 +0200 | |
branch | transitional_engine |
changeset 16061 | 31cc1e450273 |
parent 15955 | b0e8cc72bfef |
permissions | -rw-r--r-- |
15954 | 1 |
use integral_geometry::Size; |
15953
d46ad15c6dec
Get wavefront collapse generator to work in engine
unC0Rr
parents:
15952
diff
changeset
|
2 |
|
15954 | 3 |
use landgen::wavefront_collapse::generator::*; |
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
4 |
use serde_derive::Deserialize; |
15953
d46ad15c6dec
Get wavefront collapse generator to work in engine
unC0Rr
parents:
15952
diff
changeset
|
5 |
|
15954 | 6 |
use std::collections::hash_map::HashMap; |
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
7 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
8 |
#[derive(Deserialize)] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
9 |
#[serde(remote = "EdgeDescription")] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
10 |
pub struct EdgeDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
11 |
pub name: String, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
12 |
pub reversed: Option<bool>, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
13 |
pub symmetrical: Option<bool>, |
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 |
#[serde(remote = "EdgesDescription")] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
18 |
pub struct EdgesDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
19 |
#[serde(with = "EdgeDesc")] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
20 |
pub top: EdgeDescription, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
21 |
#[serde(with = "EdgeDesc")] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
22 |
pub right: EdgeDescription, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
23 |
#[serde(with = "EdgeDesc")] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
24 |
pub bottom: EdgeDescription, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
25 |
#[serde(with = "EdgeDesc")] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
26 |
pub left: EdgeDescription, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
27 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
28 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
29 |
#[derive(Deserialize)] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
30 |
#[serde(remote = "TileDescription")] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
31 |
pub struct TileDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
32 |
pub name: String, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
33 |
#[serde(with = "EdgesDesc")] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
34 |
pub edges: EdgesDescription, |
15954 | 35 |
pub is_negative: Option<bool>, |
36 |
pub can_flip: Option<bool>, |
|
37 |
pub can_mirror: Option<bool>, |
|
38 |
pub can_rotate90: Option<bool>, |
|
39 |
pub can_rotate180: Option<bool>, |
|
40 |
pub can_rotate270: Option<bool>, |
|
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
41 |
} |
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 |
#[derive(Deserialize)] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
44 |
pub struct TileDescriptionHelper(#[serde(with = "TileDesc")] TileDescription); |
15955
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
45 |
#[derive(Deserialize)] |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
46 |
pub struct EdgeDescriptionHelper(#[serde(with = "EdgeDesc")] EdgeDescription); |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
47 |
|
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
48 |
#[derive(Deserialize)] |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
49 |
pub struct NonStrictEdgesDesc { |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
50 |
pub top: Option<EdgeDescriptionHelper>, |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
51 |
pub right: Option<EdgeDescriptionHelper>, |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
52 |
pub bottom: Option<EdgeDescriptionHelper>, |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
53 |
pub left: Option<EdgeDescriptionHelper>, |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
54 |
} |
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
55 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
56 |
#[derive(Deserialize)] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
57 |
pub struct TemplateDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
58 |
pub width: usize, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
59 |
pub height: usize, |
15953
d46ad15c6dec
Get wavefront collapse generator to work in engine
unC0Rr
parents:
15952
diff
changeset
|
60 |
pub can_invert: bool, |
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
61 |
pub is_negative: bool, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
62 |
pub put_girders: bool, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
63 |
pub max_hedgehogs: u8, |
15954 | 64 |
pub wrap: bool, |
15955
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
65 |
pub edges: Option<NonStrictEdgesDesc>, |
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
66 |
pub tiles: Vec<TileDescriptionHelper>, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
67 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
68 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
69 |
#[derive(Deserialize)] |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
70 |
pub struct TemplateCollectionDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
71 |
pub templates: Vec<TemplateDesc>, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
72 |
pub template_types: HashMap<String, Vec<usize>>, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
73 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
74 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
75 |
impl From<&TemplateDesc> for TemplateDescription { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
76 |
fn from(desc: &TemplateDesc) -> Self { |
15955
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
77 |
let [top, right, bottom, left] = if let Some(edges) = &desc.edges { |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
78 |
[ |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
79 |
edges.top.as_ref(), |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
80 |
edges.right.as_ref(), |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
81 |
edges.bottom.as_ref(), |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
82 |
edges.left.as_ref(), |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
83 |
] |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
84 |
.map(|e| e.map(|EdgeDescriptionHelper(e)| e.clone())) |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
85 |
} else { |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
86 |
[None, None, None, None] |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
87 |
}; |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
88 |
|
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
89 |
Self { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
90 |
size: Size::new(desc.width, desc.height), |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
91 |
tiles: desc |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
92 |
.tiles |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
93 |
.iter() |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
94 |
.map(|TileDescriptionHelper(t)| t.clone()) |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
95 |
.collect(), |
15954 | 96 |
wrap: desc.wrap, |
15955
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
97 |
edges: NonStrictEdgesDescription { |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
98 |
top, |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
99 |
right, |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
100 |
bottom, |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
101 |
left, |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15954
diff
changeset
|
102 |
}, |
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
103 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
104 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
105 |
} |