wolfrpg_map_parser/command/input_key_command/automatic_input/
state.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
#[cfg(feature = "serde")]
use serde::Serialize;
use crate::command::input_key_command::automatic_input::basic::Basic;
use crate::command::input_key_command::automatic_input::input_type::InputType;
use crate::command::input_key_command::automatic_input::keyboard::Keyboard;
use crate::command::input_key_command::automatic_input::mouse::Mouse;

#[cfg_attr(feature = "serde", derive(Serialize))]
pub enum State {
    Basic(Basic),
    Keyboard(Keyboard),
    Mouse(Mouse)
}

impl State {
    pub fn parse_base(bytes: &[u8], input_type: &InputType) -> (usize, Self) {
        match *input_type {
            InputType::Basic => {
                let (bytes_read, state): (usize, Basic) = Basic::parse(bytes);

                (bytes_read, Self::Basic(state))
            }

            InputType::Mouse => {
                let (bytes_read, mouse): (usize, Mouse) = Mouse::parse(bytes);

                (bytes_read, Self::Mouse(mouse))
            }

            _ => unreachable!()
        }
    }

    pub fn parse_keyboard(bytes: &[u8], _: &InputType) -> (usize, Self) {
        let (bytes_read, keyboard): (usize, Keyboard) = Keyboard::parse(bytes);

        (bytes_read, Self::Keyboard(keyboard))
    }
}