author | unC0Rr |
Mon, 13 Feb 2023 12:31:30 +0100 | |
branch | transitional_engine |
changeset 15952 | da6b67f13c12 |
parent 15951 | 5f00829c55ec |
child 15953 | d46ad15c6dec |
permissions | -rw-r--r-- |
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
1 |
mod template; |
14172 | 2 |
pub mod theme; |
3 |
||
14731 | 4 |
use self::theme::Theme; |
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
5 |
use crate::template::outline::TemplateCollectionDesc as OutlineTemplateCollectionDesc; |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
6 |
use crate::template::wavefront_collapse::TemplateCollectionDesc as WfcTemplateCollectionDesc; |
14731 | 7 |
use integral_geometry::{Point, Rect, Size}; |
8 |
use land2d::Land2D; |
|
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
9 |
use landgen::{ |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
10 |
outline_template_based::{ |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
11 |
outline_template::OutlineTemplate, template_based::TemplatedLandGenerator, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
12 |
}, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
13 |
wavefront_collapse::generator::{ |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
14 |
TemplateDescription as WfcTemplate, WavefrontCollapseLandGenerator, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
15 |
}, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
16 |
LandGenerationParameters, LandGenerator, |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
17 |
}; |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
18 |
use rand::{seq::SliceRandom, Rng}; |
14731 | 19 |
use serde_derive::Deserialize; |
14148
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
20 |
use serde_yaml; |
14731 | 21 |
use std::{borrow::Borrow, collections::hash_map::HashMap, mem::replace}; |
14181 | 22 |
use vec2d::Vec2D; |
14148
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
23 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
24 |
#[derive(PartialEq, Eq, Hash, Clone, Debug)] |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
25 |
struct TemplateType(String); |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
26 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
27 |
impl Borrow<str> for TemplateType { |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
28 |
fn borrow(&self) -> &str { |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
29 |
self.0.as_str() |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
30 |
} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
31 |
} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
32 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
33 |
#[derive(Debug)] |
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
34 |
pub struct MapGenerator<T> { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
35 |
pub(crate) templates: HashMap<TemplateType, Vec<T>>, |
14148
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
36 |
} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
37 |
|
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
38 |
impl<T> MapGenerator<T> { |
14148
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
39 |
pub fn new() -> Self { |
14731 | 40 |
Self { |
41 |
templates: HashMap::new(), |
|
42 |
} |
|
14148
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
43 |
} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
44 |
|
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
45 |
pub fn get_template<R: Rng>(&self, template_type: &str, rng: &mut R) -> Option<&T> { |
14731 | 46 |
self.templates |
47 |
.get(template_type) |
|
15932
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
48 |
.and_then(|t| t.as_slice().choose(rng)) |
14148
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
49 |
} |
14172 | 50 |
|
15932
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
51 |
pub fn make_texture<LandT>( |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
52 |
&self, |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
53 |
land: &Land2D<LandT>, |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
54 |
parameters: &LandGenerationParameters<LandT>, |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
55 |
theme: &Theme, |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
56 |
) -> Vec2D<u32> |
14731 | 57 |
where |
58 |
LandT: Copy + Default + PartialEq, |
|
59 |
{ |
|
15944 | 60 |
let mut texture = Vec2D::new(&land.size().size(), 0); |
14191 | 61 |
|
14181 | 62 |
if let Some(land_sprite) = theme.land_texture() { |
14731 | 63 |
for (row_index, (land_row, tex_row)) in land.rows().zip(texture.rows_mut()).enumerate() |
14181 | 64 |
{ |
65 |
let sprite_row = land_sprite.get_row(row_index % land_sprite.height()); |
|
66 |
let mut x_offset = 0; |
|
67 |
while sprite_row.len() < land.width() - x_offset { |
|
68 |
let copy_range = x_offset..x_offset + sprite_row.len(); |
|
69 |
tex_row_copy( |
|
15932
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
70 |
parameters.basic(), |
14181 | 71 |
&land_row[copy_range.clone()], |
72 |
&mut tex_row[copy_range], |
|
14731 | 73 |
sprite_row, |
14181 | 74 |
); |
75 |
||
76 |
x_offset += land_sprite.width() |
|
77 |
} |
|
14172 | 78 |
|
14181 | 79 |
if x_offset < land.width() { |
14185
1749961647b9
fix texturing and add a theme loading option to land_dump
alfadur
parents:
14181
diff
changeset
|
80 |
let final_range = x_offset..land.width(); |
14181 | 81 |
tex_row_copy( |
15932
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
82 |
parameters.basic(), |
14181 | 83 |
&land_row[final_range.clone()], |
84 |
&mut tex_row[final_range], |
|
14731 | 85 |
&sprite_row[..land.width() - x_offset], |
14181 | 86 |
); |
87 |
} |
|
88 |
} |
|
89 |
} |
|
14191 | 90 |
|
91 |
if let Some(border_sprite) = theme.border_texture() { |
|
92 |
assert!(border_sprite.height() <= 512); |
|
93 |
let border_width = (border_sprite.height() / 2) as u8; |
|
14196 | 94 |
let border_sprite = border_sprite.to_tiled(); |
14191 | 95 |
|
96 |
let mut offsets = vec![255u8; land.width()]; |
|
97 |
||
98 |
land_border_pass( |
|
15932
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
99 |
parameters.basic(), |
14191 | 100 |
land.rows().rev().zip(texture.rows_mut().rev()), |
101 |
&mut offsets, |
|
102 |
border_width, |
|
14731 | 103 |
|x, y| { |
104 |
border_sprite |
|
105 |
.get_pixel(x % border_sprite.width(), border_sprite.height() - 1 - y) |
|
106 |
}, |
|
14191 | 107 |
); |
108 |
||
109 |
offsets.iter_mut().for_each(|v| *v = 255); |
|
110 |
||
111 |
land_border_pass( |
|
15932
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
112 |
parameters.basic(), |
14191 | 113 |
land.rows().zip(texture.rows_mut()), |
114 |
&mut offsets, |
|
115 |
border_width, |
|
14731 | 116 |
|x, y| border_sprite.get_pixel(x % border_sprite.width(), y), |
14723 | 117 |
); |
118 |
} |
|
119 |
||
120 |
texture |
|
121 |
} |
|
14148
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
122 |
} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
123 |
|
15952
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
124 |
impl MapGenerator<OutlineTemplate> { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
125 |
pub fn import_yaml_templates(&mut self, text: &str) { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
126 |
let mut desc: OutlineTemplateCollectionDesc = serde_yaml::from_str(text).unwrap(); |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
127 |
let templates = replace(&mut desc.templates, vec![]); |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
128 |
self.templates = desc |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
129 |
.template_types |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
130 |
.into_iter() |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
131 |
.map(|(size, indices)| { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
132 |
( |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
133 |
TemplateType(size), |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
134 |
indices.iter().map(|i| (&templates[*i]).into()).collect(), |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
135 |
) |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
136 |
}) |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
137 |
.collect(); |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
138 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
139 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
140 |
pub fn build_generator(&self, template: OutlineTemplate) -> impl LandGenerator { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
141 |
TemplatedLandGenerator::new(template) |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
142 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
143 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
144 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
145 |
impl MapGenerator<WfcTemplate> { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
146 |
pub fn import_yaml_templates(&mut self, text: &str) { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
147 |
let mut desc: WfcTemplateCollectionDesc = serde_yaml::from_str(text).unwrap(); |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
148 |
let templates = replace(&mut desc.templates, vec![]); |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
149 |
self.templates = desc |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
150 |
.template_types |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
151 |
.into_iter() |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
152 |
.map(|(size, indices)| { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
153 |
( |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
154 |
TemplateType(size), |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
155 |
indices.iter().map(|i| (&templates[*i]).into()).collect(), |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
156 |
) |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
157 |
}) |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
158 |
.collect(); |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
159 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
160 |
|
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
161 |
pub fn build_generator(&self, template: WfcTemplate) -> impl LandGenerator { |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
162 |
WavefrontCollapseLandGenerator::new(template) |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
163 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
164 |
} |
da6b67f13c12
Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
15951
diff
changeset
|
165 |
|
14191 | 166 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
167 |
struct Color(u32); |
|
168 |
||
169 |
impl Color { |
|
170 |
#[inline] |
|
171 |
fn red(self) -> u8 { |
|
172 |
(self.0 >> 0 & 0xFF) as u8 |
|
173 |
} |
|
174 |
||
175 |
#[inline] |
|
176 |
fn green(self) -> u8 { |
|
177 |
(self.0 >> 8 & 0xFF) as u8 |
|
178 |
} |
|
179 |
||
180 |
#[inline] |
|
181 |
fn blue(self) -> u8 { |
|
182 |
(self.0 >> 16 & 0xFF) as u8 |
|
183 |
} |
|
184 |
||
185 |
#[inline] |
|
186 |
fn alpha(self) -> u8 { |
|
187 |
(self.0 >> 24 & 0xFF) as u8 |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
#[inline] |
|
192 |
fn lerp(from: u8, to: u8, coef: u8) -> u8 { |
|
193 |
((from as u16 * (256 - coef as u16) + to as u16 * coef as u16) / 256) as u8 |
|
194 |
} |
|
195 |
||
196 |
#[inline] |
|
197 |
fn blend(source: u32, target: u32) -> u32 { |
|
198 |
let source = Color(source); |
|
199 |
let target = Color(target); |
|
200 |
let alpha = lerp(target.alpha(), 255, source.alpha()); |
|
201 |
let red = lerp(target.red(), source.red(), source.alpha()); |
|
202 |
let green = lerp(target.green(), source.green(), source.alpha()); |
|
203 |
let blue = lerp(target.blue(), source.blue(), source.alpha()); |
|
204 |
(red as u32) << 0 | (green as u32) << 8 | (blue as u32) << 16 | (alpha as u32) << 24 |
|
205 |
} |
|
206 |
||
15932
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
207 |
fn land_border_pass<'a, LandT, T, F>( |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
208 |
basic_value: LandT, |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
209 |
rows: T, |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
210 |
offsets: &mut [u8], |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
211 |
border_width: u8, |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
212 |
pixel_getter: F, |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
213 |
) where |
14731 | 214 |
LandT: Default + PartialEq + 'a, |
215 |
T: Iterator<Item = (&'a [LandT], &'a mut [u32])>, |
|
216 |
F: (Fn(usize, usize) -> u32), |
|
14191 | 217 |
{ |
218 |
for (land_row, tex_row) in rows { |
|
14731 | 219 |
for (x, ((land_v, tex_v), offset_v)) in land_row |
220 |
.iter() |
|
14191 | 221 |
.zip(tex_row.iter_mut()) |
222 |
.zip(offsets.iter_mut()) |
|
223 |
.enumerate() |
|
224 |
{ |
|
15932
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
225 |
*offset_v = if *land_v == basic_value { |
14191 | 226 |
if *offset_v < border_width { |
14731 | 227 |
*tex_v = blend(pixel_getter(x, *offset_v as usize), *tex_v) |
14191 | 228 |
} |
229 |
offset_v.saturating_add(1) |
|
230 |
} else { |
|
231 |
0 |
|
232 |
} |
|
233 |
} |
|
234 |
} |
|
235 |
} |
|
236 |
||
15932
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
237 |
fn tex_row_copy<LandT>( |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
238 |
basic_value: LandT, |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
239 |
land_row: &[LandT], |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
240 |
tex_row: &mut [u32], |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
241 |
sprite_row: &[u32], |
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
242 |
) where |
14731 | 243 |
LandT: Default + PartialEq, |
14723 | 244 |
{ |
14731 | 245 |
for ((land_v, tex_v), sprite_v) in land_row.iter().zip(tex_row.iter_mut()).zip(sprite_row) { |
15932
230dc46487ea
Update mapgen to take into account actual values for 'zero' and 'basic' colors
unC0Rr
parents:
15850
diff
changeset
|
246 |
*tex_v = if *land_v == basic_value { *sprite_v } else { 0 } |
14723 | 247 |
} |
248 |
} |
|
249 |
||
14148
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
250 |
#[cfg(test)] |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
251 |
mod tests { |
14731 | 252 |
use crate::{MapGenerator, TemplateType}; |
14148
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
253 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
254 |
#[test] |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
255 |
fn simple_load() { |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
256 |
let text = r#" |
14149
b04dac00e8e2
add command arguments to use a template from file into land_dump
alfadur
parents:
14148
diff
changeset
|
257 |
# comment |
b04dac00e8e2
add command arguments to use a template from file into land_dump
alfadur
parents:
14148
diff
changeset
|
258 |
|
14148
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
259 |
templates: |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
260 |
- |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
261 |
width: 3072 |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
262 |
height: 1424 |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
263 |
can_flip: false |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
264 |
can_invert: false |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
265 |
can_mirror: true |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
266 |
is_negative: false |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
267 |
put_girders: true |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
268 |
max_hedgehogs: 18 |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
269 |
outline_points: |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
270 |
- |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
271 |
- {x: 748, y: 1424, w: 1, h: 1} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
272 |
- {x: 636, y: 1252, w: 208, h: 72} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
273 |
- {x: 898, y: 1110, w: 308, h: 60} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
274 |
- {x: 1128, y: 1252, w: 434, h: 40} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
275 |
- {x: 1574, y: 1112, w: 332, h: 40} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
276 |
- {x: 1802, y: 1238, w: 226, h: 36} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
277 |
- {x: 1930, y: 1424, w: 1, h: 1} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
278 |
fill_points: |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
279 |
- {x: 1023, y: 0} |
14149
b04dac00e8e2
add command arguments to use a template from file into land_dump
alfadur
parents:
14148
diff
changeset
|
280 |
- {x: 1023, y: 0} |
14148
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
281 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
282 |
template_types: |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
283 |
test: [0] |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
284 |
"#; |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
285 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
286 |
let mut generator = MapGenerator::new(); |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
287 |
generator.import_yaml_templates(&text); |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
288 |
|
14731 | 289 |
assert!(generator |
290 |
.templates |
|
291 |
.contains_key(&TemplateType("test".to_string()))); |
|
14148
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
292 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
293 |
let template = generator.get_template("test").unwrap(); |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
294 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
295 |
assert_eq!(template.islands[0].len(), 7); |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
296 |
} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
297 |
} |