rust/mapgen/src/lib.rs
author alfadur
Wed, 07 Nov 2018 22:01:47 +0300
changeset 14181 c24a76f131d6
parent 14177 74ca70cb753d
child 14185 1749961647b9
permissions -rw-r--r--
implement basic land texturing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14172
3c8a33ba06ba start loading theme textures
alfadur
parents: 14158
diff changeset
     1
pub mod theme;
3c8a33ba06ba start loading theme textures
alfadur
parents: 14158
diff changeset
     2
14148
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};
14172
3c8a33ba06ba start loading theme textures
alfadur
parents: 14158
diff changeset
    15
use land2d::Land2D;
14181
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
    16
use vec2d::Vec2D;
14177
74ca70cb753d fix mapgen
alfadur
parents: 14172
diff changeset
    17
use self::theme::Theme;
14148
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()
14158
3119d665d3c6 collapse rectangle types back together with consistent usage of size
alfadur
parents: 14149
diff changeset
    58
                    .map(|r| Rect::from_size(
3119d665d3c6 collapse rectangle types back together with consistent usage of size
alfadur
parents: 14149
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: 14149
diff changeset
    60
                        Size::new(r.w as usize, r.h as usize)))
14148
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
    }
14172
3c8a33ba06ba start loading theme textures
alfadur
parents: 14158
diff changeset
   108
14181
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   109
    pub fn make_texture(&self, land: &Land2D<u32>, theme: &Theme) -> Vec2D<u32> {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   110
        let mut texture = Vec2D::new(land.size(), 0);
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   111
        if let Some(land_sprite) = theme.land_texture() {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   112
            for (row_index, (land_row, tex_row)) in land.rows()
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   113
                .zip(texture.rows_mut())
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   114
                .enumerate()
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   115
            {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   116
                let sprite_row = land_sprite.get_row(row_index % land_sprite.height());
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   117
                let mut x_offset = 0;
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   118
                while sprite_row.len() < land.width() - x_offset {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   119
                    let copy_range = x_offset..x_offset + sprite_row.len();
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   120
                    tex_row_copy(
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   121
                        &land_row[copy_range.clone()],
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   122
                        &mut tex_row[copy_range],
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   123
                        sprite_row
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   124
                    );
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   125
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   126
                    x_offset += land_sprite.width()
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   127
                }
14172
3c8a33ba06ba start loading theme textures
alfadur
parents: 14158
diff changeset
   128
14181
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   129
                if x_offset < land.width() {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   130
                    let final_range = x_offset..land.width() - 1;
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   131
                    tex_row_copy(
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   132
                        &land_row[final_range.clone()],
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   133
                        &mut tex_row[final_range],
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   134
                        &sprite_row[..land.width() - x_offset]
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   135
                    );
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   136
                }
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   137
            }
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   138
        }
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   139
        texture
14172
3c8a33ba06ba start loading theme textures
alfadur
parents: 14158
diff changeset
   140
    }
14148
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   141
}
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   142
14181
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   143
fn tex_row_copy(land_row: &[u32], tex_row: &mut [u32], sprite_row: &[u32]) {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   144
    for ((land_v, tex_v), sprite_v) in
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   145
        land_row.iter().zip(tex_row.iter_mut()).zip(sprite_row)
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   146
        {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   147
            *tex_v = if *land_v == 0 {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   148
                *sprite_v
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   149
            } else {
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   150
                0
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   151
            }
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   152
        }
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   153
}
c24a76f131d6 implement basic land texturing
alfadur
parents: 14177
diff changeset
   154
14148
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   155
#[cfg(test)]
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   156
mod tests {
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   157
    use crate::{
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   158
        MapGenerator,
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   159
        TemplateType
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   160
    };
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   161
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   162
    #[test]
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   163
    fn simple_load() {
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   164
        let text = r#"
14149
b04dac00e8e2 add command arguments to use a template from file into land_dump
alfadur
parents: 14148
diff changeset
   165
# comment
b04dac00e8e2 add command arguments to use a template from file into land_dump
alfadur
parents: 14148
diff changeset
   166
14148
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   167
templates:
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   168
  -
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   169
    width: 3072
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   170
    height: 1424
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   171
    can_flip: false
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   172
    can_invert: false
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   173
    can_mirror: true
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   174
    is_negative: false
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   175
    put_girders: true
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   176
    max_hedgehogs: 18
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   177
    outline_points:
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   178
      -
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   179
        - {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
   180
        - {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
   181
        - {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
   182
        - {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
   183
        - {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
   184
        - {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
   185
        - {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
   186
    fill_points:
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   187
      - {x: 1023, y: 0}
14149
b04dac00e8e2 add command arguments to use a template from file into land_dump
alfadur
parents: 14148
diff changeset
   188
      - {x: 1023, y: 0}
14148
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   189
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   190
template_types:
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   191
    test: [0]
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   192
"#;
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   193
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   194
        let mut generator = MapGenerator::new();
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   195
        generator.import_yaml_templates(&text);
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   196
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   197
        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
   198
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   199
        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
   200
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   201
        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
   202
    }
0c5b9cfda9ab add a higher level map generation lib to load yaml templates into somewhere
alfadur
parents:
diff changeset
   203
}