wolfrpg_map_parser/db_parser/models/
tile.rs

1#[cfg(feature = "serde")]
2use serde::{Deserialize, Serialize};
3
4/// Settings for a specific tile in a given tileset.
5#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
6#[derive(PartialEq, Clone)]
7pub struct Tile {
8    tag_number: u8,
9    down_not_passable: bool,
10    left_not_passable: bool,
11    right_not_passable: bool,
12    up_not_passable: bool,
13    always_above_character: bool,
14    bottom_half_translucent: bool,
15    conceal_character_behind: bool,
16    match_passable_under: bool
17}
18
19impl Tile {
20    pub fn new(tag_number: u8, options: u32) -> Self {
21        Self {
22            tag_number,
23            down_not_passable: options & 0b00000001 != 0,
24            left_not_passable: options & 0b00000010 != 0,
25            right_not_passable: options & 0b00000100 != 0,
26            up_not_passable: options & 0b00001000 != 0,
27            always_above_character: options & 0b00010000 != 0,
28
29            bottom_half_translucent: options & 0b01000000 != 0,
30
31            conceal_character_behind: (options >> 8) & 0b00000001 != 0,
32            match_passable_under: (options >> 8) & 0b00000010 != 0
33        }
34    }
35
36    /// A value that can be assigned to tiles and retrieved via the [`SetVariablePlus`] command.
37    ///
38    /// [`SetVariablePlus`]: crate::command::set_variable_plus_command::SetVariablePlusCommand
39    pub fn tag_number(&self) -> u8 {
40        self.tag_number
41    }
42
43    /// Mutable reference accessor for [`Tile::tag_number`].
44    pub fn tag_number_mut(&mut self) -> &mut u8 {
45        &mut self.tag_number
46    }
47
48    /// Whether the tile can be passed from its downside.
49    pub fn down_not_passable(&self) -> bool {
50        self.down_not_passable
51    }
52
53    /// Mutable reference accessor for [`Tile::down_not_passable`].
54    pub fn down_not_passable_mut(&mut self) -> &mut bool {
55        &mut self.down_not_passable
56    }
57
58    /// Whether the tile can be passed from its left side.
59    pub fn left_not_passable(&self) -> bool {
60        self.left_not_passable
61    }
62
63    /// Mutable reference accessor for [`Tile::left_not_passable`].
64    pub fn left_not_passable_mut(&mut self) -> &mut bool {
65        &mut self.left_not_passable
66    }
67
68    /// Whether the tile can be passed from its right side.
69    pub fn right_not_passable(&self) -> bool {
70        self.right_not_passable
71    }
72
73    /// Mutable reference accessor for [`Tile::right_not_passable`].
74    pub fn right_not_passable_mut(&mut self) -> &mut bool {
75        &mut self.right_not_passable
76    }
77
78    /// Whether the tile can be passed from its upside.
79    pub fn up_not_passable(&self) -> bool {
80        self.up_not_passable
81    }
82
83    /// Mutable reference accessor for [`Tile::up_not_passable`].
84    pub fn up_not_passable_mut(&mut self) -> &mut bool {
85        &mut self.up_not_passable
86    }
87
88    /// If true, this tile will always be displayed above a character.
89    pub fn always_above_character(&self) -> bool {
90        self.always_above_character
91    }
92
93    /// Mutable reference accessor for [`Tile::always_above_character`].
94    pub fn always_above_character_mut(&mut self) -> &mut bool {
95        &mut self.always_above_character
96    }
97
98    /// If true, the bottom half of this tile will be translucent.
99    pub fn bottom_half_translucent(&self) -> bool {
100        self.bottom_half_translucent
101    }
102
103    /// Mutable reference accessor for [`Tile::bottom_half_translucent`].
104    pub fn bottom_half_translucent_mut(&mut self) -> &mut bool {
105        &mut self.bottom_half_translucent
106    }
107
108    /// If true, this tile will be displayed above characters with a smaller or equal y position.
109    pub fn conceal_character_behind(&self) -> bool {
110        self.conceal_character_behind
111    }
112
113    /// Mutable reference accessor for [`Tile::conceal_character_behind`].
114    pub fn conceal_character_behind_mut(&mut self) -> &mut bool {
115        &mut self.conceal_character_behind
116    }
117
118    /// If true, whether this tile is passable or not depends on the tile on the lower layer.
119    pub fn match_passable_under(&self) -> bool {
120        self.match_passable_under
121    }
122
123    /// Mutable reference accessor for [`Tile::match_passable_under`].
124    pub fn match_passable_under_mut(&mut self) -> &mut bool {
125        &mut self.match_passable_under
126    }
127}