rust/mapgen/src/template/outline.rs
branchtransitional_engine
changeset 16044 5c941f5deeec
parent 16029 9cbd18220eb7
equal deleted inserted replaced
16043:adb44a2d8226 16044:5c941f5deeec
     3 use landgen::outline_template_based::outline_template::OutlineTemplate;
     3 use landgen::outline_template_based::outline_template::OutlineTemplate;
     4 use serde_derive::Deserialize;
     4 use serde_derive::Deserialize;
     5 
     5 
     6 use std::collections::hash_map::HashMap;
     6 use std::collections::hash_map::HashMap;
     7 
     7 
     8 #[derive(Deserialize)]
     8 #[derive(Deserialize, Clone)]
     9 pub struct PointDesc {
     9 pub struct PointDesc {
    10     x: u32,
    10     x: u32,
    11     y: u32,
    11     y: u32,
    12 }
    12 }
    13 
    13 
    14 #[derive(Deserialize)]
    14 #[derive(Deserialize, Clone)]
    15 pub struct RectDesc {
    15 pub struct RectDesc {
    16     x: u32,
    16     x: u32,
    17     y: u32,
    17     y: u32,
    18     w: u32,
    18     w: u32,
    19     h: u32,
    19     h: u32,
    20 }
    20 }
    21 
    21 
    22 #[derive(Deserialize)]
    22 #[derive(Deserialize, Clone)]
    23 pub struct TemplateDesc {
    23 pub struct TemplateDesc {
    24     width: usize,
    24     width: usize,
    25     height: usize,
    25     height: usize,
    26     can_flip: bool,
    26     can_flip: bool,
    27     can_invert: bool,
    27     can_invert: bool,
    28     can_mirror: bool,
    28     can_mirror: bool,
    29     is_negative: bool,
    29     is_negative: bool,
    30     put_girders: bool,
    30     put_girders: bool,
    31     max_hedgehogs: u8,
    31     max_hedgehogs: u8,
    32     outline_points: Vec<Vec<RectDesc>>,
    32     outline_points: Vec<Vec<RectDesc>>,
       
    33     walls: Option<Vec<Vec<RectDesc>>>,
    33     fill_points: Vec<PointDesc>,
    34     fill_points: Vec<PointDesc>,
    34 }
    35 }
    35 
    36 
    36 #[derive(Deserialize)]
    37 #[derive(Deserialize)]
    37 pub struct TemplateTypeDesc {
    38 pub struct TemplateTypeDesc {
    43 pub struct TemplateCollectionDesc {
    44 pub struct TemplateCollectionDesc {
    44     pub templates: Vec<TemplateDesc>,
    45     pub templates: Vec<TemplateDesc>,
    45     pub template_types: HashMap<String, TemplateTypeDesc>,
    46     pub template_types: HashMap<String, TemplateTypeDesc>,
    46 }
    47 }
    47 
    48 
    48 impl From<&TemplateDesc> for OutlineTemplate {
    49 impl From<TemplateDesc> for OutlineTemplate {
    49     fn from(desc: &TemplateDesc) -> Self {
    50     fn from(desc: TemplateDesc) -> Self {
    50         OutlineTemplate {
    51         OutlineTemplate {
    51             islands: desc
    52             islands: desc
    52                 .outline_points
    53                 .outline_points
       
    54                 .iter()
       
    55                 .map(|v| {
       
    56                     v.iter()
       
    57                         .map(|r| {
       
    58                             Rect::from_size(
       
    59                                 Point::new(r.x as i32, r.y as i32),
       
    60                                 Size::new(r.w as usize, r.h as usize),
       
    61                             )
       
    62                         })
       
    63                         .collect()
       
    64                 })
       
    65                 .collect(),
       
    66             walls: desc
       
    67                 .walls.unwrap_or_default()
    53                 .iter()
    68                 .iter()
    54                 .map(|v| {
    69                 .map(|v| {
    55                     v.iter()
    70                     v.iter()
    56                         .map(|r| {
    71                         .map(|r| {
    57                             Rect::from_size(
    72                             Rect::from_size(