use spectrusty::peripherals::{
joystick::{JoystickInterface, Directions}
};
#[cfg(feature = "minifb")]
pub mod minifb;
#[cfg(feature = "sdl2")]
pub mod sdl2;
#[cfg(feature = "winit")]
pub mod winit;
#[cfg(feature = "web-sys")]
pub mod web_sys;
pub fn update_joystick_from_key_event<'a, K, J, D, F>(
key: K,
pressed: bool,
fire_key: K,
key_to_dir: D,
get_joy: F
) -> bool
where K: PartialEq + Copy,
J: 'a + JoystickInterface + ?Sized,
D: FnOnce(K) -> Directions,
F: FnOnce() -> Option<&'a mut J>
{
let directions = key_to_dir(key);
if !directions.is_empty() {
if let Some(joy) = get_joy() {
let mut cur_dirs = joy.get_directions();
cur_dirs.set(directions, pressed);
joy.set_directions(cur_dirs);
return true
}
}
else if key == fire_key {
if let Some(joy) = get_joy() {
joy.fire(0, pressed);
return true
}
}
false
}