mirror of
https://github.com/notwa/mm
synced 2024-11-05 02:39:02 -08:00
22 lines
460 B
Lua
22 lines
460 B
Lua
|
local InputHandler = Class()
|
||
|
function InputHandler:init(binds)
|
||
|
self.binds = binds
|
||
|
self.old_ctrl = {}
|
||
|
end
|
||
|
|
||
|
function InputHandler:update()
|
||
|
local ctrl = {}
|
||
|
local pressed = {}
|
||
|
local j = joypad.getimmediate()
|
||
|
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
|