wolfrpg_map_parser/command/input_key_command/
input_toggle.rs1#[cfg(feature = "serde")]
2use serde::{Serialize, Deserialize};
3use crate::command::input_key_command::input_toggle::input_type::InputType;
4use crate::command::input_key_command::input_toggle::state::State;
5
6pub mod input_type;
7pub mod state;
8pub mod basic;
9pub mod basic_inputs;
10pub mod enabled_inputs;
11pub mod device;
12pub mod device_inputs;
13
14#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
15#[derive(PartialEq, Clone)]
16pub struct InputToggle {
17 input_type: InputType,
18 state: State
19}
20
21impl InputToggle {
22 pub(crate) fn parse(bytes: &[u8]) -> (usize, Self) {
23 let mut offset: usize = 0;
24
25 let input_type: u8 = bytes[offset+3];
26 let input_type: InputType = InputType::new(input_type);
27
28 let (bytes_read, state): (usize, State) = State::parse(&bytes[offset..], &input_type);
29 offset += bytes_read;
30
31 offset += 3; (offset, Self {
34 input_type,
35 state
36 })
37 }
38
39 pub fn input_type(&self) -> &InputType {
40 &self.input_type
41 }
42
43 pub fn input_type_mut(&mut self) -> &mut InputType {
44 &mut self.input_type
45 }
46
47 pub fn state(&self) -> &State {
48 &self.state
49 }
50
51 pub fn state_mut(&mut self) -> &mut State {
52 &mut self.state
53 }
54}