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