mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-12-22 17:19:03 -06:00
Refactored joystick input handling
This commit is contained in:
parent
b15cd9802f
commit
a3a27d2566
4
main.lua
4
main.lua
@ -225,13 +225,13 @@ function love.joystickaxis(joystick, axis, value)
|
||||
config.input.joysticks[joystick:getName()].axes and
|
||||
config.input.joysticks[joystick:getName()].axes[axis]
|
||||
then
|
||||
if math.abs(value) >= 0.5 then
|
||||
if math.abs(value) >= 1 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
|
||||
if math.abs(value) >= 1 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})
|
||||
|
@ -57,7 +57,7 @@ function ConfigScene:render()
|
||||
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")
|
||||
love.graphics.printf(self.set_inputs[input], 210, 50 + i * 20, 400, "left")
|
||||
end
|
||||
end
|
||||
if self.input_state > table.getn(configurable_inputs) then
|
||||
@ -135,7 +135,7 @@ function ConfigScene:onInputPress(e)
|
||||
self.input_state = self.input_state + 1
|
||||
self.key = 1
|
||||
elseif e.type == "joyaxis" then
|
||||
if (e.axis ~= self.last_axis or self.axis_timer > 30) and math.abs(e.value) >= 1 then
|
||||
if (e.axis ~= self.last_axis or self.axis_timer > 30) and e.value >= 1 then
|
||||
addJoystick(self.new_input, e.name)
|
||||
if not self.new_input.joysticks[e.name].axes then
|
||||
self.new_input.joysticks[e.name].axes = {}
|
||||
@ -146,7 +146,7 @@ function ConfigScene:onInputPress(e)
|
||||
self.set_inputs[configurable_inputs[self.input_state]] =
|
||||
self.set_inputs[configurable_inputs[self.input_state]] ..
|
||||
" / jaxis " ..
|
||||
(e.value >= 1 and "+" or "-") .. e.axis ..
|
||||
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 >= 1 and "positive" or "negative"] = configurable_inputs[self.input_state]
|
||||
self.input_state = self.input_state + 1
|
||||
@ -164,7 +164,7 @@ function ConfigScene:onInputPress(e)
|
||||
self.new_input.joysticks[e.name].hats[e.hat] = {}
|
||||
end
|
||||
self.set_inputs[configurable_inputs[self.input_state]] =
|
||||
self.set_inputs[configurable_inputs[self.input_state]]
|
||||
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 "")
|
||||
|
Loading…
Reference in New Issue
Block a user