use bones_schema::HasSchema;
use self::prelude::{GamepadInputs, KeyboardInputs};
pub mod gamepad;
pub mod keyboard;
pub mod mouse;
pub mod window;
#[derive(HasSchema, Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
#[repr(u8)]
pub enum ButtonState {
Pressed,
#[default]
Released,
}
impl ButtonState {
pub fn pressed(&self) -> bool {
matches!(self, ButtonState::Pressed)
}
}
pub mod prelude {
pub use super::{gamepad::*, keyboard::*, mouse::*, window::*, ButtonState};
pub use crate::input::{InputCollector, PlayerControls};
}
pub trait InputCollector<'a, ControlMapping: HasSchema, ControlSource, Control>:
Send + Sync
{
fn apply_inputs(
&mut self,
mapping: &ControlMapping,
keyboard: &KeyboardInputs,
gamepad: &GamepadInputs,
);
fn advance_frame(&mut self);
fn update_just_pressed(&mut self);
fn get_control(&self, player_idx: usize, control_source: ControlSource) -> &Control;
}
pub trait PlayerControls<'a, Control> {
type InputCollector: InputCollector<'a, Self::ControlMapping, Self::ControlSource, Control>;
type ControlMapping: HasSchema;
type ControlSource;
fn update_controls(&mut self, collector: &mut Self::InputCollector);
fn get_control_source(&self, local_player_idx: usize) -> Option<Self::ControlSource>;
fn get_control(&self, player_idx: usize) -> &Control;
fn get_control_mut(&mut self, player_idx: usize) -> &mut Control;
}