mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 12:19:02 -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 and
|
||||||
config.input.joysticks[joystick:getName()].axes[axis]
|
config.input.joysticks[joystick:getName()].axes[axis]
|
||||||
then
|
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"]
|
input_pressed = config.input.joysticks[joystick:getName()].axes[axis][value >= 0.5 and "positive" or "negative"]
|
||||||
end
|
end
|
||||||
positive_released = config.input.joysticks[joystick:getName()].axes[axis].positive
|
positive_released = config.input.joysticks[joystick:getName()].axes[axis].positive
|
||||||
negative_released = config.input.joysticks[joystick:getName()].axes[axis].negative
|
negative_released = config.input.joysticks[joystick:getName()].axes[axis].negative
|
||||||
end
|
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})
|
scene:onInputPress({input=input_pressed, type="joyaxis", name=joystick:getName(), axis=axis, value=value})
|
||||||
else
|
else
|
||||||
scene:onInputRelease({input=positive_released, type="joyaxis", name=joystick:getName(), axis=axis, value=value})
|
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
|
for i, input in ipairs(configurable_inputs) do
|
||||||
love.graphics.printf(input, 40, 50 + i * 20, 200, "left")
|
love.graphics.printf(input, 40, 50 + i * 20, 200, "left")
|
||||||
if self.set_inputs[input] then
|
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
|
||||||
end
|
end
|
||||||
if self.input_state > table.getn(configurable_inputs) then
|
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.input_state = self.input_state + 1
|
||||||
self.key = 1
|
self.key = 1
|
||||||
elseif e.type == "joyaxis" then
|
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)
|
addJoystick(self.new_input, e.name)
|
||||||
if not self.new_input.joysticks[e.name].axes then
|
if not self.new_input.joysticks[e.name].axes then
|
||||||
self.new_input.joysticks[e.name].axes = {}
|
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]] =
|
||||||
self.set_inputs[configurable_inputs[self.input_state]] ..
|
self.set_inputs[configurable_inputs[self.input_state]] ..
|
||||||
" / jaxis " ..
|
" / jaxis " ..
|
||||||
(e.value >= 1 and "+" or "-") .. e.axis ..
|
e.axis ..
|
||||||
" " .. string.sub(e.name, 1, 10) .. (string.len(e.name) > 10 and "..." or "")
|
" " .. 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.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
|
self.input_state = self.input_state + 1
|
||||||
@ -164,7 +164,7 @@ function ConfigScene:onInputPress(e)
|
|||||||
self.new_input.joysticks[e.name].hats[e.hat] = {}
|
self.new_input.joysticks[e.name].hats[e.hat] = {}
|
||||||
end
|
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]]
|
self.set_inputs[configurable_inputs[self.input_state]] ..
|
||||||
" / jhat " ..
|
" / jhat " ..
|
||||||
e.hat .. " " .. e.direction ..
|
e.hat .. " " .. e.direction ..
|
||||||
" " .. string.sub(e.name, 1, 10) .. (string.len(e.name) > 10 and "..." or "")
|
" " .. string.sub(e.name, 1, 10) .. (string.len(e.name) > 10 and "..." or "")
|
||||||
|
Loading…
Reference in New Issue
Block a user