diff --git a/main.lua b/main.lua index f683fe1..9243edc 100644 --- a/main.lua +++ b/main.lua @@ -114,14 +114,15 @@ function love.keypressed(key, scancode) if scancode == "f4" then config["fullscreen"] = not config["fullscreen"] love.window.setFullscreen(config["fullscreen"]) - -- reserved keys, so the user can always get back to configure input - elseif scancode == "return" then - scene:onInputPress({input="menu_decide", type="key", key=key, scancode=scancode}) + elseif scancode == "f2" and scene.title ~= "Input Config" and scene.title ~= "Game" then + scene = InputConfigScene() + -- function keys are reserved + elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f[1-9][0-9]+$") then + return + -- escape is reserved for menu_back elseif scancode == "escape" then scene:onInputPress({input="menu_back", type="key", key=key, scancode=scancode}) - elseif scancode == "left" or scancode == "right" or scancode == "up" or scancode == "down" then - scene:onInputPress({input=scancode, type="key", key=key, scancode=scancode}) - -- other keys can be configured + -- pass any other key to the scene, with its configured mapping else local input_pressed = nil if config.input and config.input.keys then @@ -132,14 +133,13 @@ function love.keypressed(key, scancode) end function love.keyreleased(key, scancode) - -- reserved keys, so the user can always get back to configure input - if scancode == "return" then - scene:onInputRelease({input="menu_decide", type="key", key=key, scancode=scancode}) - elseif scancode == "escape" then + -- escape is reserved for menu_back + if scancode == "escape" then scene:onInputRelease({input="menu_back", type="key", key=key, scancode=scancode}) - elseif scancode == "left" or scancode == "right" or scancode == "up" or scancode == "down" then - scene:onInputRelease({input=scancode, type="key", key=key, scancode=scancode}) - -- other keys can be configured + -- function keys are reserved + elseif string.match(scancode, "^f[1-9]$") or string.match(scancode, "^f[1-9][0-9]+$") then + return + -- handle all other keys; tab is reserved, but the input config scene keeps it from getting configured as a game input, so pass tab to the scene here else local input_released = nil if config.input and config.input.keys then diff --git a/scene/game.lua b/scene/game.lua index 17e5a11..05b5ff3 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -1,4 +1,7 @@ local GameScene = Scene:extend() + +GameScene.title = "Game" + require 'load.save' function GameScene:new(game_mode, ruleset) diff --git a/scene/input_config.lua b/scene/input_config.lua index 16efcad..a389382 100644 --- a/scene/input_config.lua +++ b/scene/input_config.lua @@ -61,7 +61,7 @@ function ConfigScene:render() love.graphics.print("press enter to confirm, delete/backspace to retry" .. (config.input and ", escape to cancel" or "")) else love.graphics.print("press key or joystick input for " .. configurable_inputs[self.input_state] .. ", tab to skip" .. (config.input and ", escape to cancel" or ""), 0, 0) - love.graphics.print("enter, delete, backspace, tab, arrows, and escape can't be changed", 0, 20) + love.graphics.print("function keys (F1, F2, etc.), escape, and tab can't be changed", 0, 20) end end @@ -76,8 +76,9 @@ end function ConfigScene:onInputPress(e) if e.type == "key" then - -- enter, delete, backspace, tab, arrows, and escape are reserved and can't be remapped + -- function keys, escape, and tab are reserved and can't be remapped if e.scancode == "escape" and config.input then + -- cancel only if there was an input config already scene = TitleScene() elseif self.input_state > table.getn(configurable_inputs) then if e.scancode == "return" then @@ -90,30 +91,18 @@ function ConfigScene:onInputPress(e) self.input_state = 1 self.set_inputs = newSetInputs() self.new_input = {} - elseif e.scancode == "escape" and config.input then - -- cancel only if there was an input config already - scene = TitleScene() end - elseif - e.scancode ~= "delete" and - e.scancode ~= "backspace" and - e.scancode ~= "return" and - e.scancode ~= "left" and - e.scancode ~= "right" and - e.scancode ~= "up" and - e.scancode ~= "down" - then - if e.scancode == "tab" then - self.set_inputs[configurable_inputs[self.input_state]] = "skipped" - self.input_state = self.input_state + 1 - else - if not self.new_input.keys then - self.new_input.keys = {} - end - self.set_inputs[configurable_inputs[self.input_state]] = "key " .. love.keyboard.getKeyFromScancode(e.scancode) .. " (" .. e.scancode .. ")" - self.new_input.keys[e.scancode] = configurable_inputs[self.input_state] - self.input_state = self.input_state + 1 + elseif e.scancode == "tab" then + self.set_inputs[configurable_inputs[self.input_state]] = "skipped" + self.input_state = self.input_state + 1 + elseif e.scancode ~= "escape" then + -- all other keys can be configured + if not self.new_input.keys then + self.new_input.keys = {} end + self.set_inputs[configurable_inputs[self.input_state]] = "key " .. love.keyboard.getKeyFromScancode(e.scancode) .. " (" .. e.scancode .. ")" + self.new_input.keys[e.scancode] = configurable_inputs[self.input_state] + self.input_state = self.input_state + 1 end elseif string.sub(e.type, 1, 3) == "joy" then if self.input_state <= table.getn(configurable_inputs) then