BatterUp/src/dbg.lua

65 lines
1.6 KiB
Lua

dbg = {}
function dbg.label(value, name)
if type(value) == "table" then
print(name .. ":")
printTable(value)
elseif type(value) == "boolean" then
if value then
print(name .. ": " .. (value and "true" or "false"))
end
elseif value ~= nil then
print(name .. ": " .. value)
else
print(name .. ": nil")
end
return value
end
-- Only works if called with the bases empty (i.e. the only runner should be the batter.
function dbg.loadTheBases(br)
br:pushNewBatter()
br:pushNewBatter()
br:pushNewBatter()
br.runners[2].x = C.Bases[C.First].x
br.runners[2].y = C.Bases[C.First].y
br.runners[2].nextBase = C.Bases[C.Second]
br.runners[3].x = C.Bases[C.Second].x
br.runners[3].y = C.Bases[C.Second].y
br.runners[3].nextBase = C.Bases[C.Third]
br.runners[4].x = C.Bases[C.Third].x
br.runners[4].y = C.Bases[C.Third].y
br.runners[4].nextBase = C.Bases[C.Home]
end
---@return BoxScoreData
function dbg.mockBoxScoreData(inningCount)
inningCount = inningCount or 9
local data = {
home = {},
away = {},
}
for i = 1, inningCount do
data.home[i] = math.floor(math.random() * 5)
data.away[i] = math.floor(math.random() * 5)
end
return data
end
---@param points XyPair[]
function dbg.drawLine(points)
playdate.graphics.setColor(playdate.graphics.kColorWhite)
for i = 2, #points do
local prev = points[i - 1]
local next = points[i]
playdate.graphics.drawLine(prev.x, prev.y, next.x, next.y)
end
end
if not playdate then
return dbg
end