mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-27 17:19:31 +00:00
Fix triggeringTrigger, improve gamepad handling
This commit is contained in:
parent
d85424d866
commit
1ec81f2ebb
2 changed files with 94 additions and 46 deletions
|
|
@ -101,27 +101,39 @@ input.basicButtonDetector = function(id)
|
||||||
end
|
end
|
||||||
-- Gamepad button
|
-- Gamepad button
|
||||||
elseif id:match("^gamepad%.button%.") then
|
elseif id:match("^gamepad%.button%.") then
|
||||||
local gid, key = id:match("^gamepad%.button%.(.+)%.(.+)$")
|
local gidkey = id:match("^gamepad%.button%.(.+)$")
|
||||||
gid = tonumber(gid)
|
local key = gidkey:match("([^.]+)$")
|
||||||
|
local gid = tonumber(gidkey:match("^(.+)%..+$"))
|
||||||
|
local gamepad
|
||||||
return function()
|
return function()
|
||||||
local gamepad
|
if not gamepad or not gamepad:isConnected() then
|
||||||
for _,j in ipairs(love.joystick.getJoysticks()) do
|
for _, j in ipairs(love.joystick.getJoysticks()) do
|
||||||
if j:getID() == gid then gamepad = j end
|
if (gid and j:getID() == gid) or j:isGamepad() then
|
||||||
|
gamepad = j
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return gamepad and gamepad:isGamepadDown(key)
|
return gamepad and gamepad:isGamepadDown(key)
|
||||||
end
|
end
|
||||||
-- Gamepad axis
|
-- Gamepad axis
|
||||||
elseif id:match("^gamepad%.axis%.") then
|
elseif id:match("^gamepad%.axis%.") then
|
||||||
local gid, axis, threshold = id:match("^gamepad%.axis%.(.+)%.(.+)%%(.+)$")
|
local gidaxis, threshold = id:match("^gamepad%.axis%.(.+)%%(.+)$")
|
||||||
if not gid then gid, axis = id:match("^gamepad%.axis%.(.+)%.(.+)$") end -- no threshold (=0.5)
|
if not gidaxis then gidaxis = id:match("^gamepad%.axis%.(.+)$") end -- no threshold (=0.5)
|
||||||
gid = tonumber(gid)
|
local axis = gidaxis:match("([^.]+)$")
|
||||||
|
local gid = tonumber(gidaxis:match("^(.+)%..+$"))
|
||||||
threshold = tonumber(threshold) or 0.5
|
threshold = tonumber(threshold) or 0.5
|
||||||
|
local gamepad
|
||||||
return function()
|
return function()
|
||||||
local gamepad
|
if not gamepad or not gamepad:isConnected() then
|
||||||
for _,j in ipairs(love.joystick.getJoysticks()) do
|
for _, j in ipairs(love.joystick.getJoysticks()) do
|
||||||
if j:getID() == gid then gamepad = j end
|
if (gid and j:getID() == gid) or j:isGamepad() then
|
||||||
|
gamepad = j
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if not gamepad then
|
if not gamepad or not gamepad:isConnected() then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
local val = gamepad:getGamepadAxis(axis)
|
local val = gamepad:getGamepadAxis(axis)
|
||||||
|
|
@ -167,16 +179,22 @@ input.basicAxisDetector = function(id)
|
||||||
end
|
end
|
||||||
-- Gamepad axis
|
-- Gamepad axis
|
||||||
elseif id:match("^gamepad%.axis%.") then
|
elseif id:match("^gamepad%.axis%.") then
|
||||||
local gid, axis, threshold = id:match("^gamepad%.axis%.(.+)%.(.+)%%(.+)$")
|
local gidaxis, threshold = id:match("^gamepad%.axis%.(.+)%%(.+)$")
|
||||||
if not gid then gid, axis = id:match("^gamepad%.axis%.(.+)%.(.+)$") end -- no threshold (=0.1)
|
if not gidaxis then gidaxis = id:match("^gamepad%.axis%.(.+)$") end -- no threshold (=0.1)
|
||||||
gid = tonumber(gid)
|
local axis = gidaxis:match("([^.]+)$")
|
||||||
|
local gid = tonumber(gidaxis:match("^(.+)%..+$"))
|
||||||
threshold = tonumber(threshold) or 0.1
|
threshold = tonumber(threshold) or 0.1
|
||||||
|
local gamepad
|
||||||
return function()
|
return function()
|
||||||
local gamepad
|
if not gamepad or not gamepad:isConnected() then
|
||||||
for _,j in ipairs(love.joystick.getJoysticks()) do
|
for _, j in ipairs(love.joystick.getJoysticks()) do
|
||||||
if j:getID() == gid then gamepad = j end
|
if (gid and j:getID() == gid) or j:isGamepad() then
|
||||||
|
gamepad = j
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if not gamepad then
|
if not gamepad or not gamepad:isConnected() then
|
||||||
return 0
|
return 0
|
||||||
else
|
else
|
||||||
local val = gamepad:getGamepadAxis(axis)
|
local val = gamepad:getGamepadAxis(axis)
|
||||||
|
|
@ -231,24 +249,42 @@ input.buttonName = function(...)
|
||||||
table.insert(ret, "Mouse "..key)
|
table.insert(ret, "Mouse "..key)
|
||||||
-- Gamepad button
|
-- Gamepad button
|
||||||
elseif id:match("^gamepad%.button%.") then
|
elseif id:match("^gamepad%.button%.") then
|
||||||
local gid, key = id:match("^gamepad%.button%.(.+)%.(.+)$")
|
local gidkey = id:match("^gamepad%.button%.(.+)$")
|
||||||
table.insert(ret, "Gamepad "..gid.." button "..key)
|
local key = gidkey:match("([^.]+)$")
|
||||||
|
local gid = tonumber(gidkey:match("^(.+)%..+$"))
|
||||||
|
if gid then
|
||||||
|
table.insert(ret, "Gamepad "..gid.." button "..key)
|
||||||
|
else
|
||||||
|
table.insert(ret, "Gamepad button "..key)
|
||||||
|
end
|
||||||
-- Gamepad axis
|
-- Gamepad axis
|
||||||
elseif id:match("^gamepad%.axis%.") then
|
elseif id:match("^gamepad%.axis%.") then
|
||||||
local gid, axis, threshold = id:match("^gamepad%.axis%.(.+)%.(.+)%%(.+)$")
|
local gidaxis, threshold = id:match("^gamepad%.axis%.(.+)%%(.+)$")
|
||||||
if not gid then gid, axis = id:match("^gamepad%.axis%.(.+)%.(.+)$") end -- no threshold (=0)
|
if not gidaxis then gidaxis = id:match("^gamepad%.axis%.(.+)$") end -- no threshold (=0.5)
|
||||||
threshold = tonumber(threshold) or 0.1
|
local axis = gidaxis:match("([^.]+)$")
|
||||||
if axis == "rightx" then
|
local gid = tonumber(gidaxis:match("^(.+)%..+$"))
|
||||||
table.insert(ret, ("Gamepad %s right stick %s (deadzone %s%%)"):format(gid, threshold >= 0 and "right" or "left", math.abs(threshold*100)))
|
threshold = tonumber(threshold) or 0.5
|
||||||
elseif axis == "righty" then
|
|
||||||
table.insert(ret, ("Gamepad %s right stick %s (deadzone %s%%)"):format(gid, threshold >= 0 and "down" or "up", math.abs(threshold*100)))
|
local str
|
||||||
elseif axis == "leftx" then
|
if gid then
|
||||||
table.insert(ret, ("Gamepad %s left stick %s (deadzone %s%%)"):format(gid, threshold >= 0 and "right" or "left", math.abs(threshold*100)))
|
str = "Gamepad "..gid
|
||||||
elseif axis == "lefty" then
|
|
||||||
table.insert(ret, ("Gamepad %s left stick %s (deadzone %s%%)"):format(gid, threshold >= 0 and "down" or "up", math.abs(threshold*100)))
|
|
||||||
else
|
else
|
||||||
table.insert(ret, ("Gamepad %s axis %s (deadzone %s%%)"):format(gid, axis, math.abs(threshold*100)))
|
str = "Gamepad"
|
||||||
end
|
end
|
||||||
|
if axis == "rightx" then
|
||||||
|
str = str .. (" right stick %s (deadzone %s%%)"):format(threshold >= 0 and "right" or "left")
|
||||||
|
elseif axis == "righty" then
|
||||||
|
str = str .. (" right stick %s (deadzone %s%%)"):format(threshold >= 0 and "down" or "up")
|
||||||
|
elseif axis == "leftx" then
|
||||||
|
str = str .. (" left stick %s (deadzone %s%%)"):format(threshold >= 0 and "right" or "left")
|
||||||
|
elseif axis == "lefty" then
|
||||||
|
str = str .. (" left stick %s (deadzone %s%%)"):format(threshold >= 0 and "down" or "up")
|
||||||
|
else
|
||||||
|
str = str .. (" axis %s (deadzone %s%%)"):format(axis, math.abs(threshold*100))
|
||||||
|
end
|
||||||
|
str = str .. " (deadzone %s%%)"):format(math.abs(threshold*100))
|
||||||
|
|
||||||
|
table.insert(ret, str)
|
||||||
else
|
else
|
||||||
table.insert(ret, id)
|
table.insert(ret, id)
|
||||||
end
|
end
|
||||||
|
|
@ -277,20 +313,32 @@ input.axisName = function(...)
|
||||||
table.insert(ret, ("Mouse %s position (threshold %s%%)"):format(axis, math.abs(threshold*100)))
|
table.insert(ret, ("Mouse %s position (threshold %s%%)"):format(axis, math.abs(threshold*100)))
|
||||||
-- Gamepad axis
|
-- Gamepad axis
|
||||||
elseif id:match("^gamepad%.axis%.") then
|
elseif id:match("^gamepad%.axis%.") then
|
||||||
local gid, axis, threshold = id:match("^gamepad%.axis%.(.+)%.(.+)%%(.+)$")
|
local gidaxis, threshold = id:match("^gamepad%.axis%.(.+)%%(.+)$")
|
||||||
if not gid then gid, axis = id:match("^gamepad%.axis%.(.+)%.(.+)$") end -- no threshold (=0)
|
if not gidaxis then gidaxis = id:match("^gamepad%.axis%.(.+)$") end -- no threshold (=0.1)
|
||||||
|
local axis = gidaxis:match("([^.]+)$")
|
||||||
|
local gid = tonumber(gidaxis:match("^(.+)%..+$"))
|
||||||
threshold = tonumber(threshold) or 0.1
|
threshold = tonumber(threshold) or 0.1
|
||||||
if axis == "rightx" then
|
|
||||||
table.insert(ret, ("Gamepad %s right stick %s (deadzone %s%%)"):format(gid, threshold >= 0 and "right" or "left", math.abs(threshold*100)))
|
local str
|
||||||
elseif axis == "righty" then
|
if gid then
|
||||||
table.insert(ret, ("Gamepad %s right stick %s (deadzone %s%%)"):format(gid, threshold >= 0 and "down" or "up", math.abs(threshold*100)))
|
str = "Gamepad "..gid
|
||||||
elseif axis == "leftx" then
|
|
||||||
table.insert(ret, ("Gamepad %s left stick %s (deadzone %s%%)"):format(gid, threshold >= 0 and "right" or "left", math.abs(threshold*100)))
|
|
||||||
elseif axis == "lefty" then
|
|
||||||
table.insert(ret, ("Gamepad %s left stick %s (deadzone %s%%)"):format(gid, threshold >= 0 and "down" or "up", math.abs(threshold*100)))
|
|
||||||
else
|
else
|
||||||
table.insert(ret, ("Gamepad %s axis %s (deadzone %s%%)"):format(gid, axis, math.abs(threshold*100)))
|
str = "Gamepad"
|
||||||
end
|
end
|
||||||
|
if axis == "rightx" then
|
||||||
|
str = str .. (" right stick %s (deadzone %s%%)"):format(threshold >= 0 and "right" or "left")
|
||||||
|
elseif axis == "righty" then
|
||||||
|
str = str .. (" right stick %s (deadzone %s%%)"):format(threshold >= 0 and "down" or "up")
|
||||||
|
elseif axis == "leftx" then
|
||||||
|
str = str .. (" left stick %s (deadzone %s%%)"):format(threshold >= 0 and "right" or "left")
|
||||||
|
elseif axis == "lefty" then
|
||||||
|
str = str .. (" left stick %s (deadzone %s%%)"):format(threshold >= 0 and "down" or "up")
|
||||||
|
else
|
||||||
|
str = str .. (" axis %s (deadzone %s%%)"):format(axis, math.abs(threshold*100))
|
||||||
|
end
|
||||||
|
str = str .. " (deadzone %s%%)"):format(math.abs(threshold*100))
|
||||||
|
|
||||||
|
table.insert(ret, str)
|
||||||
else
|
else
|
||||||
table.insert(ret, id)
|
table.insert(ret, id)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ local axis_mt = {
|
||||||
local hijacked
|
local hijacked
|
||||||
hijacked = setmetatable({
|
hijacked = setmetatable({
|
||||||
positive = input.button(function() return hijacked:value() > self.triggeringThreshold end),
|
positive = input.button(function() return hijacked:value() > self.triggeringThreshold end),
|
||||||
negative = input.button(function() return hijacked:value() < self.triggeringThreshold end)
|
negative = input.button(function() return hijacked:value() < -self.triggeringThreshold end)
|
||||||
}, { __index = self, __newindex = self })
|
}, { __index = self, __newindex = self })
|
||||||
table.insert(self.hijackStack, hijacked)
|
table.insert(self.hijackStack, hijacked)
|
||||||
self.hijacking = hijacked
|
self.hijacking = hijacked
|
||||||
|
|
@ -625,7 +625,7 @@ input = {
|
||||||
r.hijacking = r
|
r.hijacking = r
|
||||||
r:bind(...)
|
r:bind(...)
|
||||||
r.positive = input.button(function() return r:value() > r.triggeringThreshold end)
|
r.positive = input.button(function() return r:value() > r.triggeringThreshold end)
|
||||||
r.negative = input.button(function() return r:value() < r.triggeringThreshold end)
|
r.negative = input.button(function() return r:value() < -r.triggeringThreshold end)
|
||||||
return r
|
return r
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue