Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ default-members = ["lighthouse-client"]
resolver = "2"

[workspace.package]
version = "5.1.6"
version = "6.0.0"
edition = "2021"
license = "MIT"

[workspace.dependencies]
lighthouse-protocol = { version = "^5.1.6", path = "lighthouse-protocol" }
lighthouse-protocol = { version = "^6.0.0", path = "lighthouse-protocol" }
24 changes: 22 additions & 2 deletions lighthouse-protocol/src/input/input_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};

use crate::Direction;

use super::{EventSource, GamepadEvent, KeyEvent, MouseEvent};
use super::{EventSource, GamepadEvent, KeyEvent, MouseEvent, UnknownEvent};

/// A user input event, as generated by the new frontend (LUNA).
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
Expand All @@ -11,6 +11,8 @@ pub enum InputEvent {
Key(KeyEvent),
Mouse(MouseEvent),
Gamepad(GamepadEvent),
#[serde(untagged)]
Unknown(UnknownEvent),
}

impl InputEvent {
Expand All @@ -20,6 +22,7 @@ impl InputEvent {
InputEvent::Key(KeyEvent { source, .. }) => source,
InputEvent::Mouse(MouseEvent { source, .. }) => source,
InputEvent::Gamepad(GamepadEvent { source, .. }) => source,
InputEvent::Unknown(UnknownEvent { source, .. }) => source,
}
}

Expand Down Expand Up @@ -53,7 +56,7 @@ impl InputEvent {
mod tests {
use serde_json::json;

use crate::{Delta, EventSource, GamepadAxis2DEvent, GamepadAxisEvent, GamepadButtonEvent, GamepadControlEvent, GamepadEvent, InputEvent, KeyEvent, KeyModifiers, MouseButton, MouseEvent, Pos, Vec2};
use crate::{Delta, EventSource, GamepadAxis2DEvent, GamepadAxisEvent, GamepadButtonEvent, GamepadControlEvent, GamepadEvent, InputEvent, KeyEvent, KeyModifiers, MouseButton, MouseEvent, Pos, UnknownEvent, Vec2};

#[test]
fn key_event() {
Expand Down Expand Up @@ -174,4 +177,21 @@ mod tests {
})
);
}

#[test]
fn unknown_event() {
assert_eq!(
serde_json::from_value::<InputEvent>(json!({
"type": "someEventWeDoNotKnowAbout",
"source": 1,
"possibly": "abc",
"more": "def",
"fields": "ghi"
})).unwrap(),
InputEvent::Unknown(UnknownEvent {
source: EventSource::Int(1),
event_type: "someEventWeDoNotKnowAbout".into(),
})
)
}
}
2 changes: 2 additions & 0 deletions lighthouse-protocol/src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod key_modifiers;
mod legacy_input_event;
mod mouse_button;
mod mouse_event;
mod unknown_event;

pub use event_source::*;
pub use gamepad_axis_2d_event::*;
Expand All @@ -23,3 +24,4 @@ pub use key_modifiers::*;
pub use legacy_input_event::*;
pub use mouse_button::*;
pub use mouse_event::*;
pub use unknown_event::*;
14 changes: 14 additions & 0 deletions lighthouse-protocol/src/input/unknown_event.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
use serde::{Deserialize, Serialize};

use super::EventSource;

/// A gamepad/controller event.
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct UnknownEvent {
/// The event type.
#[serde(rename = "type")]
pub event_type: String,
/// The client identifier. Also unique per gamepad.
pub source: EventSource,
}