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
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};

use crate::{
    input::{ActionState, KeyCode},
    message::MessageType,
};

/// Describes an action that can be registered with the engine.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RegisterAction {
    pub id: String,
    pub default_key: KeyCode,
}

/// Describes an event that is sent when an action is triggered.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct ActionEvent {
    pub name: String,
    pub state: ActionState,
}

impl MessageType for ActionEvent {
    fn id() -> &'static str {
        "builtin:action_event"
    }
}

/// Describes the kind of action that was triggered.
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize_repr, Deserialize_repr)]
#[repr(u8)]
pub enum ActionKind {
    Pressed = 1,
    Released = 2,
}