aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:22 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:22 +0100
commit7be602f38f9ba5067de8fa8f3a004ce4e5200ade (patch)
treebccf3cf8acd0043e9292824660b776f69366256e
parent8004132c918a52af3b2e7b32b4fc72c65fde9e3c (diff)
feat(input): add type of inputs to inputmanager trait
-rw-r--r--stockton-input-codegen/src/lib.rs8
-rw-r--r--stockton-input/src/manager.rs3
2 files changed, 11 insertions, 0 deletions
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<Item = &'a ::stockton_input::Action>>(&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<Item = &'a Action>>(&mut self, actions: X);
+ fn get_inputs(&self) -> &Self::Inputs;
}