From 14629a5346850fec395ff9d73fbc0cc9ee572233 Mon Sep 17 00:00:00 2001 From: Sage Vaillancourt Date: Mon, 3 Feb 2025 12:46:15 -0500 Subject: [PATCH] Add batting-team indicator to scoreboard. --- src/main.lua | 2 +- src/scoreboard.lua | 32 +++++++++++++++++++++++--------- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/main.lua b/src/main.lua index 23ded06..5277f2c 100644 --- a/src/main.lua +++ b/src/main.lua @@ -629,7 +629,7 @@ function playdate.update() end gfx.setDrawOffset(0, 0) - drawScoreboard(0, Screen.H * 0.77, teams, outs) + drawScoreboard(0, Screen.H * 0.77, teams, outs, battingTeam) announcer:draw(Center.x, 10) end diff --git a/src/scoreboard.lua b/src/scoreboard.lua index a9ba418..83bbd85 100644 --- a/src/scoreboard.lua +++ b/src/scoreboard.lua @@ -1,18 +1,32 @@ local ScoreFont = playdate.graphics.font.new("fonts/font-full-circle.pft") local OutBubbleRadius = 5 -local ScoreboardMarginX = 8 -local ScoreboardHeight = 55 +local ScoreboardMarginX = 6 +local ScoreboardHeight = 55 +local Indicator = "> " +local IndicatorWidth = ScoreFont:getTextWidth(Indicator) -function drawScoreboard(x, y, teams, outs) +---@param teams any +---@param battingTeam any +---@return string, number, string, number +function getIndicators(teams, battingTeam) + if teams.home == battingTeam then + return Indicator, 0, "", IndicatorWidth + end + return "", IndicatorWidth, Indicator, 0 +end + +function drawScoreboard(x, y, teams, outs, battingTeam) local gfx = playdate.graphics local homeScore = teams.home.score local awayScore = teams.away.score - local homeScoreText = "HOME " .. (homeScore > 9 and homeScore or " " .. homeScore) - local awayScoreText = "AWAY " .. (awayScore > 9 and awayScore or " " .. awayScore) + local homeIndicator, homeOffset, awayIndicator, awayOffset = getIndicators(teams, battingTeam) - local rectWidth = (ScoreboardMarginX * 2) + ScoreFont:getTextWidth(homeScoreText) + local homeScoreText = homeIndicator .. "HOME " .. (homeScore > 9 and homeScore or " " .. homeScore) + local awayScoreText = awayIndicator .. "AWAY " .. (awayScore > 9 and awayScore or " " .. awayScore) + + local rectWidth = (ScoreboardMarginX * 2) + ScoreFont:getTextWidth(homeScoreText) + homeOffset gfx.setLineWidth(1) gfx.setColor(gfx.kColorBlack) @@ -21,8 +35,8 @@ function drawScoreboard(x, y, teams, outs) local originalDrawMode = gfx.getImageDrawMode() gfx.setImageDrawMode(gfx.kDrawModeInverted) - ScoreFont:drawText(homeScoreText, x + ScoreboardMarginX, y + 6) - ScoreFont:drawText(awayScoreText, x + ScoreboardMarginX, y + 22) + ScoreFont:drawText(homeScoreText, x + ScoreboardMarginX + homeOffset, y + 6) + ScoreFont:drawText(awayScoreText, x + ScoreboardMarginX + awayOffset, y + 22) gfx.setImageDrawMode(originalDrawMode) @@ -30,7 +44,7 @@ function drawScoreboard(x, y, teams, outs) function circleParams(i) local circleOffset = i * 2.5 * OutBubbleRadius - return (x + ScoreboardMarginX + OutBubbleRadius) + circleOffset, y + 46, OutBubbleRadius + return (x + ScoreboardMarginX + OutBubbleRadius + IndicatorWidth) + circleOffset, y + 46, OutBubbleRadius end for i = outs, 2 do