diff --git a/main.lua b/main.lua index 4c390da..f683fe1 100644 --- a/main.lua +++ b/main.lua @@ -46,10 +46,10 @@ function love.load() end --sort mode/rule lists local function padnum(d) return ("%03d%s"):format(#d, d) end - table.sort(game_modes, function(a,b) - return tostring(a.name):gsub("%d+",padnum) < tostring(b.name):gsub("%d+",padnum) end) + table.sort(game_modes, function(a,b) + return tostring(a.name):gsub("%d+",padnum) < tostring(b.name):gsub("%d+",padnum) end) table.sort(rulesets, function(a,b) - return tostring(a.name):gsub("%d+",padnum) < tostring(b.name):gsub("%d+",padnum) end) + return tostring(a.name):gsub("%d+",padnum) < tostring(b.name):gsub("%d+",padnum) end) end @@ -114,120 +114,120 @@ 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 == "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 + -- 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 == "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 else - local input_pressed = nil - if config.input and config.input.keys then - input_pressed = config.input.keys[scancode] - end + local input_pressed = nil + if config.input and config.input.keys then + input_pressed = config.input.keys[scancode] + end scene:onInputPress({input=input_pressed, type="key", key=key, scancode=scancode}) end 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 - 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 + -- 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 + 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 else - local input_released = nil - if config.input and config.input.keys then - input_released = config.input.keys[scancode] - end + local input_released = nil + if config.input and config.input.keys then + input_released = config.input.keys[scancode] + end scene:onInputRelease({input=input_released, type="key", key=key, scancode=scancode}) end end function love.joystickpressed(joystick, button) - local input_pressed = nil - if - config.input and - config.input.joysticks and - config.input.joysticks[joystick:getName()] and - config.input.joysticks[joystick:getName()].buttons - then - input_pressed = config.input.joysticks[joystick:getName()].buttons[button] - end - scene:onInputPress({input=input_pressed, type="joybutton", name=joystick:getName(), button=button}) + local input_pressed = nil + if + config.input and + config.input.joysticks and + config.input.joysticks[joystick:getName()] and + config.input.joysticks[joystick:getName()].buttons + then + input_pressed = config.input.joysticks[joystick:getName()].buttons[button] + end + scene:onInputPress({input=input_pressed, type="joybutton", name=joystick:getName(), button=button}) end function love.joystickreleased(joystick, button) - local input_released = nil - if - config.input and - config.input.joysticks and - config.input.joysticks[joystick:getName()] and - config.input.joysticks[joystick:getName()].buttons - then - input_released = config.input.joysticks[joystick:getName()].buttons[button] - end - scene:onInputRelease({input=input_released, type="joybutton", name=joystick:getName(), button=button}) + local input_released = nil + if + config.input and + config.input.joysticks and + config.input.joysticks[joystick:getName()] and + config.input.joysticks[joystick:getName()].buttons + then + input_released = config.input.joysticks[joystick:getName()].buttons[button] + end + scene:onInputRelease({input=input_released, type="joybutton", name=joystick:getName(), button=button}) end function love.joystickaxis(joystick, axis, value) - local input_pressed = nil - local positive_released = nil - local negative_released = nil - if - config.input and - config.input.joysticks and - config.input.joysticks[joystick:getName()] and - config.input.joysticks[joystick:getName()].axes and - config.input.joysticks[joystick:getName()].axes[axis] - then - if math.abs(value) >= 0.5 then - input_pressed = config.input.joysticks[joystick:getName()].axes[axis][value >= 0.5 and "positive" or "negative"] - end - positive_released = config.input.joysticks[joystick:getName()].axes[axis].positive - negative_released = config.input.joysticks[joystick:getName()].axes[axis].negative - end - if math.abs(value) >= 0.5 then - scene:onInputPress({input=input_pressed, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) - else - scene:onInputRelease({input=positive_released, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) - scene:onInputRelease({input=negative_released, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) - end + local input_pressed = nil + local positive_released = nil + local negative_released = nil + if + config.input and + config.input.joysticks and + config.input.joysticks[joystick:getName()] and + config.input.joysticks[joystick:getName()].axes and + config.input.joysticks[joystick:getName()].axes[axis] + then + if math.abs(value) >= 0.5 then + input_pressed = config.input.joysticks[joystick:getName()].axes[axis][value >= 0.5 and "positive" or "negative"] + end + positive_released = config.input.joysticks[joystick:getName()].axes[axis].positive + negative_released = config.input.joysticks[joystick:getName()].axes[axis].negative + end + if math.abs(value) >= 0.5 then + scene:onInputPress({input=input_pressed, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) + else + scene:onInputRelease({input=positive_released, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) + scene:onInputRelease({input=negative_released, type="joyaxis", name=joystick:getName(), axis=axis, value=value}) + end end function love.joystickhat(joystick, hat, direction) - local input_pressed = nil - local has_hat = false - if - config.input and - config.input.joysticks and - config.input.joysticks[joystick:getName()] and - config.input.joysticks[joystick:getName()].hats and - config.input.joysticks[joystick:getName()].hats[hat] - then - if direction ~= "c" then - input_pressed = config.input.joysticks[joystick:getName()].hats[hat][direction] - end - has_hat = true - end - if input_pressed then - scene:onInputPress({input=input_pressed, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) - elseif has_hat then - for i, direction in ipairs{"d", "l", "ld", "lu", "r", "rd", "ru", "u"} do - scene:onInputRelease({input=config.input.joysticks[joystick:getName()].hats[hat][direction], type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) - end - elseif direction ~= "c" then - scene:onInputPress({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) - else - for i, direction in ipairs{"d", "l", "ld", "lu", "r", "rd", "ru", "u"} do - scene:onInputRelease({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) - end - end + local input_pressed = nil + local has_hat = false + if + config.input and + config.input.joysticks and + config.input.joysticks[joystick:getName()] and + config.input.joysticks[joystick:getName()].hats and + config.input.joysticks[joystick:getName()].hats[hat] + then + if direction ~= "c" then + input_pressed = config.input.joysticks[joystick:getName()].hats[hat][direction] + end + has_hat = true + end + if input_pressed then + scene:onInputPress({input=input_pressed, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) + elseif has_hat then + for i, direction in ipairs{"d", "l", "ld", "lu", "r", "rd", "ru", "u"} do + scene:onInputRelease({input=config.input.joysticks[joystick:getName()].hats[hat][direction], type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) + end + elseif direction ~= "c" then + scene:onInputPress({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) + else + for i, direction in ipairs{"d", "l", "ld", "lu", "r", "rd", "ru", "u"} do + scene:onInputRelease({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) + end + end end function love.focus(f) diff --git a/scene/game.lua b/scene/game.lua index f896d60..416045a 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -2,23 +2,23 @@ local GameScene = Scene:extend() require 'load.save' function GameScene:new(game_mode, ruleset) - self.retry_mode = game_mode - self.retry_ruleset = ruleset + self.retry_mode = game_mode + self.retry_ruleset = ruleset self.game = game_mode() self.ruleset = ruleset() self.game:initialize(self.ruleset) - self.inputs = { - left=false, - right=false, - up=false, - down=false, - rotate_left=false, - rotate_left2=false, - rotate_right=false, - rotate_right2=false, - rotate_180=false, - hold=false, - } + self.inputs = { + left=false, + right=false, + up=false, + down=false, + rotate_left=false, + rotate_left2=false, + rotate_right=false, + rotate_right2=false, + rotate_180=false, + hold=false, + } DiscordRPC:update({ details = self.game.rpc_details, state = self.game.name, @@ -27,10 +27,10 @@ end function GameScene:update() if love.window.hasFocus() then - local inputs = {} - for input, value in pairs(self.inputs) do - inputs[input] = value - end + local inputs = {} + for input, value in pairs(self.inputs) do + inputs[input] = value + end self.game:update(inputs, self.ruleset) end @@ -67,24 +67,24 @@ function GameScene:render() end function GameScene:onInputPress(e) - if self.game.completed and (e.input == "menu_decide" or e.input == "menu_back") then - highscore_entry = self.game:getHighscoreData() - highscore_hash = self.game.hash .. "-" .. self.ruleset.hash - submitHighscore(highscore_hash, highscore_entry) - scene = ModeSelectScene() - elseif e.input == "retry" then - scene = GameScene(self.retry_mode, self.retry_ruleset) - elseif e.input == "menu_back" then - scene = ModeSelectScene() - elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then - self.inputs[e.input] = true - end + if self.game.completed and (e.input == "menu_decide" or e.input == "menu_back") then + highscore_entry = self.game:getHighscoreData() + highscore_hash = self.game.hash .. "-" .. self.ruleset.hash + submitHighscore(highscore_hash, highscore_entry) + scene = ModeSelectScene() + elseif e.input == "retry" then + scene = GameScene(self.retry_mode, self.retry_ruleset) + elseif e.input == "menu_back" then + scene = ModeSelectScene() + elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then + self.inputs[e.input] = true + end end function GameScene:onInputRelease(e) - if e.input and string.sub(e.input, 1, 5) ~= "menu_" then - self.inputs[e.input] = false - end + if e.input and string.sub(e.input, 1, 5) ~= "menu_" then + self.inputs[e.input] = false + end end function submitHighscore(hash, data) diff --git a/scene/game_config.lua b/scene/game_config.lua index 0fa2585..beef971 100644 --- a/scene/game_config.lua +++ b/scene/game_config.lua @@ -5,10 +5,10 @@ ConfigScene.title = "Game Settings" require 'load.save' ConfigScene.options = { - -- this serves as reference to what the options' values mean i guess? - {"manlock", "Manual locking",{"Per ruleset","Per gamemode","Harddrop", "Softdrop"}}, - {"piece_colour", "Piece Colours", {"Per ruleset","Arika" ,"TTC"}}, - {"world_reverse","World Reverse", {"No" ,"SRS only" ,"Always"}}, + -- this serves as reference to what the options' values mean i guess? + {"manlock", "Manual locking",{"Per ruleset","Per gamemode","Harddrop", "Softdrop"}}, + {"piece_colour", "Piece Colours", {"Per ruleset","Arika" ,"TTC"}}, + {"world_reverse","World Reverse", {"No" ,"SRS only" ,"Always"}}, } local optioncount = #ConfigScene.options diff --git a/scene/input_config.lua b/scene/input_config.lua index 1b4ae0f..16efcad 100644 --- a/scene/input_config.lua +++ b/scene/input_config.lua @@ -5,8 +5,8 @@ ConfigScene.title = "Input Config" require 'load.save' local configurable_inputs = { - "menu_decide", - "menu_back", + "menu_decide", + "menu_back", "left", "right", "up", @@ -21,17 +21,17 @@ local configurable_inputs = { } local function newSetInputs() - local set_inputs = {} - for i, input in ipairs(configurable_inputs) do - set_inputs[input] = false - end - return set_inputs + local set_inputs = {} + for i, input in ipairs(configurable_inputs) do + set_inputs[input] = false + end + return set_inputs end function ConfigScene:new() self.input_state = 1 - self.set_inputs = newSetInputs() - self.new_input = {} + self.set_inputs = newSetInputs() + self.new_input = {} DiscordRPC:update({ details = "In menus", @@ -53,116 +53,116 @@ function ConfigScene:render() love.graphics.setFont(font_3x5_2) for i, input in ipairs(configurable_inputs) do love.graphics.printf(input, 40, 50 + i * 20, 200, "left") - if self.set_inputs[input] then - love.graphics.printf(self.set_inputs[input], 240, 50 + i * 20, 300, "left") - end - end + if self.set_inputs[input] then + love.graphics.printf(self.set_inputs[input], 240, 50 + i * 20, 300, "left") + end + end if self.input_state > table.getn(configurable_inputs) then 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("enter, delete, backspace, tab, arrows, and escape can't be changed", 0, 20) end end local function addJoystick(input, name) - if not input.joysticks then - input.joysticks = {} - end - if not input.joysticks[name] then - input.joysticks[name] = {} - end + if not input.joysticks then + input.joysticks = {} + end + if not input.joysticks[name] then + input.joysticks[name] = {} + end end function ConfigScene:onInputPress(e) - if e.type == "key" then - -- enter, delete, backspace, tab, arrows, and escape are reserved and can't be remapped - if e.scancode == "escape" and config.input then - scene = TitleScene() - elseif self.input_state > table.getn(configurable_inputs) then - if e.scancode == "return" then - -- save new input, then load next scene - config.input = self.new_input - saveConfig() - scene = TitleScene() - elseif e.scancode == "delete" or e.scancode == "backspace" then - -- retry - 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 - end - end - elseif string.sub(e.type, 1, 3) == "joy" then - if self.input_state <= table.getn(configurable_inputs) then - if e.type == "joybutton" then - addJoystick(self.new_input, e.name) - if not self.new_input.joysticks[e.name].buttons then - self.new_input.joysticks[e.name].buttons = {} - end - self.set_inputs[configurable_inputs[self.input_state]] = - "jbtn " .. - e.button .. - " " .. string.sub(e.name, 1, 10) .. (string.len(e.name) > 10 and "..." or "") - self.new_input.joysticks[e.name].buttons[e.button] = configurable_inputs[self.input_state] - self.input_state = self.input_state + 1 - elseif e.type == "joyaxis" then - if math.abs(e.value) >= 0.5 then - addJoystick(self.new_input, e.name) - if not self.new_input.joysticks[e.name].axes then - self.new_input.joysticks[e.name].axes = {} - end - if not self.new_input.joysticks[e.name].axes[e.axis] then - self.new_input.joysticks[e.name].axes[e.axis] = {} - end - self.set_inputs[configurable_inputs[self.input_state]] = - "jaxis " .. - (e.value >= 0.5 and "+" or "-") .. e.axis .. - " " .. string.sub(e.name, 1, 10) .. (string.len(e.name) > 10 and "..." or "") - self.new_input.joysticks[e.name].axes[e.axis][e.value >= 0.5 and "positive" or "negative"] = configurable_inputs[self.input_state] - self.input_state = self.input_state + 1 - end - elseif e.type == "joyhat" then - if e.direction ~= "c" then - addJoystick(self.new_input, e.name) - if not self.new_input.joysticks[e.name].hats then - self.new_input.joysticks[e.name].hats = {} - end - if not self.new_input.joysticks[e.name].hats[e.hat] then - self.new_input.joysticks[e.name].hats[e.hat] = {} - end - self.set_inputs[configurable_inputs[self.input_state]] = - "jhat " .. - e.hat .. " " .. e.direction .. - " " .. string.sub(e.name, 1, 10) .. (string.len(e.name) > 10 and "..." or "") - self.new_input.joysticks[e.name].hats[e.hat][e.direction] = configurable_inputs[self.input_state] - self.input_state = self.input_state + 1 - end - end - end - end + if e.type == "key" then + -- enter, delete, backspace, tab, arrows, and escape are reserved and can't be remapped + if e.scancode == "escape" and config.input then + scene = TitleScene() + elseif self.input_state > table.getn(configurable_inputs) then + if e.scancode == "return" then + -- save new input, then load next scene + config.input = self.new_input + saveConfig() + scene = TitleScene() + elseif e.scancode == "delete" or e.scancode == "backspace" then + -- retry + 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 + end + end + elseif string.sub(e.type, 1, 3) == "joy" then + if self.input_state <= table.getn(configurable_inputs) then + if e.type == "joybutton" then + addJoystick(self.new_input, e.name) + if not self.new_input.joysticks[e.name].buttons then + self.new_input.joysticks[e.name].buttons = {} + end + self.set_inputs[configurable_inputs[self.input_state]] = + "jbtn " .. + e.button .. + " " .. string.sub(e.name, 1, 10) .. (string.len(e.name) > 10 and "..." or "") + self.new_input.joysticks[e.name].buttons[e.button] = configurable_inputs[self.input_state] + self.input_state = self.input_state + 1 + elseif e.type == "joyaxis" then + if math.abs(e.value) >= 0.5 then + addJoystick(self.new_input, e.name) + if not self.new_input.joysticks[e.name].axes then + self.new_input.joysticks[e.name].axes = {} + end + if not self.new_input.joysticks[e.name].axes[e.axis] then + self.new_input.joysticks[e.name].axes[e.axis] = {} + end + self.set_inputs[configurable_inputs[self.input_state]] = + "jaxis " .. + (e.value >= 0.5 and "+" or "-") .. e.axis .. + " " .. string.sub(e.name, 1, 10) .. (string.len(e.name) > 10 and "..." or "") + self.new_input.joysticks[e.name].axes[e.axis][e.value >= 0.5 and "positive" or "negative"] = configurable_inputs[self.input_state] + self.input_state = self.input_state + 1 + end + elseif e.type == "joyhat" then + if e.direction ~= "c" then + addJoystick(self.new_input, e.name) + if not self.new_input.joysticks[e.name].hats then + self.new_input.joysticks[e.name].hats = {} + end + if not self.new_input.joysticks[e.name].hats[e.hat] then + self.new_input.joysticks[e.name].hats[e.hat] = {} + end + self.set_inputs[configurable_inputs[self.input_state]] = + "jhat " .. + e.hat .. " " .. e.direction .. + " " .. string.sub(e.name, 1, 10) .. (string.len(e.name) > 10 and "..." or "") + self.new_input.joysticks[e.name].hats[e.hat][e.direction] = configurable_inputs[self.input_state] + self.input_state = self.input_state + 1 + end + end + end + end end return ConfigScene diff --git a/scene/title.lua b/scene/title.lua index b688eb7..0a7dc52 100644 --- a/scene/title.lua +++ b/scene/title.lua @@ -26,7 +26,7 @@ function TitleScene:new() self.main_menu_state = 1 DiscordRPC:update({ details = "In menus", - state = mainmenuidle[math.random(#mainmenuidle)], + state = mainmenuidle[math.random(#mainmenuidle)], }) end