luncher/src/systems/input.lua

27 lines
977 B
Lua

local buttonJustPressed = playdate.buttonJustPressed
---@type InputState
local inputState = {}
inputSystem = filteredSystem("input", { canReceiveInput = T.marker }, function(e, _, system)
e.inputState = inputState
system.world:addEntity(e)
end)
function inputSystem:preProcess()
inputState.upJustPressed = buttonJustPressed(playdate.kButtonUp)
inputState.downJustPressed = buttonJustPressed(playdate.kButtonDown)
inputState.rightJustPressed = buttonJustPressed(playdate.kButtonRight)
inputState.leftJustPressed = buttonJustPressed(playdate.kButtonLeft)
inputState.aJustPressed = buttonJustPressed(playdate.kButtonA)
inputState.bJustPressed = buttonJustPressed(playdate.kButtonB)
inputState.receivedInputThisFrame =
inputState.upJustPressed
or inputState.downJustPressed
or inputState.rightJustPressed
or inputState.leftJustPressed
or inputState.aJustPressed
or inputState.bJustPressed
end