~starkingdoms/starkingdoms

ae2065e5a194e9d2cd80242c859a37903bb6aab6 — c0repwn3r 2 years ago b16e992
input subsystem basics
2 files changed, 38 insertions(+), 0 deletions(-)

A client/src/input/mod.rs
M client/src/lib.rs
A client/src/input/mod.rs => client/src/input/mod.rs +37 -0
@@ 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<Self, Box<dyn Error>> where Self: Sized;

    async fn register_on_mouse_move(&mut self, id: &str, callback: dyn FnMut(OnMouseMoveEvent)) -> Result<(), Box<dyn Error>>;
    async fn unregister_on_mouse_move(&mut self, id: &str) -> Result<(), Box<dyn Error>>;

    async fn register_on_key_down(&mut self, id: &str, callback: dyn FnMut(OnKeyDownEvent)) -> Result<(), Box<dyn Error>>;
    async fn unregister_on_key_down(&mut self, id: &str) -> Result<(), Box<dyn Error>>;

    async fn register_on_key_up(&mut self, id: &str, callback: dyn FnMut(OnKeyUpEvent)) -> Result<(), Box<dyn Error>>;
    async fn unregister_on_key_up(&mut self, id: &str) -> Result<(), Box<dyn Error>>;

    async fn register_on_keypress(&mut self, id: &str, callback: dyn FnMut(OnKeypressEvent)) -> Result<(), Box<dyn Error>>;
    async fn unregister_on_keypress(&mut self, id: &str) -> Result<(), Box<dyn Error>>;

    async fn register_on_click(&mut self, id: &str, callback: dyn FnMut(OnClickEvent)) -> Result<(), Box<dyn Error>>;
    async fn unregister_on_click(&mut self, id: &str) -> Result<(), Box<dyn Error>>;
}

pub struct OnMouseMoveEvent {}
pub struct OnKeyDownEvent {}
pub struct OnKeyUpEvent {}
pub struct OnKeypressEvent {}
pub struct OnClickEvent {}
\ No newline at end of file

M client/src/lib.rs => client/src/lib.rs +1 -0
@@ 33,6 33,7 @@ pub mod macros;
pub mod chat;
pub mod rendering;
pub mod textures;
pub mod input;

#[wasm_bindgen]
extern {