From 7be602f38f9ba5067de8fa8f3a004ce4e5200ade Mon Sep 17 00:00:00 2001 From: tcmal Date: Sun, 25 Aug 2024 17:44:22 +0100 Subject: feat(input): add type of inputs to inputmanager trait --- stockton-input-codegen/src/lib.rs | 8 ++++++++ stockton-input/src/manager.rs | 3 +++ 2 files changed, 11 insertions(+) diff --git a/stockton-input-codegen/src/lib.rs b/stockton-input-codegen/src/lib.rs index a6e8215..d3ee525 100644 --- a/stockton-input-codegen/src/lib.rs +++ b/stockton-input-codegen/src/lib.rs @@ -51,6 +51,7 @@ pub fn derive_inputmanager(input: TokenStream) -> TokenStream { ); let trait_impl = gen_trait_impl( &manager_ident, + &struct_ident, &fields_enum_ident, &buttons, &axes, @@ -234,6 +235,7 @@ fn gen_manager_struct( /// ``` fn gen_trait_impl( manager: &Ident, + struct_ident: &Ident, fields_enum: &Ident, buttons: &[Ident], axes: &[Ident], @@ -246,6 +248,8 @@ fn gen_trait_impl( quote!( impl InputManager for #manager { + type Inputs = #struct_ident; + fn handle_frame<'a, X: IntoIterator>(&mut self, actions: X) -> () { #(#just_hot_resets)* @@ -267,6 +271,10 @@ fn gen_trait_impl( } } } + + fn get_inputs(&self) -> &Self::Inputs { + &self.inputs + } } ) } diff --git a/stockton-input/src/manager.rs b/stockton-input/src/manager.rs index 4d2d001..f0786b0 100644 --- a/stockton-input/src/manager.rs +++ b/stockton-input/src/manager.rs @@ -46,5 +46,8 @@ impl Action { } pub trait InputManager { + type Inputs; + fn handle_frame<'a, X: IntoIterator>(&mut self, actions: X); + fn get_inputs(&self) -> &Self::Inputs; } -- cgit v1.2.3