diff --git a/Cargo.toml b/Cargo.toml index 7e46fb3..2534aa8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" } diff --git a/lighthouse-protocol/src/input/input_event.rs b/lighthouse-protocol/src/input/input_event.rs index 0fe5fd8..a78fd5f 100644 --- a/lighthouse-protocol/src/input/input_event.rs +++ b/lighthouse-protocol/src/input/input_event.rs @@ -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)] @@ -11,6 +11,8 @@ pub enum InputEvent { Key(KeyEvent), Mouse(MouseEvent), Gamepad(GamepadEvent), + #[serde(untagged)] + Unknown(UnknownEvent), } impl InputEvent { @@ -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, } } @@ -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() { @@ -174,4 +177,21 @@ mod tests { }) ); } + + #[test] + fn unknown_event() { + assert_eq!( + serde_json::from_value::(json!({ + "type": "someEventWeDoNotKnowAbout", + "source": 1, + "possibly": "abc", + "more": "def", + "fields": "ghi" + })).unwrap(), + InputEvent::Unknown(UnknownEvent { + source: EventSource::Int(1), + event_type: "someEventWeDoNotKnowAbout".into(), + }) + ) + } } diff --git a/lighthouse-protocol/src/input/mod.rs b/lighthouse-protocol/src/input/mod.rs index 463661c..dd05c64 100644 --- a/lighthouse-protocol/src/input/mod.rs +++ b/lighthouse-protocol/src/input/mod.rs @@ -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::*; @@ -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::*; diff --git a/lighthouse-protocol/src/input/unknown_event.rs b/lighthouse-protocol/src/input/unknown_event.rs new file mode 100644 index 0000000..e6673b4 --- /dev/null +++ b/lighthouse-protocol/src/input/unknown_event.rs @@ -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, +}