rust/landgen/src/outline_template_based/outline_template.rs
author unC0Rr
Sun, 01 Dec 2024 21:08:03 +0100
branchtransitional_engine
changeset 16044 5c941f5deeec
parent 16029 9cbd18220eb7
permissions -rw-r--r--
* Introduce concept of invizible walls to constrain outline map generation * Rework some templates to work better with new parameters in rust landgen
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     1
use integral_geometry::{Point, Rect, Size};
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     2
14128
b04dac00e8e2 add command arguments to use a template from file into land_dump
alfadur
parents: 14126
diff changeset
     3
#[derive(Clone, Debug)]
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     4
pub struct OutlineTemplate {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     5
    pub islands: Vec<Vec<Rect>>,
16044
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16029
diff changeset
     6
    pub walls: Vec<Vec<Rect>>,
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     7
    pub fill_points: Vec<Point>,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     8
    pub size: Size,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
     9
    pub can_flip: bool,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    10
    pub can_invert: bool,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    11
    pub can_mirror: bool,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    12
    pub is_negative: bool,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    13
}
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    14
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    15
impl OutlineTemplate {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    16
    pub fn new(size: Size) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    17
        OutlineTemplate {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    18
            size,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    19
            islands: Vec::new(),
16044
5c941f5deeec * Introduce concept of invizible walls to constrain outline map generation
unC0Rr
parents: 16029
diff changeset
    20
            walls: Vec::new(),
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    21
            fill_points: Vec::new(),
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    22
            can_flip: false,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    23
            can_invert: false,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    24
            can_mirror: false,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    25
            is_negative: false,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    26
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    27
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    28
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    29
    pub fn flippable(self) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    30
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    31
            can_flip: true,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    32
            ..self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    33
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    34
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    35
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    36
    pub fn mirrorable(self) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    37
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    38
            can_mirror: true,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    39
            ..self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    40
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    41
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    42
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    43
    pub fn invertable(self) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    44
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    45
            can_invert: true,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    46
            ..self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    47
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    48
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    49
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    50
    pub fn negative(self) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    51
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    52
            is_negative: true,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    53
            ..self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    54
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    55
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    56
16029
9cbd18220eb7 Fix cavern templates
unC0Rr
parents: 15921
diff changeset
    57
    pub fn cavern(self) -> Self {
9cbd18220eb7 Fix cavern templates
unC0Rr
parents: 15921
diff changeset
    58
        Self {
9cbd18220eb7 Fix cavern templates
unC0Rr
parents: 15921
diff changeset
    59
            is_negative: true,
9cbd18220eb7 Fix cavern templates
unC0Rr
parents: 15921
diff changeset
    60
            can_invert: false,
9cbd18220eb7 Fix cavern templates
unC0Rr
parents: 15921
diff changeset
    61
            ..self
9cbd18220eb7 Fix cavern templates
unC0Rr
parents: 15921
diff changeset
    62
        }
9cbd18220eb7 Fix cavern templates
unC0Rr
parents: 15921
diff changeset
    63
    }
9cbd18220eb7 Fix cavern templates
unC0Rr
parents: 15921
diff changeset
    64
14069
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    65
    pub fn with_fill_points(self, fill_points: Vec<Point>) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    66
        Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    67
            fill_points,
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    68
            ..self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    69
        }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    70
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    71
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    72
    pub fn with_islands(self, islands: Vec<Vec<Rect>>) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    73
        Self { islands, ..self }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    74
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    75
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    76
    pub fn add_fill_points(mut self, points: &[Point]) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    77
        self.fill_points.extend_from_slice(points);
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    78
        self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    79
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    80
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    81
    pub fn add_island(mut self, island: &[Rect]) -> Self {
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    82
        self.islands.push(island.into());
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    83
        self
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    84
    }
abb42ba345b6 Rework lib structure, no code changes
unC0Rr
parents:
diff changeset
    85
}