rpgtools/map/gridmap/
gridcell.rs1#[derive(Clone, Debug, PartialEq)]
2pub enum AreaType {
3 Nothing,
4 Entrance,
5 Room,
6 }
9
10#[derive(Clone, Debug)]
11pub enum WallType {
12 Nothing,
13 }
17
18#[derive(Clone, Debug)]
19pub enum PointType {
20 Nothing,
21 }
23
24#[derive(Clone, Debug)]
26pub struct GridCell {
27 pub area: AreaType,
29 vert_wall: WallType,
30 horiz_wall: WallType,
31 point: PointType,
32}
33
34impl GridCell {
35 pub fn new() -> GridCell {
37 GridCell {
38 area: AreaType::Nothing,
39 vert_wall: WallType::Nothing,
40 horiz_wall: WallType::Nothing,
41 point: PointType::Nothing,
42 }
43 }
44
45 pub fn is_empty(&self) -> bool {
48 matches!(
49 *self,
50 GridCell {
51 area: AreaType::Nothing,
52 vert_wall: WallType::Nothing,
53 horiz_wall: WallType::Nothing,
54 point: PointType::Nothing,
55 ..
56 }
57 )
58 }
59
60 pub fn is_room(&self) -> bool {
70 !matches!(
71 *self,
72 GridCell {
73 area: AreaType::Nothing,
74 ..
75 }
76 )
77 }
78
79 pub fn area(&self) -> &AreaType {
81 &self.area
82 }
83
84 pub fn set_area(&mut self, area: AreaType) {
86 self.area = area;
87 }
88}
89
90impl Default for GridCell {
91 fn default() -> Self {
92 Self::new()
93 }
94}
95
96#[cfg(test)]
97mod tests {
98 use super::*;
99
100 #[test]
101 fn new() {
102 let cell = GridCell::new();
103 assert_eq!(AreaType::Nothing, cell.area);
104 }
105
106 #[test]
107 fn is_empty() {
108 let mut cell = GridCell::new();
109 cell.area = AreaType::Nothing;
111 assert_eq!(true, cell.is_empty());
112 cell.area = AreaType::Entrance;
113 assert_eq!(false, cell.is_empty());
114 cell.area = AreaType::Room;
115 assert_eq!(false, cell.is_empty());
116 }
117
118 #[test]
119 fn is_room() {
120 let mut cell = GridCell::new();
121 cell.area = AreaType::Nothing;
123 assert_eq!(false, cell.is_room());
124 cell.area = AreaType::Entrance;
125 assert_eq!(true, cell.is_room());
126 cell.area = AreaType::Room;
127 assert_eq!(true, cell.is_room());
128 }
129}