StyLua pass

Add 'lint' recipe to Makefile
This commit is contained in:
Sage Vaillancourt 2025-02-01 07:39:09 -05:00
parent 0b126919ac
commit 4fc37b133e
5 changed files with 355 additions and 347 deletions

View File

@ -1,3 +1,6 @@
lint:
stylua src/
all: all:
pdc src BatterUp.pdx pdc src BatterUp.pdx

View File

@ -61,20 +61,21 @@ end
---@param wShape W? ---@param wShape W?
---@return fun(callback: fun(componentT: T, componentU: U, componentV: V, componentW: W)) ---@return fun(callback: fun(componentT: T, componentU: U, componentV: V, componentW: W))
function ecs.entitiesHavingShapes(tShape, uShape, vShape, wShape) function ecs.entitiesHavingShapes(tShape, uShape, vShape, wShape)
return function() return function() end
end
end end
-- Print contents of `tbl`, with indentation. -- Print contents of `tbl`, with indentation.
-- `indent` sets the initial level of indentation. -- `indent` sets the initial level of indentation.
function tprint(tbl, indent) function tprint(tbl, indent)
if not indent then indent = 0 end if not indent then
indent = 0
end
for k, v in pairs(tbl) do for k, v in pairs(tbl) do
formatting = string.rep(" ", indent) .. k .. ": " formatting = string.rep(" ", indent) .. k .. ": "
if type(v) == "table" then if type(v) == "table" then
print(formatting) print(formatting)
tprint(v, indent + 1) tprint(v, indent + 1)
elseif type(v) == 'boolean' then elseif type(v) == "boolean" then
print(formatting .. tostring(v)) print(formatting .. tostring(v))
else else
print(formatting .. v) print(formatting .. v)
@ -87,7 +88,7 @@ function addSystem(callback, keys, shapes)
callback = callback, callback = callback,
keys = keys, keys = keys,
shapes = shapes, shapes = shapes,
entityCache = nil entityCache = nil,
} }
end end
@ -109,7 +110,15 @@ function ecs.update(deltaSeconds)
end end
local keys = system.keys local keys = system.keys
for entity, _ in pairs(system.entityCache) do for entity, _ in pairs(system.entityCache) do
system.callback(deltaSeconds, entity, entity[keys[1]], entity[keys[2]], entity[keys[3]], entity[keys[4]], entity) system.callback(
deltaSeconds,
entity,
entity[keys[1]],
entity[keys[2]],
entity[keys[3]],
entity[keys[4]],
entity
)
end end
end end
end end
@ -205,7 +214,7 @@ ecs.forEntitiesWith(Target, function (delta, e, pos, vel)
pos.y = pos.y + (delta * vel.y) pos.y = pos.y + (delta * vel.y)
print("position") print("position")
tprint(pos, 1) tprint(pos, 1)
ecs.set(e, Target, 'hallo') ecs.set(e, Target, "hallo")
end) end)
ecs.update(1) ecs.update(1)

View File

@ -1,3 +1,4 @@
-- stylua: ignore start
import 'CoreLibs/animation.lua' import 'CoreLibs/animation.lua'
import 'CoreLibs/animator.lua' import 'CoreLibs/animator.lua'
import 'CoreLibs/easing.lua' import 'CoreLibs/easing.lua'
@ -7,6 +8,7 @@ import 'CoreLibs/ui.lua'
import 'graphics.lua' import 'graphics.lua'
import 'utils.lua' import 'utils.lua'
-- stylua: ignore end
--- @alias XYPair { x: number, y: number } --- @alias XYPair { x: number, y: number }
@ -20,7 +22,7 @@ local gfx = playdate.graphics
local SCREEN = { local SCREEN = {
W = playdate.display.getWidth(), W = playdate.display.getWidth(),
H = playdate.display.getHeight() H = playdate.display.getHeight(),
} }
local CENTER = xy(SCREEN.W / 2, SCREEN.H / 2) local CENTER = xy(SCREEN.W / 2, SCREEN.H / 2)
@ -29,11 +31,7 @@ local batCrackSound = playdate.sound.sampleplayer.new("sounds/bat-crack-reverb.w
local grassBackground = gfx.image.new("images/game/grass.png") --[[@as PlaydateGraphicsImage]] local grassBackground = gfx.image.new("images/game/grass.png") --[[@as PlaydateGraphicsImage]]
local playerFrown = gfx.image.new("images/game/player-frown.png") --[[@as PlaydateGraphicsImage]] local playerFrown = gfx.image.new("images/game/player-frown.png") --[[@as PlaydateGraphicsImage]]
local playerImageBlipper = blipper.new( local playerImageBlipper = blipper.new(100, "images/game/player.png", "images/game/player-lowhat.png")
100,
"images/game/player.png",
"images/game/player-lowhat.png"
)
local BALL_OFFSCREEN = 999 local BALL_OFFSCREEN = 999
@ -56,14 +54,14 @@ local TAG_DISTANCE = 20
local ball = { local ball = {
x = CENTER.x, x = CENTER.x,
y = BALL_OFFSCREEN, y = BALL_OFFSCREEN,
size = 6 size = 6,
} }
local BAT_LENGTH = 45 local BAT_LENGTH = 45
local MODES = { local MODES = {
batting = {}, batting = {},
running = {} running = {},
} }
local currentMode = MODES.batting local currentMode = MODES.batting
@ -87,19 +85,19 @@ local bases = {
xy(SCREEN.W * 0.93, SCREEN.H * 0.52), xy(SCREEN.W * 0.93, SCREEN.H * 0.52),
xy(SCREEN.W * 0.47, SCREEN.H * 0.19), xy(SCREEN.W * 0.47, SCREEN.H * 0.19),
xy(SCREEN.W * 0.03, SCREEN.H * 0.52), xy(SCREEN.W * 0.03, SCREEN.H * 0.52),
xy(SCREEN.W * 0.474, SCREEN.H * 0.79) xy(SCREEN.W * 0.474, SCREEN.H * 0.79),
} }
---@type table<Base, Base> ---@type table<Base, Base>
local nextBaseMap = { local nextBaseMap = {
[bases[FIRST]] = bases[SECOND], [bases[FIRST]] = bases[SECOND],
[bases[SECOND]] = bases[THIRD], [bases[SECOND]] = bases[THIRD],
[bases[THIRD]] = bases[HOME] [bases[THIRD]] = bases[HOME],
} }
function newFielder(speed) function newFielder(speed)
return { return {
speed = speed speed = speed,
} }
end end
@ -113,12 +111,12 @@ local fielders = {
catcher = newFielder(20), catcher = newFielder(20),
left = newFielder(40), left = newFielder(40),
center = newFielder(40), center = newFielder(40),
right = newFielder(40) right = newFielder(40),
} }
local PITCHER_POS = { local PITCHER_POS = {
x = SCREEN.W * 0.48, x = SCREEN.W * 0.48,
y = SCREEN.H * 0.40 y = SCREEN.H * 0.40,
} }
--- Resets the target positions of all fielders to their defaults (at their field positions). --- Resets the target positions of all fielders to their defaults (at their field positions).
@ -161,7 +159,7 @@ function newRunner()
y = PLAYER_STARTING_Y, y = PLAYER_STARTING_Y,
nextBase = nil, nextBase = nil,
prevBase = nil, prevBase = nil,
name = runnerNames[nameI] name = runnerNames[nameI],
} }
nameI = nameI + 1 nameI = nameI + 1
runners[#runners + 1] = new runners[#runners + 1] = new
@ -236,8 +234,7 @@ function isTouchingBall(x, y)
return ballDistance < BALL_CATCH_HITBOX return ballDistance < BALL_CATCH_HITBOX
end end
function updateForcedTos() function updateForcedTos() end
end
local outs = 0 local outs = 0
local homeScore = 0 local homeScore = 0
@ -253,11 +250,9 @@ function outRunner(runnerIndex)
end end
function updateFielders() function updateFielders()
local touchingBaseCache = buildCache( local touchingBaseCache = buildCache(function(runner)
function(runner)
return isTouchingBase(runner.x, runner.y) return isTouchingBase(runner.x, runner.y)
end end)
)
for _, fielder in pairs(fielders) do for _, fielder in pairs(fielders) do
-- TODO: Target unforced runners (or their target bases) for tagging -- TODO: Target unforced runners (or their target bases) for tagging
@ -431,8 +426,10 @@ function updateBatting()
batTip.x = batBase.x + (BAT_LENGTH * math.sin(batAngle)) batTip.x = batBase.x + (BAT_LENGTH * math.sin(batAngle))
batTip.y = batBase.y + (BAT_LENGTH * math.cos(batAngle)) batTip.y = batBase.y + (BAT_LENGTH * math.cos(batAngle))
if acceleratedChange >= 0 and if
pointDirectlyUnderLine(ball.x, ball.y, batBase.x, batBase.y, batTip.x, batTip.y, SCREEN.H) then acceleratedChange >= 0
and pointDirectlyUnderLine(ball.x, ball.y, batBase.x, batBase.y, batTip.x, batTip.y, SCREEN.H)
then
batCrackSound:play() batCrackSound:play()
currentMode = MODES.running currentMode = MODES.running
ballAngle = batAngle + math.rad(90) ballAngle = batAngle + math.rad(90)
@ -565,10 +562,7 @@ function playdate.update()
if currentMode == MODES.batting then if currentMode == MODES.batting then
gfx.setLineWidth(5) gfx.setLineWidth(5)
gfx.drawLine( gfx.drawLine(batBase.x, batBase.y, batTip.x, batTip.y)
batBase.x, batBase.y,
batTip.x, batTip.y
)
end end
if playdate.isCrankDocked() then -- or (crankChange < 2 and currentMode == MODES.running) then if playdate.isCrankDocked() then -- or (crankChange < 2 and currentMode == MODES.running) then

View File

@ -1,5 +1,7 @@
-- stylua: ignore start
import 'CoreLibs/animation.lua' import 'CoreLibs/animation.lua'
import 'CoreLibs/graphics.lua' import 'CoreLibs/graphics.lua'
-- stylua: ignore end
-- number = ((number * 2) - 1) -- number = ((number * 2) - 1)
-- return number * number -- return number * number
@ -21,7 +23,7 @@ end
function xy(x, y) function xy(x, y)
return { return {
x = x, x = x,
y = y y = y,
} }
end end
@ -128,7 +130,7 @@ function buildCache(fetcher)
end end
cacheData[key] = fetcher(key) or NO_VALUE cacheData[key] = fetcher(key) or NO_VALUE
return cacheData[key] return cacheData[key]
end end,
} }
end end
@ -146,6 +148,6 @@ function blipper.new(msInterval, imagePath1, imagePath2)
draw = function(self, disableBlipping, x, y) draw = function(self, disableBlipping, x, y)
local currentImage = (disableBlipping or self.blinker.on) and self.image2 or self.image1 local currentImage = (disableBlipping or self.blinker.on) and self.image2 or self.image1
currentImage:draw(x, y) currentImage:draw(x, y)
end end,
} }
end end