From 2b436082bb5e8a29a4220165512243609099c129 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Fri, 7 Feb 2025 10:34:35 -0500 Subject: [PATCH 1/2] Properly display balls and strikes But only when the count isn't 0 - 0 --- src/main.lua | 2 +- src/scoreboard.lua | 18 ++++++++++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main.lua b/src/main.lua index 063c9c5..0447c1c 100644 --- a/src/main.lua +++ b/src/main.lua @@ -1014,7 +1014,7 @@ function playdate.update() drawMinimap() end drawScoreboard(0, Screen.H * 0.77, teams, outs, battingTeam, inning) - drawBallsAndStrikes(300, Screen.H * 0.77, balls, strikes) + drawBallsAndStrikes(290, Screen.H - 20, balls, strikes) announcer:draw(Center.x, 10) end diff --git a/src/scoreboard.lua b/src/scoreboard.lua index bd31553..44c09cd 100644 --- a/src/scoreboard.lua +++ b/src/scoreboard.lua @@ -6,6 +6,9 @@ local ScoreboardHeight = 55 local Indicator = "> " local IndicatorWidth = ScoreFont:getTextWidth(Indicator) +local BallStrikeWidth = 60 +local BallStrikeHeight = 20 + ---@param teams any ---@param battingTeam any ---@return string, number, string, number @@ -17,10 +20,21 @@ function getIndicators(teams, battingTeam) end function drawBallsAndStrikes(x, y, balls, strikes) + if balls == 0 and strikes == 0 then + return + end + local gfx = playdate.graphics - print("" .. balls .. " - " .. strikes) gfx.setColor(gfx.kColorBlack) - gfx.fillRect(x, y, 20, ScoreboardHeight) + gfx.fillRect(x, y, BallStrikeWidth, BallStrikeHeight) + local originalDrawMode = gfx.getImageDrawMode() + gfx.setImageDrawMode(gfx.kDrawModeInverted) + + local text = tostring(balls) .. " - " .. tostring(strikes) + local textWidth = ScoreFont:getTextWidth(text) + local widthDiff = BallStrikeWidth - textWidth + ScoreFont:drawText(text, x + (widthDiff / 2), y + 4) + gfx.setImageDrawMode(originalDrawMode) end function drawScoreboard(x, y, teams, outs, battingTeam, inning) -- 2.47.1 From e44bdcb57b273fd295378fce98edeb8b908d5e4b Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Fri, 7 Feb 2025 14:08:14 -0500 Subject: [PATCH 2/2] magicNumbers = magicNumbers - 1 --- src/scoreboard.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/scoreboard.lua b/src/scoreboard.lua index 44c09cd..c4827e9 100644 --- a/src/scoreboard.lua +++ b/src/scoreboard.lua @@ -6,8 +6,9 @@ local ScoreboardHeight = 55 local Indicator = "> " local IndicatorWidth = ScoreFont:getTextWidth(Indicator) +local BallStrikeMarginY = 4 local BallStrikeWidth = 60 -local BallStrikeHeight = 20 +local BallStrikeHeight = (BallStrikeMarginY * 2) + ScoreFont:getHeight() ---@param teams any ---@param battingTeam any @@ -33,7 +34,7 @@ function drawBallsAndStrikes(x, y, balls, strikes) local text = tostring(balls) .. " - " .. tostring(strikes) local textWidth = ScoreFont:getTextWidth(text) local widthDiff = BallStrikeWidth - textWidth - ScoreFont:drawText(text, x + (widthDiff / 2), y + 4) + ScoreFont:drawText(text, x + (widthDiff / 2), y + BallStrikeMarginY) gfx.setImageDrawMode(originalDrawMode) end -- 2.47.1