wolfrpg_map_parser/command/show_choice_command/
extra_cases.rs

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
#[cfg(feature = "serde")]
use serde::{Serialize, Deserialize};

#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[derive(PartialEq)]
pub struct ExtraCases {
    left_key: bool,
    right_key: bool,
    force_exit: bool
}

impl ExtraCases {
    pub fn new(extra_cases: u8) -> Self {
        Self {
            left_key:   extra_cases & 0b00000001 != 0,
            right_key:  extra_cases & 0b00000010 != 0,
            force_exit: extra_cases & 0b00000100 != 0
        }
    }

    pub fn count(&self) -> usize {
        self.left_key as usize
        + self.right_key as usize
        + self.force_exit as usize
    }

    pub fn left_key(&self) -> bool {
        self.left_key
    }

    pub fn left_key_mut(&mut self) -> &mut bool {
        &mut self.left_key
    }

    pub fn right_key(&self) -> bool {
        self.right_key
    }

    pub fn right_key_mut(&mut self) -> &mut bool {
        &mut self.right_key
    }

    pub fn force_exit(&self) -> bool {
        self.force_exit
    }

    pub fn force_exit_mut(&mut self) -> &mut bool {
        &mut self.force_exit
    }
}