lotus_shared/
action.rs

1use serde::{Deserialize, Serialize};
2use serde_repr::{Deserialize_repr, Serialize_repr};
3
4use crate::{
5    input::{ActionState, KeyCode},
6    message::MessageType,
7};
8
9/// Describes an action that can be registered with the engine.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct RegisterAction {
12    pub id: String,
13    pub default_key: KeyCode,
14}
15
16/// Describes an event that is sent when an action is triggered.
17#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
18pub struct ActionEvent {
19    pub name: String,
20    pub state: ActionState,
21}
22
23impl MessageType for ActionEvent {
24    fn id() -> &'static str {
25        "builtin:action_event"
26    }
27}
28
29/// Describes the kind of action that was triggered.
30#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize_repr, Deserialize_repr)]
31#[repr(u8)]
32pub enum ActionKind {
33    Pressed = 1,
34    Released = 2,
35}