use crate::{Button, AnyButton, DPad};
#[derive(Default, Debug, PartialEq, Clone, Copy)]
pub struct APad {
pub left_stick_x: i16,
pub left_stick_y: i16,
pub buttons: DPad,
}
impl APad {
pub fn new() -> Self {
Self::default()
}
#[inline(always)]
pub fn copy_current_to_previous_state(&mut self) {
self.buttons.copy_current_to_previous_state();
}
#[inline(always)]
pub fn is_down(&self, button: Button) -> bool {
self.buttons.is_down(button)
}
#[inline(always)]
pub fn is_up(&self, button: Button) -> bool {
self.buttons.is_up(button)
}
#[inline(always)]
pub fn is_just_pressed(&self, button: Button) -> bool {
self.buttons.is_just_pressed(button)
}
#[inline(always)]
pub fn is_just_released(&self, button: Button) -> bool {
self.buttons.is_just_released(button)
}
#[inline(always)]
pub fn is_any_down(&self, button_group: AnyButton) -> bool {
self.buttons.is_any_down(button_group)
}
#[inline(always)]
pub fn is_any_just_pressed(&self, button_group: AnyButton) -> bool {
self.buttons.is_any_just_pressed(button_group)
}
#[inline(always)]
pub fn is_any_just_released(&self, button_group: AnyButton) -> bool {
self.buttons.is_any_just_released(button_group)
}
#[inline(always)]
pub fn buttons(&self) -> u16 {
self.buttons.state
}
#[inline(always)]
pub fn left_stick_x(&self) -> f32 {
(self.left_stick_x as f32 / i16::MAX as f32).clamp(-1.0, 1.0)
}
#[inline(always)]
pub fn left_stick_y(&self) -> f32 {
(self.left_stick_y as f32 / i16::MAX as f32).clamp(-1.0, 1.0)
}
#[inline(always)]
pub fn set_button(&mut self, button: Button, value: bool) {
self.buttons.set_state(button, value);
}
#[inline(always)]
pub fn set_left_stick_x(&mut self, x: f32) {
self.left_stick_x = (x.clamp(-1.0, 1.0) * i16::MAX as f32) as i16;
}
#[inline(always)]
pub fn set_left_stick_y(&mut self, y: f32) {
self.left_stick_y = (y.clamp(-1.0, 1.0) * i16::MAX as f32) as i16;
}
}