author | Wuzzy <Wuzzy2@mail.ru> |
Mon, 08 Jun 2020 23:37:38 +0200 | |
changeset 15613 | d9c62f196fe0 |
parent 14710 | 946df0bb3b28 |
child 15828 | 44b49f255e31 |
permissions | -rw-r--r-- |
14151 | 1 |
pub mod theme; |
2 |
||
14710 | 3 |
use self::theme::Theme; |
4 |
use integral_geometry::{Point, Rect, Size}; |
|
5 |
use land2d::Land2D; |
|
6 |
use landgen::outline_template::OutlineTemplate; |
|
7 |
use rand::{thread_rng, Rng}; |
|
8 |
use serde_derive::Deserialize; |
|
14127
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
9 |
use serde_yaml; |
14710 | 10 |
use std::{borrow::Borrow, collections::hash_map::HashMap, mem::replace}; |
14160 | 11 |
use vec2d::Vec2D; |
14127
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, |
14710 | 16 |
y: u32, |
14127
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, |
14710 | 24 |
h: u32, |
14127
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>>, |
14710 | 38 |
fill_points: Vec<PointDesc>, |
14127
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>, |
14710 | 44 |
template_types: HashMap<String, Vec<usize>>, |
14127
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 { |
14710 | 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 |
}) |
|
14127
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
63 |
.collect(), |
14710 | 64 |
fill_points: desc |
65 |
.fill_points |
|
66 |
.iter() |
|
14127
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, |
14710 | 73 |
is_negative: desc.is_negative, |
14127
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 { |
14710 | 89 |
pub(crate) templates: HashMap<TemplateType, Vec<OutlineTemplate>>, |
14127
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 { |
14710 | 94 |
Self { |
95 |
templates: HashMap::new(), |
|
96 |
} |
|
14127
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![]); |
14710 | 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 |
}) |
|
14127
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 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
114 |
pub fn get_template(&self, template_type: &str) -> Option<&OutlineTemplate> { |
14710 | 115 |
self.templates |
116 |
.get(template_type) |
|
117 |
.and_then(|t| thread_rng().choose(t)) |
|
14127
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
118 |
} |
14151 | 119 |
|
14710 | 120 |
pub fn make_texture<LandT>(&self, land: &Land2D<LandT>, theme: &Theme) -> Vec2D<u32> |
121 |
where |
|
122 |
LandT: Copy + Default + PartialEq, |
|
123 |
{ |
|
14160 | 124 |
let mut texture = Vec2D::new(land.size(), 0); |
14170 | 125 |
|
14160 | 126 |
if let Some(land_sprite) = theme.land_texture() { |
14710 | 127 |
for (row_index, (land_row, tex_row)) in land.rows().zip(texture.rows_mut()).enumerate() |
14160 | 128 |
{ |
129 |
let sprite_row = land_sprite.get_row(row_index % land_sprite.height()); |
|
130 |
let mut x_offset = 0; |
|
131 |
while sprite_row.len() < land.width() - x_offset { |
|
132 |
let copy_range = x_offset..x_offset + sprite_row.len(); |
|
133 |
tex_row_copy( |
|
134 |
&land_row[copy_range.clone()], |
|
135 |
&mut tex_row[copy_range], |
|
14710 | 136 |
sprite_row, |
14160 | 137 |
); |
138 |
||
139 |
x_offset += land_sprite.width() |
|
140 |
} |
|
14151 | 141 |
|
14160 | 142 |
if x_offset < land.width() { |
14164
1749961647b9
fix texturing and add a theme loading option to land_dump
alfadur
parents:
14160
diff
changeset
|
143 |
let final_range = x_offset..land.width(); |
14160 | 144 |
tex_row_copy( |
145 |
&land_row[final_range.clone()], |
|
146 |
&mut tex_row[final_range], |
|
14710 | 147 |
&sprite_row[..land.width() - x_offset], |
14160 | 148 |
); |
149 |
} |
|
150 |
} |
|
151 |
} |
|
14170 | 152 |
|
153 |
if let Some(border_sprite) = theme.border_texture() { |
|
154 |
assert!(border_sprite.height() <= 512); |
|
155 |
let border_width = (border_sprite.height() / 2) as u8; |
|
14175 | 156 |
let border_sprite = border_sprite.to_tiled(); |
14170 | 157 |
|
158 |
let mut offsets = vec![255u8; land.width()]; |
|
159 |
||
160 |
land_border_pass( |
|
161 |
land.rows().rev().zip(texture.rows_mut().rev()), |
|
162 |
&mut offsets, |
|
163 |
border_width, |
|
14710 | 164 |
|x, y| { |
165 |
border_sprite |
|
166 |
.get_pixel(x % border_sprite.width(), border_sprite.height() - 1 - y) |
|
167 |
}, |
|
14170 | 168 |
); |
169 |
||
170 |
offsets.iter_mut().for_each(|v| *v = 255); |
|
171 |
||
172 |
land_border_pass( |
|
173 |
land.rows().zip(texture.rows_mut()), |
|
174 |
&mut offsets, |
|
175 |
border_width, |
|
14710 | 176 |
|x, y| border_sprite.get_pixel(x % border_sprite.width(), y), |
14702 | 177 |
); |
178 |
} |
|
179 |
||
180 |
texture |
|
181 |
} |
|
14127
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
182 |
} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
183 |
|
14170 | 184 |
#[derive(Debug, Clone, Copy, PartialEq, Eq)] |
185 |
struct Color(u32); |
|
186 |
||
187 |
impl Color { |
|
188 |
#[inline] |
|
189 |
fn red(self) -> u8 { |
|
190 |
(self.0 >> 0 & 0xFF) as u8 |
|
191 |
} |
|
192 |
||
193 |
#[inline] |
|
194 |
fn green(self) -> u8 { |
|
195 |
(self.0 >> 8 & 0xFF) as u8 |
|
196 |
} |
|
197 |
||
198 |
#[inline] |
|
199 |
fn blue(self) -> u8 { |
|
200 |
(self.0 >> 16 & 0xFF) as u8 |
|
201 |
} |
|
202 |
||
203 |
#[inline] |
|
204 |
fn alpha(self) -> u8 { |
|
205 |
(self.0 >> 24 & 0xFF) as u8 |
|
206 |
} |
|
207 |
} |
|
208 |
||
209 |
#[inline] |
|
210 |
fn lerp(from: u8, to: u8, coef: u8) -> u8 { |
|
211 |
((from as u16 * (256 - coef as u16) + to as u16 * coef as u16) / 256) as u8 |
|
212 |
} |
|
213 |
||
214 |
#[inline] |
|
215 |
fn blend(source: u32, target: u32) -> u32 { |
|
216 |
let source = Color(source); |
|
217 |
let target = Color(target); |
|
218 |
let alpha = lerp(target.alpha(), 255, source.alpha()); |
|
219 |
let red = lerp(target.red(), source.red(), source.alpha()); |
|
220 |
let green = lerp(target.green(), source.green(), source.alpha()); |
|
221 |
let blue = lerp(target.blue(), source.blue(), source.alpha()); |
|
222 |
(red as u32) << 0 | (green as u32) << 8 | (blue as u32) << 16 | (alpha as u32) << 24 |
|
223 |
} |
|
224 |
||
14710 | 225 |
fn land_border_pass<'a, LandT, T, F>(rows: T, offsets: &mut [u8], border_width: u8, pixel_getter: F) |
226 |
where |
|
227 |
LandT: Default + PartialEq + 'a, |
|
228 |
T: Iterator<Item = (&'a [LandT], &'a mut [u32])>, |
|
229 |
F: (Fn(usize, usize) -> u32), |
|
14170 | 230 |
{ |
231 |
for (land_row, tex_row) in rows { |
|
14710 | 232 |
for (x, ((land_v, tex_v), offset_v)) in land_row |
233 |
.iter() |
|
14170 | 234 |
.zip(tex_row.iter_mut()) |
235 |
.zip(offsets.iter_mut()) |
|
236 |
.enumerate() |
|
237 |
{ |
|
14710 | 238 |
*offset_v = if *land_v == LandT::default() { |
14170 | 239 |
if *offset_v < border_width { |
14710 | 240 |
*tex_v = blend(pixel_getter(x, *offset_v as usize), *tex_v) |
14170 | 241 |
} |
242 |
offset_v.saturating_add(1) |
|
243 |
} else { |
|
244 |
0 |
|
245 |
} |
|
246 |
} |
|
247 |
} |
|
248 |
} |
|
249 |
||
14710 | 250 |
fn tex_row_copy<LandT>(land_row: &[LandT], tex_row: &mut [u32], sprite_row: &[u32]) |
251 |
where |
|
252 |
LandT: Default + PartialEq, |
|
14702 | 253 |
{ |
14710 | 254 |
for ((land_v, tex_v), sprite_v) in land_row.iter().zip(tex_row.iter_mut()).zip(sprite_row) { |
255 |
*tex_v = if *land_v == LandT::default() { |
|
14702 | 256 |
*sprite_v |
257 |
} else { |
|
258 |
0 |
|
259 |
} |
|
260 |
} |
|
261 |
} |
|
262 |
||
14127
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
263 |
#[cfg(test)] |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
264 |
mod tests { |
14710 | 265 |
use crate::{MapGenerator, TemplateType}; |
14127
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
266 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
267 |
#[test] |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
268 |
fn simple_load() { |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
269 |
let text = r#" |
14128
b04dac00e8e2
add command arguments to use a template from file into land_dump
alfadur
parents:
14127
diff
changeset
|
270 |
# comment |
b04dac00e8e2
add command arguments to use a template from file into land_dump
alfadur
parents:
14127
diff
changeset
|
271 |
|
14127
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
272 |
templates: |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
273 |
- |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
274 |
width: 3072 |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
275 |
height: 1424 |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
276 |
can_flip: false |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
277 |
can_invert: false |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
278 |
can_mirror: true |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
279 |
is_negative: false |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
280 |
put_girders: true |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
281 |
max_hedgehogs: 18 |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
282 |
outline_points: |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
283 |
- |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
284 |
- {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
|
285 |
- {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
|
286 |
- {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
|
287 |
- {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
|
288 |
- {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
|
289 |
- {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
|
290 |
- {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
|
291 |
fill_points: |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
292 |
- {x: 1023, y: 0} |
14128
b04dac00e8e2
add command arguments to use a template from file into land_dump
alfadur
parents:
14127
diff
changeset
|
293 |
- {x: 1023, y: 0} |
14127
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 |
template_types: |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
296 |
test: [0] |
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 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
299 |
let mut generator = MapGenerator::new(); |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
300 |
generator.import_yaml_templates(&text); |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
301 |
|
14710 | 302 |
assert!(generator |
303 |
.templates |
|
304 |
.contains_key(&TemplateType("test".to_string()))); |
|
14127
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
305 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
306 |
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
|
307 |
|
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
308 |
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
|
309 |
} |
0c5b9cfda9ab
add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff
changeset
|
310 |
} |