baton
baton copied to clipboard
Add ability to use functions as control sources.
This change allows functions to be specified in the controls section of the initialization config. This allows complex composite controls to be declared.
It also includes a change that allows negative values from those functions to be handled meaningfully.
Example
input = baton.new {
controls = {
left = {'key:left', 'key:a', 'axis:leftx-', 'button:dpleft'},
right = {'key:right', 'key:d', 'axis:leftx+', 'button:dpright'},
horizontal = function(input)
--returns -1 to 1
return input:get("right")-input:get("left")
end,
up = {'key:up', 'key:w', 'axis:lefty-', 'button:dpup'},
down = {'key:down', 'key:s', 'axis:lefty+', 'button:dpdown'},
vertical = function(input)
--returns -1 to 1
return input:get("down")-input:get("up")
end,
alt = {'key:lalt', 'key:ralt'},
enter = {'key:kpenter', 'key:return'},
toggleFullscreen = function(input)
return input:down("alt") and input:pressed("enter")
end
}
}
function love.update(deltaTime)
input:update()
print(tostring(input:get("horizontal"))..", "..tostring(input:get("vertical")))
if input:pressed("toggleFullscreen") then
love.window.setFullscreen(not love.window.getFullscreen(), "desktop")
end
end
Apparently I forgot to look at this in 2019 and haven't checked this repo since...
I can definitely see the utility for defining composite buttons, but I don't understand why you would want controls to return negative numbers. Your example shows separate horizontal and vertical controls; wouldn't those be better handled by pairs?
@KurtLoeffler sorry for the incredibly late reply, is this even relevant to your life anymore?