2015-05-25 20:10:00 -07:00
|
|
|
local InputHandler = Class()
|
|
|
|
function InputHandler:init(binds)
|
|
|
|
self.binds = binds
|
|
|
|
self.old_ctrl = {}
|
|
|
|
end
|
|
|
|
|
2015-11-14 14:59:37 -08:00
|
|
|
function InputHandler:update(inputs)
|
2015-05-25 20:10:00 -07:00
|
|
|
local ctrl = {}
|
|
|
|
local pressed = {}
|
2015-11-14 14:59:37 -08:00
|
|
|
local j = inputs or joypad.getimmediate()
|
2015-05-25 20:10:00 -07:00
|
|
|
for k, v in pairs(self.binds) do
|
|
|
|
ctrl[k] = j[v]
|
|
|
|
end
|
|
|
|
for k, v in pairs(ctrl) do
|
|
|
|
pressed[k] = ctrl[k] and not self.old_ctrl[k]
|
|
|
|
end
|
|
|
|
self.old_ctrl = ctrl
|
|
|
|
return ctrl, pressed
|
|
|
|
end
|
|
|
|
|
|
|
|
return InputHandler
|