diff --git a/src/baserunning.lua b/src/baserunning.lua index 619e779..2e7a313 100644 --- a/src/baserunning.lua +++ b/src/baserunning.lua @@ -38,7 +38,7 @@ function Baserunning.new(announcer, onThirdOut) return o end ----@param runner integer | Runner +---@param runner number | Runner ---@param message string | nil ---@return boolean wasThirdOut function Baserunning:outRunner(runner, message) @@ -152,7 +152,7 @@ function Baserunning:pushNewBatter() end ---@param self table ----@param runnerIndex integer +---@param runnerIndex number function Baserunning:runnerScored(runnerIndex) -- TODO: outRunners/scoredRunners split self.outRunners[#self.outRunners + 1] = self.runners[runnerIndex] @@ -161,7 +161,7 @@ end --- Returns true only if the given runner moved during this update. ---@param runner Runner | nil ----@param runnerIndex integer | nil May only be nil if runner == batter +---@param runnerIndex number | nil May only be nil if runner == batter ---@param appliedSpeed number ---@param deltaSeconds number ---@return boolean runnerMoved, boolean runnerScored diff --git a/src/main.lua b/src/main.lua index a4f78b0..c6a2860 100644 --- a/src/main.lua +++ b/src/main.lua @@ -266,13 +266,12 @@ end function Game:nextHalfInning() pitchTracker:reset() local homeScore, awayScore = utils.totalScores(self.state.stats) - -- TODO end the game if away team just batted and home team is winning - local gameOver = self.state.battingTeam == "home" - and self.state.inning == self.settings.finalInning - and awayScore ~= homeScore + local isFinalInning = self.state.inning >= self.settings.finalInning + local gameOver = isFinalInning and self.state.battingTeam == "home" and awayScore ~= homeScore + gameOver = gameOver or self.state.battingTeam == "away" and isFinalInning and homeScore > awayScore if gameOver then - self.announcer:say("AND THAT'S THE BALL GAME!") + self.announcer:say("THAT'S THE BALL GAME!") playdate.timer.new(3000, function() transitionTo(BoxScore.new(self.state.stats)) end) diff --git a/src/test/testBaserunning.lua b/src/test/testBaserunning.lua index a27a707..d94fc02 100644 --- a/src/test/testBaserunning.lua +++ b/src/test/testBaserunning.lua @@ -11,7 +11,7 @@ function buildBaserunning() return baserunning, thirdOutCallbackData end ----@alias BaseIndexOrXyPair (integer | XyPair) +---@alias BaseIndexOrXyPair (number | XyPair) --- NOTE: in addition to the given runners, there is implicitly a batter running from first. ---@param runnerLocations BaseIndexOrXyPair[] @@ -44,7 +44,7 @@ end ---@param expected boolean ---@param fielderWithBallAt XyPair ----@param when integer[][] +---@param when number[][] function assertRunnerOutCondition(expected, when, fielderWithBallAt) local msg = expected and "out" or "safe" for _, runnersOn in ipairs(when) do