wolfrpg_map_parser/command/input_key_command/input_toggle/
basic_inputs.rs

1#[cfg(feature = "serde")]
2use serde::{Serialize, Deserialize};
3
4#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
5#[derive(PartialEq, Clone)]
6pub struct BasicInputs {
7    ok: bool,
8    cancel: bool,
9    sub: bool,
10    down: bool,
11    left: bool,
12    right: bool,
13    up: bool
14}
15
16impl BasicInputs {
17    pub fn new(inputs: u8) -> Self {
18        Self {
19            ok:     inputs & 0b00000001 != 0,
20            cancel: inputs & 0b00000010 != 0,
21            sub:    inputs & 0b00000100 != 0,
22            down:   inputs & 0b00010000 != 0,
23            left:   inputs & 0b00100000 != 0,
24            right:  inputs & 0b01000000 != 0,
25            up:     inputs & 0b10000000 != 0,
26        }
27    }
28
29    pub fn ok(&self) -> bool {
30        self.ok
31    }
32
33    pub fn ok_mut(&mut self) -> &mut bool {
34        &mut self.ok
35    }
36
37    pub fn cancel(&self) -> bool {
38        self.cancel
39    }
40
41    pub fn cancel_mut(&mut self) -> &mut bool {
42        &mut self.cancel
43    }
44
45    pub fn sub(&self) -> bool {
46        self.sub
47    }
48
49    pub fn sub_mut(&mut self) -> &mut bool {
50        &mut self.sub
51    }
52
53    pub fn down(&self) -> bool {
54        self.down
55    }
56
57    pub fn down_mut(&mut self) -> &mut bool {
58        &mut self.down
59    }
60
61    pub fn left(&self) -> bool {
62        self.left
63    }
64
65    pub fn left_mut(&mut self) -> &mut bool {
66        &mut self.left
67    }
68
69    pub fn right(&self) -> bool {
70        self.right
71    }
72
73    pub fn right_mut(&mut self) -> &mut bool {
74        &mut self.right
75    }
76
77    pub fn up(&self) -> bool {
78        self.up
79    }
80
81    pub fn up_mut(&mut self) -> &mut bool {
82        &mut self.up
83    }
84}