rust/mapgen/src/template/wavefront_collapse.rs
branchtransitional_engine
changeset 15922 da6b67f13c12
child 15923 d46ad15c6dec
equal deleted inserted replaced
15921:5f00829c55ec 15922:da6b67f13c12
       
     1 use integral_geometry::{Point, Rect, Size};
       
     2 use land2d::Land2D;
       
     3 use landgen::{wavefront_collapse::generator::*, LandGenerationParameters};
       
     4 use serde_derive::Deserialize;
       
     5 use serde_yaml;
       
     6 use std::{borrow::Borrow, collections::hash_map::HashMap, mem::replace};
       
     7 
       
     8 #[derive(Deserialize)]
       
     9 #[serde(remote = "EdgeDescription")]
       
    10 pub struct EdgeDesc {
       
    11     pub name: String,
       
    12     pub reversed: Option<bool>,
       
    13     pub symmetrical: Option<bool>,
       
    14 }
       
    15 
       
    16 #[derive(Deserialize)]
       
    17 #[serde(remote = "EdgesDescription")]
       
    18 pub struct EdgesDesc {
       
    19     #[serde(with = "EdgeDesc")]
       
    20     pub top: EdgeDescription,
       
    21     #[serde(with = "EdgeDesc")]
       
    22     pub right: EdgeDescription,
       
    23     #[serde(with = "EdgeDesc")]
       
    24     pub bottom: EdgeDescription,
       
    25     #[serde(with = "EdgeDesc")]
       
    26     pub left: EdgeDescription,
       
    27 }
       
    28 
       
    29 #[derive(Deserialize)]
       
    30 #[serde(remote = "TileDescription")]
       
    31 pub struct TileDesc {
       
    32     pub name: String,
       
    33     #[serde(with = "EdgesDesc")]
       
    34     pub edges: EdgesDescription,
       
    35     pub can_flip: bool,
       
    36     pub can_mirror: bool,
       
    37     pub can_rotate90: bool,
       
    38     pub can_rotate180: bool,
       
    39     pub can_rotate270: bool,
       
    40 }
       
    41 
       
    42 #[derive(Deserialize)]
       
    43 pub struct TileDescriptionHelper(#[serde(with = "TileDesc")] TileDescription);
       
    44 
       
    45 #[derive(Deserialize)]
       
    46 pub struct TemplateDesc {
       
    47     pub width: usize,
       
    48     pub height: usize,
       
    49     pub can_flip: bool,
       
    50     pub is_negative: bool,
       
    51     pub put_girders: bool,
       
    52     pub max_hedgehogs: u8,
       
    53     pub tiles: Vec<TileDescriptionHelper>,
       
    54 }
       
    55 
       
    56 #[derive(Deserialize)]
       
    57 pub struct TemplateCollectionDesc {
       
    58     pub templates: Vec<TemplateDesc>,
       
    59     pub template_types: HashMap<String, Vec<usize>>,
       
    60 }
       
    61 
       
    62 impl From<&TemplateDesc> for TemplateDescription {
       
    63     fn from(desc: &TemplateDesc) -> Self {
       
    64         Self {
       
    65             size: Size::new(desc.width, desc.height),
       
    66             tiles: desc
       
    67                 .tiles
       
    68                 .iter()
       
    69                 .map(|TileDescriptionHelper(t)| t.clone())
       
    70                 .collect(),
       
    71         }
       
    72     }
       
    73 }