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