1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use common::terrain::Block;

#[derive(Copy, Clone)]
pub struct BlockMask {
    block: Option<Block>,
    priority: i32,
}

impl BlockMask {
    pub const fn new(block: Block, priority: i32) -> Self {
        Self {
            block: Some(block),
            priority,
        }
    }

    pub const fn nothing() -> Self {
        Self {
            block: None,
            priority: 0,
        }
    }

    #[must_use]
    pub const fn with_priority(mut self, priority: i32) -> Self {
        self.priority = priority;
        self
    }

    #[must_use]
    pub const fn resolve_with(self, other: Self) -> Self {
        if self.priority >= other.priority {
            self
        } else {
            other
        }
    }

    pub const fn finish(self) -> Option<Block> { self.block }
}