Add selene to 'make lint'

Patch up its complaints.
Move blipper to graphics.lua
This commit is contained in:
Sage Vaillancourt 2025-02-01 11:04:27 -05:00
parent 4fc37b133e
commit f1d8c28370
4 changed files with 45 additions and 57 deletions

View File

@ -1,6 +1,6 @@
lint:
stylua src/
all: all:
pdc src BatterUp.pdx pdc src BatterUp.pdx
lint:
stylua src/
cat <(sed 's/^function/-- selene: allow(unused_variable)\nfunction/' ${PLAYDATE_SDK_PATH}/CoreLibs/__stub.lua) src/utils.lua src/graphics.lua src/main.lua | grep -v '^import' | selene -

View File

@ -4,7 +4,7 @@ local ballBuffer = 5
--- XXX --- XXX
--- XOX --- XOX
--- Where each character is the size of the screen, and 'O' is the default view. --- Where each character is the size of the screen, and 'O' is the default view.
function getDrawOffset(screenW, screenH, ballX, ballY) function getDrawOffset(screenW, _screenH, ballX, ballY)
local offsetX, offsetY local offsetX, offsetY
if ballY < ballBuffer then if ballY < ballBuffer then
offsetY = math.max(ballBuffer, -1 * (ballY - ballBuffer)) offsetY = math.max(ballBuffer, -1 * (ballY - ballBuffer))
@ -20,3 +20,22 @@ function getDrawOffset(screenW, screenH, ballX, ballY)
end end
return offsetX, offsetY return offsetX, offsetY
end end
-- selene: allow(unscoped_variables)
blipper = {}
--- Build an object that simply "blips" between the given images at the given interval.
--- Expects `playdate.graphics.animation.blinker.updateAll()` to be called on every update.
function blipper.new(msInterval, imagePath1, imagePath2)
local blinker = playdate.graphics.animation.blinker.new(msInterval, msInterval, true)
blinker:start()
return {
blinker = blinker,
image1 = playdate.graphics.image.new(imagePath1),
image2 = playdate.graphics.image.new(imagePath2),
draw = function(self, disableBlipping, x, y)
local currentImage = (disableBlipping or self.blinker.on) and self.image2 or self.image1
currentImage:draw(x, y)
end,
}
end

View File

@ -171,6 +171,7 @@ local batter = newRunner()
batter.nextBase = bases[FIRST] batter.nextBase = bases[FIRST]
batter.forcedTo = bases[FIRST] batter.forcedTo = bases[FIRST]
--- "Throws" the ball from its current position to the given destination.
function throwBall(destX, destY, easingFunc, flyTimeMs, floaty) function throwBall(destX, destY, easingFunc, flyTimeMs, floaty)
if not flyTimeMs then if not flyTimeMs then
flyTimeMs = distanceBetween(ball.x, ball.y, destX, destY) * 5 flyTimeMs = distanceBetween(ball.x, ball.y, destX, destY) * 5
@ -215,6 +216,7 @@ end
local elapsedSec = 0 local elapsedSec = 0
local crankChange = 0 local crankChange = 0
local acceleratedChange
local BASE_HITBOX = 13 local BASE_HITBOX = 13
--- Returns the base being touched by the runner at (x,y), or nil, if no base is being touched --- Returns the base being touched by the runner at (x,y), or nil, if no base is being touched
@ -249,6 +251,14 @@ function outRunner(runnerIndex)
fielderDanceAnimator:reset() fielderDanceAnimator:reset()
end end
-- TODO: Away score
function score(runnerIndex)
outRunners[#outRunners + 1] = runners[runnerIndex]
table.remove(runners, runnerIndex)
updateForcedTos()
homeScore = homeScore + 1
end
function updateFielders() function updateFielders()
local touchingBaseCache = buildCache(function(runner) local touchingBaseCache = buildCache(function(runner)
return isTouchingBase(runner.x, runner.y) return isTouchingBase(runner.x, runner.y)
@ -301,8 +311,11 @@ function updateRunners()
end) end)
local runnerMoved = false local runnerMoved = false
for _, runner in pairs(nonPlayerRunners) do for runnerIndex, runner in ipairs(nonPlayerRunners) do
local _, nearestBaseDistance = getNearestOf(bases, runner.x, runner.y) local nearestBase, nearestBaseDistance = getNearestOf(bases, runner.x, runner.y)
if nearestBaseDistance < 5 and runner.nextBase == bases[HOME] and nearestBase == bases[HOME] then
score(runnerIndex)
end
if runner.nextBase then if runner.nextBase then
local nb = runner.nextBase local nb = runner.nextBase
local x, y, distance = normalizeVector(runner.x, runner.y, nb.x, nb.y) local x, y, distance = normalizeVector(runner.x, runner.y, nb.x, nb.y)
@ -329,16 +342,6 @@ function updateRunners()
return runnerMoved return runnerMoved
end end
---@return boolean
function ballIsBeingThrown()
return false
end
---@return boolean
function throwArrivedBeforeRunner()
return false
end
function getRunnerTargeting(base) function getRunnerTargeting(base)
for _, runner in pairs(runners) do for _, runner in pairs(runners) do
if runner.nextBase == base then if runner.nextBase == base then
@ -368,14 +371,11 @@ end
function getBaseOfStrandedRunner() function getBaseOfStrandedRunner()
local farRunnersBase, farDistance local farRunnersBase, farDistance
for _, runner in pairs(runners) do for _, runner in pairs(runners) do
local base, distance = getNearestOf(bases, runner.x, runner.y, function(base) local nearestBase, distance = getNearestOf(bases, runner.x, runner.y, function(base)
return runner.nextBase == base return runner.nextBase == base
end) end)
if farRunnersBase == nil then if farRunnersBase == nil or farDistance < distance then
farRunnersBase = base farRunnersBase = nearestBase
farDistance = distance
elseif farDistance < distance then
farRunnersBase = base
farDistance = distance farDistance = distance
end end
end end
@ -432,17 +432,17 @@ function updateBatting()
then then
batCrackSound:play() batCrackSound:play()
currentMode = MODES.running currentMode = MODES.running
ballAngle = batAngle + math.rad(90) local ballAngle = batAngle + math.rad(90)
local mult = math.abs(acceleratedChange / 15) local mult = math.abs(crankChange / 15)
local ballVelX = mult * 10 * math.sin(ballAngle) local ballVelX = mult * 10 * math.sin(ballAngle)
local ballVelY = mult * 5 * math.cos(ballAngle) local ballVelY = mult * 5 * math.cos(ballAngle)
if ballVelY > 0 then if ballVelY > 0 then
ballVelX = ballVelX * -1 ballVelX = ballVelX * -1
ballVelY = ballVelY * -1 ballVelY = ballVelY * -1
end end
ballDestX = ball.x + (ballVelX * HIT_MULT) local ballDestX = ball.x + (ballVelX * HIT_MULT)
ballDestY = ball.y + (ballVelY * HIT_MULT) local ballDestY = ball.y + (ballVelY * HIT_MULT)
throwBall(ballDestX, ballDestY, playdate.easingFunctions.outQuint, 2000) throwBall(ballDestX, ballDestY, playdate.easingFunctions.outQuint, 2000)
fielders.first.target = bases[FIRST] fielders.first.target = bases[FIRST]

View File

@ -48,19 +48,6 @@ function filter(array, condition)
return newArray return newArray
end end
---@generic TIn
---@generic TOut
---@param array TIn[]
---@param mapper fun(TIn): TOut
---@return TOut[]
function map(array, mapper)
local newArray = {}
for _, element in pairs(array) do
newArray[#newArray + 1] = mapper(element)
end
return newArray
end
---@return number, number, number ---@return number, number, number
function distanceBetween(x1, y1, x2, y2) function distanceBetween(x1, y1, x2, y2)
local a = x1 - x2 local a = x1 - x2
@ -133,21 +120,3 @@ function buildCache(fetcher)
end, end,
} }
end end
blipper = {}
--- Build an object that simply "blips" between the given images at the given interval.
--- Expects `playdate.graphics.animation.blinker.updateAll()` to be called on every update.
function blipper.new(msInterval, imagePath1, imagePath2)
local blinker = playdate.graphics.animation.blinker.new(msInterval, msInterval, true)
blinker:start()
return {
blinker = blinker,
image1 = playdate.graphics.image.new(imagePath1),
image2 = playdate.graphics.image.new(imagePath2),
draw = function(self, disableBlipping, x, y)
local currentImage = (disableBlipping or self.blinker.on) and self.image2 or self.image1
currentImage:draw(x, y)
end,
}
end