author | unC0Rr |
Mon, 27 Jan 2025 15:48:24 +0100 | |
changeset 16065 | 33f09636018b |
parent 16064 | 07cb6dbc8444 |
child 16073 | 5d302b12d837 |
permissions | -rw-r--r-- |
15924 | 1 |
use integral_geometry::Size; |
15923
d46ad15c6dec
Get wavefront collapse generator to work in engine
unC0Rr
parents:
15922
diff
changeset
|
2 |
|
15924 | 3 |
use landgen::wavefront_collapse::generator::*; |
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 |
|
16059
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
8 |
#[derive(Debug, Deserialize)] |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
9 |
pub struct TileDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
10 |
pub name: String, |
16064 | 11 |
pub edges: [String; 4], |
15924 | 12 |
pub is_negative: Option<bool>, |
13 |
pub can_flip: Option<bool>, |
|
14 |
pub can_mirror: Option<bool>, |
|
15 |
pub can_rotate90: Option<bool>, |
|
16 |
pub can_rotate180: Option<bool>, |
|
17 |
pub can_rotate270: Option<bool>, |
|
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
18 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
19 |
|
16059
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
20 |
#[derive(Debug, Deserialize)] |
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
21 |
pub struct ComplexEdgeDesc { |
16064 | 22 |
pub begin: Option<String>, |
23 |
pub fill: Option<String>, |
|
24 |
pub end: Option<String>, |
|
16059
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
25 |
} |
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
26 |
#[derive(Debug, Deserialize)] |
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
27 |
pub struct NonStrictComplexEdgesDesc { |
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
28 |
pub top: Option<ComplexEdgeDesc>, |
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
29 |
pub right: Option<ComplexEdgeDesc>, |
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
30 |
pub bottom: Option<ComplexEdgeDesc>, |
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
31 |
pub left: Option<ComplexEdgeDesc>, |
15925
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15924
diff
changeset
|
32 |
} |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
33 |
|
16059
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
34 |
#[derive(Debug, Deserialize)] |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
35 |
pub struct TemplateDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
36 |
pub width: usize, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
37 |
pub height: usize, |
16065 | 38 |
pub can_invert: Option<bool>, |
39 |
pub is_negative: Option<bool>, |
|
40 |
pub put_girders: Option<bool>, |
|
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
41 |
pub max_hedgehogs: u8, |
16065 | 42 |
pub wrap: Option<bool>, |
43 |
pub edges: Option<String>, |
|
44 |
pub tiles: Vec<String>, |
|
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
45 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
46 |
|
16059
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
47 |
#[derive(Debug, Deserialize)] |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
48 |
pub struct TemplateCollectionDesc { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
49 |
pub templates: Vec<TemplateDesc>, |
16065 | 50 |
pub tiles: HashMap<String, Vec<TileDesc>>, |
51 |
pub edges: HashMap<String, NonStrictComplexEdgesDesc>, |
|
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
52 |
pub template_types: HashMap<String, Vec<usize>>, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
53 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
54 |
|
16065 | 55 |
impl TemplateDesc { |
56 |
pub fn to_template(&self, tiles: &HashMap<String, Vec<TileDesc>>, edges: &HashMap<String, NonStrictComplexEdgesDesc>) -> TemplateDescription { |
|
16064 | 57 |
let [top, right, bottom, left]: [Option<ComplexEdgeDescription>; 4] = |
16065 | 58 |
if let Some(edges_name) = &self.edges { |
59 |
let edges = edges.get(edges_name).expect("missing template edges"); |
|
16064 | 60 |
[&edges.top, &edges.right, &edges.bottom, &edges.left] |
61 |
.map(|e| e.as_ref().map(Into::into)) |
|
62 |
} else { |
|
63 |
[None, None, None, None] |
|
64 |
}; |
|
15925
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15924
diff
changeset
|
65 |
|
16065 | 66 |
let tiles = self.tiles.iter().flat_map(|t| tiles.get(t).expect("missing template tiles")).collect::<Vec<_>>(); |
67 |
||
68 |
TemplateDescription { |
|
69 |
size: Size::new(self.width, self.height), |
|
70 |
tiles: tiles.into_iter().map(|t| t.into()).collect(), |
|
71 |
wrap: self.wrap.unwrap_or(false), |
|
72 |
can_invert: self.can_invert.unwrap_or(false), |
|
73 |
is_negative: self.is_negative.unwrap_or(false), |
|
16059
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
74 |
edges: NonStrictComplexEdgesDescription { |
15925
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15924
diff
changeset
|
75 |
top, |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15924
diff
changeset
|
76 |
right, |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15924
diff
changeset
|
77 |
bottom, |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15924
diff
changeset
|
78 |
left, |
b0e8cc72bfef
Allow defining compatible edges for grid, add few more templates
unC0Rr
parents:
15924
diff
changeset
|
79 |
}, |
15922
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
80 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
81 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff
changeset
|
82 |
} |
16059
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
83 |
|
16064 | 84 |
impl From<&TileDesc> for TileDescription { |
85 |
fn from(desc: &TileDesc) -> Self { |
|
86 |
let [top, right, bottom, left]: [EdgeDescription; 4] = desc.edges.clone().map(|e| e.into()); |
|
87 |
||
88 |
Self { |
|
89 |
name: desc.name.clone(), |
|
90 |
edges: EdgesDescription { |
|
91 |
top, |
|
92 |
right, |
|
93 |
bottom, |
|
94 |
left, |
|
95 |
}, |
|
96 |
is_negative: desc.is_negative, |
|
97 |
can_flip: desc.can_flip, |
|
98 |
can_mirror: desc.can_mirror, |
|
99 |
can_rotate90: desc.can_rotate90, |
|
100 |
can_rotate180: desc.can_rotate180, |
|
101 |
can_rotate270: desc.can_rotate270, |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
105 |
||
16059
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
106 |
impl From<&ComplexEdgeDesc> for ComplexEdgeDescription { |
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
107 |
fn from(value: &ComplexEdgeDesc) -> Self { |
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
108 |
Self { |
16064 | 109 |
begin: value.begin.as_ref().map(|e| e.into()), |
110 |
fill: value.fill.as_ref().map(|e| e.into()), |
|
111 |
end: value.end.as_ref().map(|e| e.into()), |
|
16059
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
112 |
} |
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
113 |
} |
2acea266d297
Fix generation in corners by extending outline edge definitions
unC0Rr
parents:
15925
diff
changeset
|
114 |
} |