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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/// Different kind of slabs (those rectangles the ball can roll on).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SlabKind {
/// Nothing there, Void means empty. Preferring this implementation
/// over an Option as this is really critical and low-level,
/// and an Option would imply pointer and possibly a non-contiguity
/// pf data.
///
/// The base index is -1, this way the floor is 0, so they
/// translate directly into MeshLibrary items.
Void = -1,
/// Default slab kind, a basic stuff one can roll on.
Floor,
/// When stumbing on this, players jumps at max speed.
Boost,
/// A super boost.
Overdrive,
/// HighLight is a highlighted slab, just a visual effect.
/// It should never be returned by the level API, only be used
/// for rendering within Godot.
HighLight,
}
pub const MAX_ITEM: usize = 4;
impl SlabKind {
pub fn as_item(self) -> i64 {
self as i64
}
pub fn from_item(item: i64) -> Self {
match item {
0 => SlabKind::Floor,
1 => SlabKind::Boost,
2 => SlabKind::Overdrive,
3 => SlabKind::HighLight,
_ => SlabKind::Void,
}
}
}
impl std::fmt::Display for SlabKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let c = match self {
SlabKind::Void => " ",
SlabKind::Floor => "#",
SlabKind::Boost => "^",
SlabKind::Overdrive => "O",
SlabKind::HighLight => "*",
};
write!(f, "{}", c)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_fmt() {
assert_eq!(" ", format!("{}", SlabKind::Void));
assert_eq!("#", format!("{}", SlabKind::Floor));
assert_eq!("^", format!("{}", SlabKind::Boost));
assert_eq!("O", format!("{}", SlabKind::Overdrive));
assert_eq!("*", format!("{}", SlabKind::HighLight));
}
}