Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 34 additions & 22 deletions baton.lua
Original file line number Diff line number Diff line change
Expand Up @@ -192,16 +192,18 @@ end
]]
function Player:_setActiveDevice()
for _, control in pairs(self._controls) do
for _, source in ipairs(control.sources) do
local type, value = parseSource(source)
if sourceFunction.keyboardMouse[type] then
if sourceFunction.keyboardMouse[type](value) > self.config.deadzone then
self._activeDevice = 'kbm'
return
end
elseif self.config.joystick and sourceFunction.joystick[type] then
if sourceFunction.joystick[type](self.config.joystick, value) > self.config.deadzone then
self._activeDevice = 'joy'
if type(control.sources) == "table" then
for _, source in ipairs(control.sources) do
local type, value = parseSource(source)
if sourceFunction.keyboardMouse[type] then
if sourceFunction.keyboardMouse[type](value) > self.config.deadzone then
self._activeDevice = 'kbm'
return
end
elseif self.config.joystick and sourceFunction.joystick[type] then
if sourceFunction.joystick[type](self.config.joystick, value) > self.config.deadzone then
self._activeDevice = 'joy'
end
end
end
end
Expand All @@ -214,19 +216,29 @@ end
]]
function Player:_getControlRawValue(control)
local rawValue = 0
for _, source in ipairs(control.sources) do
local type, value = parseSource(source)
if sourceFunction.keyboardMouse[type] and self._activeDevice == 'kbm' then
if sourceFunction.keyboardMouse[type](value) == 1 then
return 1
end
elseif sourceFunction.joystick[type] and self._activeDevice == 'joy' then
rawValue = rawValue + sourceFunction.joystick[type](self.config.joystick, value)
if rawValue >= 1 then
return 1
if type(control.sources) == "function" then
local result = control.sources(self)
if type(result) == "number" then
rawValue = result
else
rawValue = result and 1 or 0
end
else
for _, source in ipairs(control.sources) do
local type, value = parseSource(source)
if sourceFunction.keyboardMouse[type] and self._activeDevice == 'kbm' then
if sourceFunction.keyboardMouse[type](value) == 1 then
return 1
end
elseif sourceFunction.joystick[type] and self._activeDevice == 'joy' then
rawValue = rawValue + sourceFunction.joystick[type](self.config.joystick, value)
if rawValue >= 1 then
return 1
end
end
end
end

return rawValue
end

Expand All @@ -237,9 +249,9 @@ end
function Player:_updateControls()
for _, control in pairs(self._controls) do
control.rawValue = self:_getControlRawValue(control)
control.value = control.rawValue >= self.config.deadzone and control.rawValue or 0
control.value = math.abs(control.rawValue) >= self.config.deadzone and control.rawValue or 0
control.downPrevious = control.down
control.down = control.value > 0
control.down = math.abs(control.value) > 0
control.pressed = control.down and not control.downPrevious
control.released = control.downPrevious and not control.down
end
Expand Down