Mapped the left stick of a gamepad to be used as a DPad

This commit is contained in:
jan 2024-12-23 20:28:53 +01:00
parent f5ea5b88fe
commit cea522cee3
3 changed files with 24 additions and 7 deletions

2
Cargo.lock generated
View File

@ -1813,7 +1813,7 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
[[package]]
name = "svc16"
version = "0.7.0"
version = "0.7.1"
dependencies = [
"anyhow",
"clap",

View File

@ -1,6 +1,6 @@
[package]
name = "svc16"
version = "0.7.0"
version = "0.7.1"
edition = "2021"
authors = ["Jan Neuendorf"]
description = "An emulator for a simple virtual computer"
@ -18,4 +18,5 @@ winit-input-map = {version="0.4.1",optional=true}
winit_input_helper = "0.16.0"
[features]
default=[]
gamepad = ["gilrs","winit-input-map"]

View File

@ -8,7 +8,7 @@ use winit::{
};
use winit_input_helper::WinitInputHelper;
#[cfg(feature = "gamepad")]
use winit_input_map::{input_map, GamepadButton, InputMap};
use winit_input_map::{input_map, GamepadAxis, GamepadButton, InputCode, InputMap};
#[cfg(feature = "gamepad")]
#[derive(Debug, std::hash::Hash, PartialEq, Eq, Clone, Copy)]
@ -30,10 +30,26 @@ pub fn build_gamepad_map() -> InputMap<NesInput> {
(NesInput::B, GamepadButton::South),
(NesInput::Select, GamepadButton::Select),
(NesInput::Start, GamepadButton::Start),
(NesInput::Up, GamepadButton::DPadUp),
(NesInput::Down, GamepadButton::DPadDown),
(NesInput::Left, GamepadButton::DPadLeft),
(NesInput::Right, GamepadButton::DPadRight)
(
NesInput::Up,
GamepadButton::DPadUp,
InputCode::gamepad_axis_pos(GamepadAxis::LeftStickY)
),
(
NesInput::Down,
GamepadButton::DPadDown,
InputCode::gamepad_axis_neg(GamepadAxis::LeftStickY)
),
(
NesInput::Left,
GamepadButton::DPadLeft,
InputCode::gamepad_axis_neg(GamepadAxis::LeftStickX)
),
(
NesInput::Right,
GamepadButton::DPadRight,
InputCode::gamepad_axis_pos(GamepadAxis::LeftStickX)
)
)
}