From e0f3b7c255cb83f5782978a55def988f8a7d7ca2 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 18 Nov 2021 10:32:50 -0500 Subject: [PATCH] Make sure all numpad inputs are mirrored on the number row, so that Mac OS works with numpad controls --- src/player.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/player.rs b/src/player.rs index 096ee20..12105dd 100644 --- a/src/player.rs +++ b/src/player.rs @@ -135,48 +135,49 @@ fn skip_turn(ecs: &mut World) -> RunState { } pub fn player_input(gs: &mut State, ctx: &mut Rltk) -> RunState { - // Player movement + // Mac OS is special when it comes to the numpad. Instead of reporting + // the keys as Numpad-specific numbers, it reports the number row scan + // codes. The quick fix is to match on both types of number scan codes. match ctx.key { None => return RunState::AwaitingInput, // Nothing happened Some(key) => match key { // Cardinal directions VirtualKeyCode::Left | VirtualKeyCode::Numpad4 - | VirtualKeyCode::H - | VirtualKeyCode::Key4 => try_move_player(-1, 0, &mut gs.ecs), + | VirtualKeyCode::Key4 + | VirtualKeyCode::H => try_move_player(-1, 0, &mut gs.ecs), VirtualKeyCode::Right | VirtualKeyCode::Numpad6 - | VirtualKeyCode::L - | VirtualKeyCode::Key6 => try_move_player(1, 0, &mut gs.ecs), + | VirtualKeyCode::Key6 + | VirtualKeyCode::L => try_move_player(1, 0, &mut gs.ecs), VirtualKeyCode::Up | VirtualKeyCode::Numpad8 - | VirtualKeyCode::K - | VirtualKeyCode::Key8 => try_move_player(0, -1, &mut gs.ecs), + | VirtualKeyCode::Key8 + | VirtualKeyCode::K => try_move_player(0, -1, &mut gs.ecs), VirtualKeyCode::Down | VirtualKeyCode::Numpad2 - | VirtualKeyCode::J - | VirtualKeyCode::S - | VirtualKeyCode::Key2 => try_move_player(0, 1, &mut gs.ecs), + | VirtualKeyCode::Key2 + | VirtualKeyCode::J => try_move_player(0, 1, &mut gs.ecs), // Diagonals - VirtualKeyCode::Numpad9 | VirtualKeyCode::Y | VirtualKeyCode::Key9 => { + VirtualKeyCode::Numpad9 | VirtualKeyCode::Key9 | VirtualKeyCode::Y => { try_move_player(1, -1, &mut gs.ecs) } - VirtualKeyCode::Numpad7 | VirtualKeyCode::U | VirtualKeyCode::Key7 => { + VirtualKeyCode::Numpad7 | VirtualKeyCode::Key7 | VirtualKeyCode::U => { try_move_player(-1, -1, &mut gs.ecs) } - VirtualKeyCode::Numpad3 | VirtualKeyCode::N | VirtualKeyCode::Key3 => { + VirtualKeyCode::Numpad3 | VirtualKeyCode::Key3 | VirtualKeyCode::N => { try_move_player(1, 1, &mut gs.ecs) } - VirtualKeyCode::Numpad1 | VirtualKeyCode::B | VirtualKeyCode::Key1 => { + VirtualKeyCode::Numpad1 | VirtualKeyCode::Key1 | VirtualKeyCode::B => { try_move_player(-1, 1, &mut gs.ecs) } // Skip Turn - VirtualKeyCode::Numpad5 | VirtualKeyCode::Space => return skip_turn(&mut gs.ecs), + VirtualKeyCode::Numpad5 | VirtualKeyCode::Key5 | VirtualKeyCode::Space => return skip_turn(&mut gs.ecs), // Level changes VirtualKeyCode::Period => {