rust/mapgen/src/template/wavefront_collapse.rs
author unC0Rr
Tue, 14 Feb 2023 08:52:20 +0100
branchtransitional_engine
changeset 15954 9502611bffc1
parent 15953 d46ad15c6dec
child 15955 b0e8cc72bfef
permissions -rw-r--r--
Some bug fixes, build fixes and code formatting
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
     1
use integral_geometry::Size;
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
     2
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
     3
use landgen::wavefront_collapse::generator::*;
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
     4
use serde_derive::Deserialize;
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
     5
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
     6
use std::collections::hash_map::HashMap;
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
     7
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
     8
#[derive(Deserialize)]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
     9
#[serde(remote = "EdgeDescription")]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    10
pub struct EdgeDesc {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    11
    pub name: String,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    12
    pub reversed: Option<bool>,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    13
    pub symmetrical: Option<bool>,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    14
}
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    15
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    16
#[derive(Deserialize)]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    17
#[serde(remote = "EdgesDescription")]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    18
pub struct EdgesDesc {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    19
    #[serde(with = "EdgeDesc")]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    20
    pub top: EdgeDescription,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    21
    #[serde(with = "EdgeDesc")]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    22
    pub right: EdgeDescription,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    23
    #[serde(with = "EdgeDesc")]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    24
    pub bottom: EdgeDescription,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    25
    #[serde(with = "EdgeDesc")]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    26
    pub left: EdgeDescription,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    27
}
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    28
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    29
#[derive(Deserialize)]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    30
#[serde(remote = "TileDescription")]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    31
pub struct TileDesc {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    32
    pub name: String,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    33
    #[serde(with = "EdgesDesc")]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    34
    pub edges: EdgesDescription,
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    35
    pub is_negative: Option<bool>,
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    36
    pub can_flip: Option<bool>,
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    37
    pub can_mirror: Option<bool>,
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    38
    pub can_rotate90: Option<bool>,
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    39
    pub can_rotate180: Option<bool>,
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    40
    pub can_rotate270: Option<bool>,
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    41
}
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    42
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    43
#[derive(Deserialize)]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    44
pub struct TileDescriptionHelper(#[serde(with = "TileDesc")] TileDescription);
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    45
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    46
#[derive(Deserialize)]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    47
pub struct TemplateDesc {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    48
    pub width: usize,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    49
    pub height: usize,
15953
d46ad15c6dec Get wavefront collapse generator to work in engine
unC0Rr
parents: 15952
diff changeset
    50
    pub can_invert: bool,
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    51
    pub is_negative: bool,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    52
    pub put_girders: bool,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    53
    pub max_hedgehogs: u8,
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    54
    pub wrap: bool,
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    55
    pub tiles: Vec<TileDescriptionHelper>,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    56
}
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    57
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    58
#[derive(Deserialize)]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    59
pub struct TemplateCollectionDesc {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    60
    pub templates: Vec<TemplateDesc>,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    61
    pub template_types: HashMap<String, Vec<usize>>,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    62
}
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    63
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    64
impl From<&TemplateDesc> for TemplateDescription {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    65
    fn from(desc: &TemplateDesc) -> Self {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    66
        Self {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    67
            size: Size::new(desc.width, desc.height),
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    68
            tiles: desc
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    69
                .tiles
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    70
                .iter()
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    71
                .map(|TileDescriptionHelper(t)| t.clone())
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    72
                .collect(),
15954
9502611bffc1 Some bug fixes, build fixes and code formatting
unC0Rr
parents: 15953
diff changeset
    73
            wrap: desc.wrap,
15952
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    74
        }
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    75
    }
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    76
}