Add saveToFile()
Not *likely* to work yet, but start scoping out good times to make a save. Also, correct the Pitch type.
This commit is contained in:
parent
55a3a7b0ee
commit
176a7e6d5e
|
@ -381,6 +381,10 @@ function Game:strikeOut()
|
|||
self:nextBatter()
|
||||
end
|
||||
|
||||
function Game:saveToFile()
|
||||
playdate.datastore.write(self, "data", true)
|
||||
end
|
||||
|
||||
local SwingBackDeg <const> = 30
|
||||
local SwingForwardDeg <const> = 170
|
||||
|
||||
|
@ -413,6 +417,7 @@ function Game:updateBatting(offenseHandler)
|
|||
end
|
||||
|
||||
-- Hit!
|
||||
self:saveToFile()
|
||||
BatCrackReverb:play()
|
||||
self.state.offenseState = C.Offense.running
|
||||
|
||||
|
@ -440,7 +445,8 @@ function Game:updateBatting(offenseHandler)
|
|||
return
|
||||
end
|
||||
|
||||
if utils.pointIsSquarelyAboveLine(utils.xy(ballDest.x, ballDest.y), C.OutfieldWall) then
|
||||
local isHomeRun = utils.pointIsSquarelyAboveLine(ballDest, C.OutfieldWall)
|
||||
if isHomeRun then
|
||||
playdate.timer.new(flyTimeMs, function()
|
||||
-- Verify that the home run wasn't intercepted
|
||||
if utils.within(1, ball.x, ballDest.x) and utils.within(1, ball.y, ballDest.y) then
|
||||
|
@ -503,6 +509,7 @@ function Game:updatePitching(defenseHandler)
|
|||
end
|
||||
|
||||
if pitchTracker.secondsSinceLastPitch > C.ReturnToPitcherAfterSeconds and not self.state.pitchIsOver then
|
||||
self:saveToFile()
|
||||
local outcome = pitchTracker:updatePitchCounts(self.state.didSwing, self:fieldingTeamCurrentInning())
|
||||
if outcome == PitchOutcomes.StrikeOut then
|
||||
self:strikeOut()
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
---@alias SimpleAnimator { currentValue: fun(self): number; reset: fun(self, durationMs: number | nil) }
|
||||
---@alias Pitch fun(ball: Ball): { x: SimpleAnimator, y: SimpleAnimator, z: SimpleAnimator | nil }
|
||||
---@alias Pitch fun(accuracy: number, ball: Ball): { x: SimpleAnimator, y: SimpleAnimator, z: SimpleAnimator | nil }
|
||||
|
||||
---@type pd_graphics_lib
|
||||
local gfx <const> = playdate.graphics
|
||||
|
|
Loading…
Reference in New Issue