From ae2065e5a194e9d2cd80242c859a37903bb6aab6 Mon Sep 17 00:00:00 2001 From: c0repwn3r Date: Thu, 13 Apr 2023 09:16:30 -0400 Subject: [PATCH] input subsystem basics --- client/src/input/mod.rs | 37 +++++++++++++++++++++++++++++++++++++ client/src/lib.rs | 1 + 2 files changed, 38 insertions(+) create mode 100644 client/src/input/mod.rs diff --git a/client/src/input/mod.rs b/client/src/input/mod.rs new file mode 100644 index 0000000000000000000000000000000000000000..a768e2fa2d06c7011374dce4131a0ff3f0d28c08 --- /dev/null +++ b/client/src/input/mod.rs @@ -0,0 +1,37 @@ +use std::error::Error; +use async_trait::async_trait; + +/* +Functions the input subsystem needs to perform: +- init +- register and unregister event handlers for: + - mouse movement + - keydown, keyup, keypress + - clicks + */ + +#[async_trait] +pub trait InputSubsystem { + async fn init() -> Result> where Self: Sized; + + async fn register_on_mouse_move(&mut self, id: &str, callback: dyn FnMut(OnMouseMoveEvent)) -> Result<(), Box>; + async fn unregister_on_mouse_move(&mut self, id: &str) -> Result<(), Box>; + + async fn register_on_key_down(&mut self, id: &str, callback: dyn FnMut(OnKeyDownEvent)) -> Result<(), Box>; + async fn unregister_on_key_down(&mut self, id: &str) -> Result<(), Box>; + + async fn register_on_key_up(&mut self, id: &str, callback: dyn FnMut(OnKeyUpEvent)) -> Result<(), Box>; + async fn unregister_on_key_up(&mut self, id: &str) -> Result<(), Box>; + + async fn register_on_keypress(&mut self, id: &str, callback: dyn FnMut(OnKeypressEvent)) -> Result<(), Box>; + async fn unregister_on_keypress(&mut self, id: &str) -> Result<(), Box>; + + async fn register_on_click(&mut self, id: &str, callback: dyn FnMut(OnClickEvent)) -> Result<(), Box>; + async fn unregister_on_click(&mut self, id: &str) -> Result<(), Box>; +} + +pub struct OnMouseMoveEvent {} +pub struct OnKeyDownEvent {} +pub struct OnKeyUpEvent {} +pub struct OnKeypressEvent {} +pub struct OnClickEvent {} \ No newline at end of file diff --git a/client/src/lib.rs b/client/src/lib.rs index 15446cfc3a4c50d7ddb470c11bb4b2a560f12c89..9a53e169ab1fd6fc8b0fb24cac53a7df45840f52 100644 --- a/client/src/lib.rs +++ b/client/src/lib.rs @@ -33,6 +33,7 @@ pub mod macros; pub mod chat; pub mod rendering; pub mod textures; +pub mod input; #[wasm_bindgen] extern {