Add batting-team indicator to scoreboard.
This commit is contained in:
parent
e68566957d
commit
14629a5346
|
@ -629,7 +629,7 @@ function playdate.update()
|
||||||
end
|
end
|
||||||
|
|
||||||
gfx.setDrawOffset(0, 0)
|
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)
|
announcer:draw(Center.x, 10)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,18 +1,32 @@
|
||||||
local ScoreFont <const> = playdate.graphics.font.new("fonts/font-full-circle.pft")
|
local ScoreFont <const> = playdate.graphics.font.new("fonts/font-full-circle.pft")
|
||||||
local OutBubbleRadius <const> = 5
|
local OutBubbleRadius <const> = 5
|
||||||
local ScoreboardMarginX <const> = 8
|
local ScoreboardMarginX <const> = 6
|
||||||
local ScoreboardHeight = 55
|
local ScoreboardHeight <const> = 55
|
||||||
|
local Indicator = "> "
|
||||||
|
local IndicatorWidth <const> = 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 gfx = playdate.graphics
|
||||||
|
|
||||||
local homeScore = teams.home.score
|
local homeScore = teams.home.score
|
||||||
local awayScore = teams.away.score
|
local awayScore = teams.away.score
|
||||||
|
|
||||||
local homeScoreText = "HOME " .. (homeScore > 9 and homeScore or " " .. homeScore)
|
local homeIndicator, homeOffset, awayIndicator, awayOffset = getIndicators(teams, battingTeam)
|
||||||
local awayScoreText = "AWAY " .. (awayScore > 9 and awayScore or " " .. awayScore)
|
|
||||||
|
|
||||||
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.setLineWidth(1)
|
||||||
gfx.setColor(gfx.kColorBlack)
|
gfx.setColor(gfx.kColorBlack)
|
||||||
|
@ -21,8 +35,8 @@ function drawScoreboard(x, y, teams, outs)
|
||||||
local originalDrawMode = gfx.getImageDrawMode()
|
local originalDrawMode = gfx.getImageDrawMode()
|
||||||
gfx.setImageDrawMode(gfx.kDrawModeInverted)
|
gfx.setImageDrawMode(gfx.kDrawModeInverted)
|
||||||
|
|
||||||
ScoreFont:drawText(homeScoreText, x + ScoreboardMarginX, y + 6)
|
ScoreFont:drawText(homeScoreText, x + ScoreboardMarginX + homeOffset, y + 6)
|
||||||
ScoreFont:drawText(awayScoreText, x + ScoreboardMarginX, y + 22)
|
ScoreFont:drawText(awayScoreText, x + ScoreboardMarginX + awayOffset, y + 22)
|
||||||
|
|
||||||
gfx.setImageDrawMode(originalDrawMode)
|
gfx.setImageDrawMode(originalDrawMode)
|
||||||
|
|
||||||
|
@ -30,7 +44,7 @@ function drawScoreboard(x, y, teams, outs)
|
||||||
|
|
||||||
function circleParams(i)
|
function circleParams(i)
|
||||||
local circleOffset = i * 2.5 * OutBubbleRadius
|
local circleOffset = i * 2.5 * OutBubbleRadius
|
||||||
return (x + ScoreboardMarginX + OutBubbleRadius) + circleOffset, y + 46, OutBubbleRadius
|
return (x + ScoreboardMarginX + OutBubbleRadius + IndicatorWidth) + circleOffset, y + 46, OutBubbleRadius
|
||||||
end
|
end
|
||||||
|
|
||||||
for i = outs, 2 do
|
for i = outs, 2 do
|
||||||
|
|
Loading…
Reference in New Issue