111 lines
3.0 KiB
Lua
111 lines
3.0 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
|
|
|
|
local hitSamples = {
|
|
away = {
|
|
{
|
|
utils.xy(7.88733, -16.3434),
|
|
utils.xy(378.3376, 30.49521),
|
|
utils.xy(367.1036, 21.55336),
|
|
},
|
|
{
|
|
utils.xy(379.8051, -40.82794),
|
|
utils.xy(-444.5791, -30.30901),
|
|
utils.xy(-30.43079, -30.50307),
|
|
},
|
|
{
|
|
utils.xy(227.8881, -14.56854),
|
|
utils.xy(293.5208, 39.38919),
|
|
utils.xy(154.4738, -26.55899),
|
|
},
|
|
},
|
|
home = {
|
|
{
|
|
utils.xy(146.2505, -89.12155),
|
|
utils.xy(429.5428, 59.62944),
|
|
utils.xy(272.4666, -78.578),
|
|
},
|
|
{
|
|
utils.xy(485.0516, 112.8341),
|
|
utils.xy(290.9232, -4.946442),
|
|
utils.xy(263.4262, -6.482407),
|
|
},
|
|
{
|
|
utils.xy(260.6927, -63.63049),
|
|
utils.xy(392.1548, -44.22421),
|
|
utils.xy(482.5545, 105.3476),
|
|
utils.xy(125.5928, 18.53091),
|
|
},
|
|
},
|
|
}
|
|
|
|
---@return Statistics
|
|
function dbg.mockStatistics(inningCount)
|
|
inningCount = inningCount or 9
|
|
local stats = Statistics.new()
|
|
for i = 1, inningCount - 1 do
|
|
stats.innings[i].home.score = math.floor(math.random() * 5)
|
|
stats.innings[i].away.score = math.floor(math.random() * 5)
|
|
if hitSamples.home[i] ~= nil then
|
|
stats.innings[i].home.hits = hitSamples.home[i]
|
|
end
|
|
if hitSamples.away[i] ~= nil then
|
|
stats.innings[i].away.hits = hitSamples.away[i]
|
|
end
|
|
stats:pushInning()
|
|
end
|
|
|
|
local homeScore, awayScore = utils.totalScores(stats)
|
|
if homeScore == awayScore then
|
|
stats.innings[#stats.innings].home.score = 1 + stats.innings[#stats.innings].home.score
|
|
end
|
|
return stats
|
|
end
|
|
|
|
---@param points XyPair[]
|
|
function dbg.drawLine(points)
|
|
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
|