mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 17:09:02 -06:00
Fixed the hat input mapping.
This commit is contained in:
parent
a9bbe4a08d
commit
36f5287a39
30
main.lua
30
main.lua
@ -243,6 +243,12 @@ function love.joystickaxis(joystick, axis, value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local last_hat_direction = ""
|
local last_hat_direction = ""
|
||||||
|
local directions = {
|
||||||
|
["u"] = "up",
|
||||||
|
["d"] = "down",
|
||||||
|
["l"] = "left",
|
||||||
|
["r"] = "right",
|
||||||
|
}
|
||||||
|
|
||||||
function love.joystickhat(joystick, hat, direction)
|
function love.joystickhat(joystick, hat, direction)
|
||||||
local input_pressed = nil
|
local input_pressed = nil
|
||||||
@ -264,9 +270,14 @@ function love.joystickhat(joystick, hat, direction)
|
|||||||
local char = direction:sub(i, i)
|
local char = direction:sub(i, i)
|
||||||
local _, count = last_hat_direction:gsub(char, char)
|
local _, count = last_hat_direction:gsub(char, char)
|
||||||
if count == 0 then
|
if count == 0 then
|
||||||
scene:onInputPress({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})
|
||||||
else
|
end
|
||||||
scene:onInputRelease({input=input_pressed, type="joyhat", name=joystick:getName(), hat=hat, direction=char})
|
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
|
||||||
end
|
end
|
||||||
last_hat_direction = direction
|
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
|
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})
|
scene:onInputRelease({input=config.input.joysticks[joystick:getName()].hats[hat][direction], type="joyhat", name=joystick:getName(), hat=hat, direction=direction})
|
||||||
end
|
end
|
||||||
|
last_hat_direction = ""
|
||||||
elseif direction ~= "c" then
|
elseif direction ~= "c" then
|
||||||
for i = 1, #direction do
|
for i = 1, #direction do
|
||||||
local char = direction:sub(i, i)
|
local char = direction:sub(i, i)
|
||||||
local _, count = last_hat_direction:gsub(char, char)
|
local _, count = last_hat_direction:gsub(char, char)
|
||||||
if count == 0 then
|
if count == 0 then
|
||||||
scene:onInputPress({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})
|
||||||
else
|
end
|
||||||
scene:onInputRelease({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=char})
|
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
|
||||||
end
|
end
|
||||||
last_hat_direction = direction
|
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
|
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})
|
scene:onInputRelease({input=nil, type="joyhat", name=joystick:getName(), hat=hat, direction=direction})
|
||||||
end
|
end
|
||||||
|
last_hat_direction = ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user