From 70a9142c9f62ea30022a7972fb9f25017b49bf06 Mon Sep 17 00:00:00 2001 From: Dregu Date: Sat, 11 Nov 2023 18:10:52 +0200 Subject: [PATCH] fix indexing with input_mapping --- docs/game_data/lua_enums.txt | 183 +++++++++--------- docs/game_data/spel2.lua | 129 +++++++++++- docs/src/includes/_types.md | 6 +- src/game_api/game_manager.hpp | 5 +- .../script/usertypes/game_manager_lua.cpp | 126 ++++++------ 5 files changed, 288 insertions(+), 161 deletions(-) diff --git a/docs/game_data/lua_enums.txt b/docs/game_data/lua_enums.txt index b107f6480..0b52187a5 100644 --- a/docs/game_data/lua_enums.txt +++ b/docs/game_data/lua_enums.txt @@ -2569,97 +2569,98 @@ QUEST_FLAG = { WADDLER_AGGROED = 10 } RAW_KEY = { - ["0"] = 66, - ["1"] = 67, - ["2"] = 68, - ["3"] = 69, - ["4"] = 70, - ["5"] = 71, - ["6"] = 72, - ["7"] = 73, - ["8"] = 74, - ["9"] = 75, - A = 8, - ADD = 87, - ALT = 38, - B = 9, - BACKSPACE = 41, - C = 10, - COMMA = 94, - CTRL = 34, - D = 11, - DECIMAL = 91, - DELETE = 105, - DIVIDE = 89, - DOWN = 2, - E = 12, - END = 107, - ESCAPE = 5, - F = 13, - F1 = 42, - F2 = 43, - F3 = 44, - F4 = 45, - F5 = 46, - F6 = 47, - F7 = 48, - F8 = 49, - F9 = 50, - F10 = 51, - F11 = 52, - F12 = 53, - G = 14, - H = 15, - HOME = 109, - I = 16, - INSERT = 104, - J = 17, - K = 18, - L = 19, - LALT = 38, - LCONTROL = 34, - LEFT = 3, - LSHIFT = 36, - M = 20, - MINUS = 93, - MULTIPLY = 88, - N = 21, - NUMPAD0 = 76, - NUMPAD1 = 77, - NUMPAD2 = 78, - NUMPAD3 = 79, - NUMPAD4 = 80, - NUMPAD5 = 81, - NUMPAD6 = 82, - NUMPAD7 = 83, - NUMPAD8 = 84, - NUMPAD9 = 85, - O = 22, - P = 23, - PERIOD = 95, - PGDN = 106, - PGUP = 108, - PLUS = 99, - Q = 24, - R = 25, - RALT = 39, - RCONTROL = 35, - RETURN = 6, - RIGHT = 4, - RSHIFT = 37, - S = 26, - SHIFT = 36, - SPACE = 40, - SUBTRACT = 86, - T = 27, - TAB = 7, - U = 28, - UP = 1, - V = 29, - W = 30, - X = 31, - Y = 32, - Z = 33 + ["0"] = 65, + ["1"] = 66, + ["2"] = 67, + ["3"] = 68, + ["4"] = 69, + ["5"] = 70, + ["6"] = 71, + ["7"] = 72, + ["8"] = 73, + ["9"] = 74, + A = 9, + ADD = 86, + ALT = 37, + B = 10, + BACKSPACE = 40, + C = 11, + COMMA = 93, + CTRL = 33, + D = 12, + DECIMAL = 90, + DELETE = 104, + DIVIDE = 88, + DOWN = 1, + E = 13, + END = 106, + ESCAPE = 4, + F = 14, + F1 = 41, + F2 = 42, + F3 = 43, + F4 = 44, + F5 = 45, + F6 = 46, + F7 = 47, + F8 = 48, + F9 = 49, + F10 = 50, + F11 = 51, + F12 = 52, + G = 15, + H = 16, + HOME = 108, + I = 17, + INSERT = 103, + J = 18, + K = 19, + L = 20, + LALT = 37, + LCONTROL = 33, + LEFT = 2, + LSHIFT = 35, + M = 21, + MINUS = 92, + MULTIPLY = 87, + N = 22, + NUMPAD0 = 75, + NUMPAD1 = 76, + NUMPAD2 = 77, + NUMPAD3 = 78, + NUMPAD4 = 79, + NUMPAD5 = 80, + NUMPAD6 = 81, + NUMPAD7 = 82, + NUMPAD8 = 83, + NUMPAD9 = 84, + NUMPADENTER = 110, + O = 23, + P = 24, + PERIOD = 94, + PGDN = 105, + PGUP = 107, + PLUS = 98, + Q = 25, + R = 26, + RALT = 38, + RCONTROL = 34, + RETURN = 5, + RIGHT = 3, + RSHIFT = 36, + S = 27, + SHIFT = 35, + SPACE = 39, + SUBTRACT = 85, + T = 28, + TAB = 6, + U = 29, + UP = 0, + V = 30, + W = 31, + X = 32, + Y = 33, + Z = 34 } RECURSIVE_MODE = { EXCLUSIVE = 0, diff --git a/docs/game_data/spel2.lua b/docs/game_data/spel2.lua index 5b9086e01..03c911d6f 100644 --- a/docs/game_data/spel2.lua +++ b/docs/game_data/spel2.lua @@ -2297,15 +2297,15 @@ do ---@field input_index integer[] @size: 5 @Input index for players 1-4 and maybe for the menu controls. -1: disabled, 0..3: keyboards, 4..7: Xinput, 8..11: other controllers ---@class RawInput - ---@field keyboard KeyboardKey[] @size: 112 @State of all keyboard buttons in a random game order as usual, most key indexes can be found in RAW_KEY. - ---@field controller ControllerInput[] @size: 12 @State of controller buttons per controller. Zero-based indexing, i.e. use game_props.input_index directly to index this. + ---@field keyboard KeyboardKey[] @size: 112 @State of all keyboard buttons in a random game order as usual, most key indexes can be found in RAW_KEY. Zero-based indexing, i.e. use PlayerSlot.input_mapping_keyboard directly to index this. + ---@field controller ControllerInput[] @size: 12 @State of controller buttons per controller. Zero-based indexing, i.e. use GameProps.input_index directly to index this. ---@class KeyboardKey ---@field down boolean @Key is being held ---@field pressed boolean @Key was just pressed down this frame ---@class ControllerInput - ---@field buttons ControllerButton[] @size: 16 + ---@field buttons ControllerButton[] @size: 16 @Zero-based indexing, i.e. use PlayerSlot.input_mapping_controller directly to index this. ---@class ControllerButton ---@field down boolean @Button is being held @@ -8470,6 +8470,7 @@ KEY = { ["6"] = 54, ["7"] = 55, ["8"] = 56, + ["9"] = 57, A = 65, ADD = 107, ALT = 18, @@ -8588,7 +8589,8 @@ KEY = { V = 86, W = 87, X = 88, - Y = 89 + Y = 89, + Z = 90 } ---@alias KEY integer LAYER = { @@ -8622,6 +8624,13 @@ LEVEL_CONFIG = { MOUNT_CHANCE = 4 } ---@alias LEVEL_CONFIG integer +LIGHT_TYPE = { + FOLLOW_CAMERA = 1, + FOLLOW_ENTITY = 2, + NONE = 0, + ROOM_LIGHT = 4 +} +---@alias LIGHT_TYPE integer LIQUID_POOL = { COARSE_LAVA = 4, COARSE_WATER = 2, @@ -8681,6 +8690,19 @@ MASK = { WATER = 8192 } ---@alias MASK integer +MENU_INPUT = { + BACK = 2, + DELETE = 4, + DOWN = 256, + JOURNAL = 16, + LEFT = 32, + NONE = 0, + RANDOM = 8, + RIGHT = 64, + SELECT = 1, + UP = 128 +} +---@alias MENU_INPUT integer ON = { ARENA_INTRO = 25, ARENA_ITEMS = 23, @@ -8709,6 +8731,7 @@ ON = { ONLINE_LOBBY = 29, OPTIONS = 5, PLAYER_PROFILE = 6, + POST_GAME_LOOP = 156, POST_LAYER_CREATION = 148, POST_LAYER_DESTRUCTION = 152, POST_LEVEL_CREATION = 146, @@ -8716,8 +8739,10 @@ ON = { POST_LEVEL_GENERATION = 112, POST_LOAD_JOURNAL_CHAPTER = 139, POST_LOAD_SCREEN = 136, + POST_PROCESS_INPUT = 154, POST_ROOM_GENERATION = 111, POST_UPDATE = 143, + PRE_GAME_LOOP = 155, PRE_GET_FEAT = 140, PRE_GET_RANDOM_ROOM = 113, PRE_HANDLE_ROOM_TILES = 114, @@ -8729,6 +8754,7 @@ ON = { PRE_LOAD_JOURNAL_CHAPTER = 138, PRE_LOAD_LEVEL_FILES = 109, PRE_LOAD_SCREEN = 135, + PRE_PROCESS_INPUT = 153, PRE_SET_FEAT = 141, PRE_UPDATE = 142, PROLOGUE = 2, @@ -9150,6 +9176,101 @@ QUEST_FLAG = { WADDLER_AGGROED = 10 } ---@alias QUEST_FLAG integer +RAW_KEY = { + ["0"] = 65, + ["1"] = 66, + ["2"] = 67, + ["3"] = 68, + ["4"] = 69, + ["5"] = 70, + ["6"] = 71, + ["7"] = 72, + ["8"] = 73, + ["9"] = 74, + A = 9, + ADD = 86, + ALT = 37, + B = 10, + BACKSPACE = 40, + C = 11, + COMMA = 93, + CTRL = 33, + D = 12, + DECIMAL = 90, + DELETE = 104, + DIVIDE = 88, + DOWN = 1, + E = 13, + END = 106, + ESCAPE = 4, + F = 14, + F1 = 41, + F2 = 42, + F3 = 43, + F4 = 44, + F5 = 45, + F6 = 46, + F7 = 47, + F8 = 48, + F9 = 49, + F10 = 50, + F11 = 51, + F12 = 52, + G = 15, + H = 16, + HOME = 108, + I = 17, + INSERT = 103, + J = 18, + K = 19, + L = 20, + LALT = 37, + LCONTROL = 33, + LEFT = 2, + LSHIFT = 35, + M = 21, + MINUS = 92, + MULTIPLY = 87, + N = 22, + NUMPAD0 = 75, + NUMPAD1 = 76, + NUMPAD2 = 77, + NUMPAD3 = 78, + NUMPAD4 = 79, + NUMPAD5 = 80, + NUMPAD6 = 81, + NUMPAD7 = 82, + NUMPAD8 = 83, + NUMPAD9 = 84, + NUMPADENTER = 110, + O = 23, + P = 24, + PERIOD = 94, + PGDN = 105, + PGUP = 107, + PLUS = 98, + Q = 25, + R = 26, + RALT = 38, + RCONTROL = 34, + RETURN = 5, + RIGHT = 3, + RSHIFT = 36, + S = 27, + SHIFT = 35, + SPACE = 39, + SUBTRACT = 85, + T = 28, + TAB = 6, + U = 29, + UP = 0, + V = 30, + W = 31, + X = 32, + Y = 33, + Z = 34 +} +---@alias RAW_KEY integer RECURSIVE_MODE = { EXCLUSIVE = 0, INCLUSIVE = 1, diff --git a/docs/src/includes/_types.md b/docs/src/includes/_types.md index fa3eeb2e4..e7f05949a 100644 --- a/docs/src/includes/_types.md +++ b/docs/src/includes/_types.md @@ -1003,7 +1003,7 @@ tuple<float, float> | [split()](https://github.com/spelunky-fyi/overlunky/ Type | Name | Description ---- | ---- | ----------- -array<[ControllerButton](#ControllerButton), 16> | [buttons](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=buttons) | +array<[ControllerButton](#ControllerButton), 16> | [buttons](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=buttons) | Zero-based indexing, i.e. use [PlayerSlot](#PlayerSlot).input_mapping_controller directly to index this. ### Gamepad @@ -1096,8 +1096,8 @@ array<[PlayerSlotSettings](#PlayerSlotSettings), MAX_PLAYERS> | [player_se Type | Name | Description ---- | ---- | ----------- -array<[KeyboardKey](#KeyboardKey), 112> | [keyboard](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keyboard) | State of all keyboard buttons in a random game order as usual, most key indexes can be found in [RAW_KEY](#RAW_KEY). -array<[ControllerInput](#ControllerInput), 12> | [controller](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=controller) | State of controller buttons per controller. Zero-based indexing, i.e. use game_props.input_index directly to index this. +array<[KeyboardKey](#KeyboardKey), 112> | [keyboard](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=keyboard) | State of all keyboard buttons in a random game order as usual, most key indexes can be found in [RAW_KEY](#RAW_KEY). Zero-based indexing, i.e. use [PlayerSlot](#PlayerSlot).input_mapping_keyboard directly to index this. +array<[ControllerInput](#ControllerInput), 12> | [controller](https://github.com/spelunky-fyi/overlunky/search?l=Lua&q=controller) | State of controller buttons per controller. Zero-based indexing, i.e. use [GameProps](#GameProps).input_index directly to index this. ## Journal types diff --git a/src/game_api/game_manager.hpp b/src/game_api/game_manager.hpp index 7cfee3a43..4ed2a7c52 100644 --- a/src/game_api/game_manager.hpp +++ b/src/game_api/game_manager.hpp @@ -89,14 +89,15 @@ struct ControllerButton struct ControllerInput { + /// Zero-based indexing, i.e. use PlayerSlot.input_mapping_controller directly to index this. std::array buttons; }; struct RawInput { - /// State of all keyboard buttons in a random game order as usual, most key indexes can be found in RAW_KEY. + /// State of all keyboard buttons in a random game order as usual, most key indexes can be found in RAW_KEY. Zero-based indexing, i.e. use PlayerSlot.input_mapping_keyboard directly to index this. std::array keyboard; - /// State of controller buttons per controller. Zero-based indexing, i.e. use game_props.input_index directly to index this. + /// State of controller buttons per controller. Zero-based indexing, i.e. use GameProps.input_index directly to index this. std::array controller; }; diff --git a/src/game_api/script/usertypes/game_manager_lua.cpp b/src/game_api/script/usertypes/game_manager_lua.cpp index cbb98b7c9..309fae496 100644 --- a/src/game_api/script/usertypes/game_manager_lua.cpp +++ b/src/game_api/script/usertypes/game_manager_lua.cpp @@ -130,7 +130,9 @@ void register_usertypes(sol::state& lua) lua.new_usertype( "RawInput", "keyboard", - &RawInput::keyboard, + //&RawInput::keyboard, + sol::property([](RawInput& r) + { return ZeroIndexArray(r.keyboard) /**/; }), "controller", //&RawInput::controller, sol::property([](RawInput& r) @@ -144,7 +146,9 @@ void register_usertypes(sol::state& lua) lua.new_usertype( "ControllerInput", "buttons", - &ControllerInput::buttons); + //&ControllerInput::buttons, + sol::property([](ControllerInput& r) + { return ZeroIndexArray(r.buttons) /**/; })); lua.new_usertype( "ControllerButton", "down", @@ -155,71 +159,71 @@ void register_usertypes(sol::state& lua) /// Returns RawInput, a game structure for raw keyboard and controller state lua["get_raw_input"] = get_raw_input; - /// Keycodes used specifically in RawInput.keyboard. There are more keys than this though, but I didn't want to figure out the OEM keys. + /// Keycodes used specifically in RawInput.keyboard. There are more keys than this though, but I didn't want to figure out the OEM keys. Because these are physical keys, SHIFT, CTRL and ALT are only mapped to the left keys. lua.create_named_table("RAW_KEY" //, "UP", 1 //, "", ...check__[lua_enums.txt]\[game_data/lua_enums.txt\]... ); - lua["RAW_KEY"]["BACKSPACE"] = 0x29; - lua["RAW_KEY"]["TAB"] = 0x07; - lua["RAW_KEY"]["RETURN"] = 0x06; - lua["RAW_KEY"]["SHIFT"] = 0x24; - lua["RAW_KEY"]["CTRL"] = 0x22; - lua["RAW_KEY"]["ALT"] = 0x26; - lua["RAW_KEY"]["RALT"] = 0x27; - lua["RAW_KEY"]["ESCAPE"] = 0x05; - lua["RAW_KEY"]["SPACE"] = 0x28; - lua["RAW_KEY"]["PGUP"] = 0x6C; - lua["RAW_KEY"]["PGDN"] = 0x6A; - lua["RAW_KEY"]["END"] = 0x6B; - lua["RAW_KEY"]["HOME"] = 0x6D; - lua["RAW_KEY"]["LEFT"] = 0x03; - lua["RAW_KEY"]["UP"] = 0x01; - lua["RAW_KEY"]["RIGHT"] = 0x04; - lua["RAW_KEY"]["DOWN"] = 0x02; - lua["RAW_KEY"]["INSERT"] = 0x68; - lua["RAW_KEY"]["DELETE"] = 0x69; - lua["RAW_KEY"]["NUMPAD0"] = 0x4C; - lua["RAW_KEY"]["NUMPAD1"] = 0x4D; - lua["RAW_KEY"]["NUMPAD2"] = 0x4E; - lua["RAW_KEY"]["NUMPAD3"] = 0x4F; - lua["RAW_KEY"]["NUMPAD4"] = 0x50; - lua["RAW_KEY"]["NUMPAD5"] = 0x51; - lua["RAW_KEY"]["NUMPAD6"] = 0x52; - lua["RAW_KEY"]["NUMPAD7"] = 0x53; - lua["RAW_KEY"]["NUMPAD8"] = 0x54; - lua["RAW_KEY"]["NUMPAD9"] = 0x55; - lua["RAW_KEY"]["MULTIPLY"] = 0x58; - lua["RAW_KEY"]["ADD"] = 0x57; - lua["RAW_KEY"]["SUBTRACT"] = 0x56; - lua["RAW_KEY"]["DECIMAL"] = 0x5B; - lua["RAW_KEY"]["DIVIDE"] = 0x59; - lua["RAW_KEY"]["F1"] = 0x2A; - lua["RAW_KEY"]["F2"] = 0x2B; - lua["RAW_KEY"]["F3"] = 0x2C; - lua["RAW_KEY"]["F4"] = 0x2D; - lua["RAW_KEY"]["F5"] = 0x2E; - lua["RAW_KEY"]["F6"] = 0x2F; - lua["RAW_KEY"]["F7"] = 0x30; - lua["RAW_KEY"]["F8"] = 0x31; - lua["RAW_KEY"]["F9"] = 0x32; - lua["RAW_KEY"]["F10"] = 0x33; - lua["RAW_KEY"]["F11"] = 0x34; - lua["RAW_KEY"]["F12"] = 0x35; - lua["RAW_KEY"]["LSHIFT"] = 0x24; - lua["RAW_KEY"]["RSHIFT"] = 0x25; - lua["RAW_KEY"]["LCONTROL"] = 0x22; - lua["RAW_KEY"]["RCONTROL"] = 0x23; - lua["RAW_KEY"]["LALT"] = 0x26; - lua["RAW_KEY"]["RALT"] = 0x27; - lua["RAW_KEY"]["PLUS"] = 0x63; - lua["RAW_KEY"]["COMMA"] = 0x5E; - lua["RAW_KEY"]["MINUS"] = 0x5D; - lua["RAW_KEY"]["PERIOD"] = 0x5F; + lua["RAW_KEY"]["BACKSPACE"] = 0x28; + lua["RAW_KEY"]["TAB"] = 0x06; + lua["RAW_KEY"]["RETURN"] = 0x05; + lua["RAW_KEY"]["SHIFT"] = 0x23; + lua["RAW_KEY"]["CTRL"] = 0x21; + lua["RAW_KEY"]["ALT"] = 0x25; + lua["RAW_KEY"]["ESCAPE"] = 0x04; + lua["RAW_KEY"]["SPACE"] = 0x27; + lua["RAW_KEY"]["PGUP"] = 0x6B; + lua["RAW_KEY"]["PGDN"] = 0x69; + lua["RAW_KEY"]["END"] = 0x6A; + lua["RAW_KEY"]["HOME"] = 0x6C; + lua["RAW_KEY"]["LEFT"] = 0x02; + lua["RAW_KEY"]["UP"] = 0x00; + lua["RAW_KEY"]["RIGHT"] = 0x03; + lua["RAW_KEY"]["DOWN"] = 0x01; + lua["RAW_KEY"]["INSERT"] = 0x67; + lua["RAW_KEY"]["DELETE"] = 0x68; + lua["RAW_KEY"]["NUMPAD0"] = 0x4B; + lua["RAW_KEY"]["NUMPAD1"] = 0x4C; + lua["RAW_KEY"]["NUMPAD2"] = 0x4D; + lua["RAW_KEY"]["NUMPAD3"] = 0x4E; + lua["RAW_KEY"]["NUMPAD4"] = 0x4F; + lua["RAW_KEY"]["NUMPAD5"] = 0x50; + lua["RAW_KEY"]["NUMPAD6"] = 0x51; + lua["RAW_KEY"]["NUMPAD7"] = 0x52; + lua["RAW_KEY"]["NUMPAD8"] = 0x53; + lua["RAW_KEY"]["NUMPAD9"] = 0x54; + lua["RAW_KEY"]["MULTIPLY"] = 0x57; + lua["RAW_KEY"]["ADD"] = 0x56; + lua["RAW_KEY"]["SUBTRACT"] = 0x55; + lua["RAW_KEY"]["DECIMAL"] = 0x5A; + lua["RAW_KEY"]["DIVIDE"] = 0x58; + lua["RAW_KEY"]["NUMPADENTER"] = 0x6E; + lua["RAW_KEY"]["F1"] = 0x29; + lua["RAW_KEY"]["F2"] = 0x2A; + lua["RAW_KEY"]["F3"] = 0x2B; + lua["RAW_KEY"]["F4"] = 0x2C; + lua["RAW_KEY"]["F5"] = 0x2D; + lua["RAW_KEY"]["F6"] = 0x2E; + lua["RAW_KEY"]["F7"] = 0x2F; + lua["RAW_KEY"]["F8"] = 0x30; + lua["RAW_KEY"]["F9"] = 0x31; + lua["RAW_KEY"]["F10"] = 0x32; + lua["RAW_KEY"]["F11"] = 0x33; + lua["RAW_KEY"]["F12"] = 0x34; + lua["RAW_KEY"]["LSHIFT"] = 0x23; + lua["RAW_KEY"]["RSHIFT"] = 0x24; + lua["RAW_KEY"]["LCONTROL"] = 0x21; + lua["RAW_KEY"]["RCONTROL"] = 0x22; + lua["RAW_KEY"]["LALT"] = 0x25; + lua["RAW_KEY"]["RALT"] = 0x26; + lua["RAW_KEY"]["PLUS"] = 0x62; + lua["RAW_KEY"]["COMMA"] = 0x5D; + lua["RAW_KEY"]["MINUS"] = 0x5C; + lua["RAW_KEY"]["PERIOD"] = 0x5E; for (char c = '0'; c <= '9'; c++) - lua["RAW_KEY"][std::string{c}] = (int)c + 18; + lua["RAW_KEY"][std::string{c}] = (int)c + 17; for (char c = 'A'; c <= 'Z'; c++) - lua["RAW_KEY"][std::string{c}] = (int)c - 57; + lua["RAW_KEY"][std::string{c}] = (int)c - 56; } }; // namespace NGM