rust/mapgen/src/template/wavefront_collapse.rs
author unC0Rr
Mon, 13 Feb 2023 12:31:30 +0100
branchtransitional_engine
changeset 15922 da6b67f13c12
child 15923 d46ad15c6dec
permissions -rw-r--r--
Refactor mapgen to allow for easy switching between generators
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
15922
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
     1
use integral_geometry::{Point, Rect, Size};
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
     2
use land2d::Land2D;
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
     3
use landgen::{wavefront_collapse::generator::*, LandGenerationParameters};
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
     4
use serde_derive::Deserialize;
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
     5
use serde_yaml;
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
     6
use std::{borrow::Borrow, collections::hash_map::HashMap, mem::replace};
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,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    35
    pub can_flip: bool,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    36
    pub can_mirror: bool,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    37
    pub can_rotate90: bool,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    38
    pub can_rotate180: bool,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    39
    pub can_rotate270: bool,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    40
}
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
#[derive(Deserialize)]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    43
pub struct TileDescriptionHelper(#[serde(with = "TileDesc")] TileDescription);
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    44
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    45
#[derive(Deserialize)]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    46
pub struct TemplateDesc {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    47
    pub width: usize,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    48
    pub height: usize,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    49
    pub can_flip: bool,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    50
    pub is_negative: bool,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    51
    pub put_girders: bool,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    52
    pub max_hedgehogs: u8,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    53
    pub tiles: Vec<TileDescriptionHelper>,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    54
}
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    55
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    56
#[derive(Deserialize)]
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    57
pub struct TemplateCollectionDesc {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    58
    pub templates: Vec<TemplateDesc>,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    59
    pub template_types: HashMap<String, Vec<usize>>,
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    60
}
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    61
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    62
impl From<&TemplateDesc> for TemplateDescription {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    63
    fn from(desc: &TemplateDesc) -> Self {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    64
        Self {
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    65
            size: Size::new(desc.width, desc.height),
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    66
            tiles: desc
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    67
                .tiles
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    68
                .iter()
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    69
                .map(|TileDescriptionHelper(t)| t.clone())
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    70
                .collect(),
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    71
        }
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    72
    }
da6b67f13c12 Refactor mapgen to allow for easy switching between generators
unC0Rr
parents:
diff changeset
    73
}