From ee431f5fd89604b3831a064552c545b642dc65dd Mon Sep 17 00:00:00 2001 From: Ishaan Bhardwaj Date: Sun, 7 Mar 2021 16:29:01 -0500 Subject: [PATCH 1/3] Revert "(Hopefully) Fixed an obscure bug with SOCD and joystick hats" This did not fix it. This reverts commit 36f2672e06b96b5a5e3050297c398f6686ef9447. --- main.lua | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/main.lua b/main.lua index 64dfbf7..6699f2e 100644 --- a/main.lua +++ b/main.lua @@ -258,27 +258,13 @@ function love.joystickhat(joystick, hat, direction) has_hat = true end if input_pressed then - dir = direction - for i, direction in ipairs{"d", "l", "u", "r"} do - if dir:sub(1, 1) == direction or dir:sub(2) == direction then - scene:onInputPress({input=input_pressed, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) - else - scene:onInputRelease({input=input_pressed, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) - end - end + 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 - dir = direction - for i, direction in ipairs{"d", "l", "u", "r"} do - if dir:sub(1, 1) == direction or dir:sub(2) == direction then - scene:onInputPress({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) - else - scene:onInputRelease({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) - end - end + 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}) From a9bbe4a08d50987dc3350455246e82ea2f700890 Mon Sep 17 00:00:00 2001 From: Ishaan Bhardwaj Date: Sun, 7 Mar 2021 16:42:33 -0500 Subject: [PATCH 2/3] Init hat handling --- main.lua | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/main.lua b/main.lua index 6699f2e..e8acd55 100644 --- a/main.lua +++ b/main.lua @@ -242,6 +242,8 @@ function love.joystickaxis(joystick, axis, value) end end +local last_hat_direction = "" + function love.joystickhat(joystick, hat, direction) local input_pressed = nil local has_hat = false @@ -258,13 +260,31 @@ function love.joystickhat(joystick, hat, direction) has_hat = true end if input_pressed then - scene:onInputPress({input=input_pressed, type="joyhat", name=joystick:getName(), hat=hat, direction=direction}) + for i = 1, #direction do + local char = direction:sub(i, i) + local _, count = last_hat_direction:gsub(char, char) + if count == 0 then + scene:onInputPress({input=input_pressed, type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + else + scene:onInputRelease({input=input_pressed, type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + end + end + last_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}) + for i = 1, #direction do + local char = direction:sub(i, i) + local _, count = last_hat_direction:gsub(char, char) + if count == 0 then + scene:onInputPress({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + else + scene:onInputRelease({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + end + end + last_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}) From 36f5287a393697b2dfac55cd41aeb9842901663c Mon Sep 17 00:00:00 2001 From: Joe Z Date: Sun, 7 Mar 2021 20:43:55 -0500 Subject: [PATCH 3/3] Fixed the hat input mapping. --- main.lua | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/main.lua b/main.lua index e8acd55..d6c3703 100644 --- a/main.lua +++ b/main.lua @@ -243,6 +243,12 @@ function love.joystickaxis(joystick, axis, value) end local last_hat_direction = "" +local directions = { + ["u"] = "up", + ["d"] = "down", + ["l"] = "left", + ["r"] = "right", +} function love.joystickhat(joystick, hat, direction) local input_pressed = nil @@ -264,9 +270,14 @@ function love.joystickhat(joystick, hat, direction) local char = direction:sub(i, i) local _, count = last_hat_direction:gsub(char, char) if count == 0 then - scene:onInputPress({input=input_pressed, type="joyhat", name=joystick:getName(), hat=hat, direction=char}) - else - scene:onInputRelease({input=input_pressed, type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + scene:onInputPress({input=config.input.joysticks[joystick:getName()].hats[hat][char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + end + end + for i = 1, #last_hat_direction do + local char = last_hat_direction:sub(i, i) + local _, count = direction:gsub(char, char) + if count == 0 then + scene:onInputRelease({input=config.input.joysticks[joystick:getName()].hats[hat][char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) end end last_hat_direction = direction @@ -274,14 +285,20 @@ function love.joystickhat(joystick, hat, direction) 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 + last_hat_direction = "" elseif direction ~= "c" then for i = 1, #direction do local char = direction:sub(i, i) local _, count = last_hat_direction:gsub(char, char) if count == 0 then - scene:onInputPress({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=char}) - else - scene:onInputRelease({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + scene:onInputPress({input=directions[char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) + end + end + for i = 1, #last_hat_direction do + local char = last_hat_direction:sub(i, i) + local _, count = direction:gsub(char, char) + if count == 0 then + scene:onInputRelease({input=directions[char], type="joyhat", name=joystick:getName(), hat=hat, direction=char}) end end last_hat_direction = direction @@ -289,6 +306,7 @@ function love.joystickhat(joystick, hat, direction) 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 + last_hat_direction = "" end end