Use : instead of . in self function definitions
This commit is contained in:
parent
c56cae6527
commit
aadaa6e0d6
|
@ -24,7 +24,7 @@ actionQueue = {
|
||||||
---@param name string
|
---@param name string
|
||||||
---@param maxTimeMs number
|
---@param maxTimeMs number
|
||||||
---@param action Action
|
---@param action Action
|
||||||
function actionQueue.upsert(self, name, maxTimeMs, action)
|
function actionQueue:upsert(name, maxTimeMs, action)
|
||||||
if action(0) ~= ActionResult.NeedsMoreTime then
|
if action(0) ~= ActionResult.NeedsMoreTime then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -37,7 +37,7 @@ end
|
||||||
|
|
||||||
--- Must be called on every playdate.update() to check for (and run) any waiting tasks.
|
--- Must be called on every playdate.update() to check for (and run) any waiting tasks.
|
||||||
--- Actions that return NeedsMoreTime will not be removed from the queue unless they have expired.
|
--- Actions that return NeedsMoreTime will not be removed from the queue unless they have expired.
|
||||||
function actionQueue.runWaiting(self, deltaSeconds)
|
function actionQueue:runWaiting(deltaSeconds)
|
||||||
local currentTimeMs = playdate.getCurrentTimeMilliseconds()
|
local currentTimeMs = playdate.getCurrentTimeMilliseconds()
|
||||||
for name, actionObject in pairs(self.queue) do
|
for name, actionObject in pairs(self.queue) do
|
||||||
local result = actionObject.action(deltaSeconds)
|
local result = actionObject.action(deltaSeconds)
|
||||||
|
|
|
@ -18,7 +18,7 @@ announcer = {
|
||||||
|
|
||||||
local DurationMs <const> = 3000
|
local DurationMs <const> = 3000
|
||||||
|
|
||||||
function announcer.popIn(self)
|
function announcer:popIn()
|
||||||
self.animatorY = AnnouncerAnimatorInY
|
self.animatorY = AnnouncerAnimatorInY
|
||||||
self.animatorY:reset()
|
self.animatorY:reset()
|
||||||
|
|
||||||
|
@ -39,14 +39,14 @@ function announcer.popIn(self)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
function announcer.say(self, text)
|
function announcer:say(text)
|
||||||
self.textQueue[#self.textQueue + 1] = text
|
self.textQueue[#self.textQueue + 1] = text
|
||||||
if #self.textQueue == 1 then
|
if #self.textQueue == 1 then
|
||||||
self:popIn()
|
self:popIn()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function announcer.draw(self, x, y)
|
function announcer:draw(x, y)
|
||||||
if #self.textQueue == 0 then
|
if #self.textQueue == 0 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
|
@ -27,7 +27,7 @@ baserunning = {
|
||||||
|
|
||||||
---@param runner integer | Runner
|
---@param runner integer | Runner
|
||||||
---@param message string | nil
|
---@param message string | nil
|
||||||
function baserunning.outRunner(self, runner, message)
|
function baserunning:outRunner(runner, message)
|
||||||
self.outs = self.outs + 1
|
self.outs = self.outs + 1
|
||||||
if type(runner) ~= "number" then
|
if type(runner) ~= "number" then
|
||||||
for i, maybe in ipairs(self.runners) do
|
for i, maybe in ipairs(self.runners) do
|
||||||
|
@ -55,7 +55,7 @@ function baserunning.outRunner(self, runner, message)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function baserunning.outEligibleRunners(self, fielder)
|
function baserunning:outEligibleRunners(fielder)
|
||||||
local touchedBase = utils.isTouchingBase(fielder.x, fielder.y)
|
local touchedBase = utils.isTouchingBase(fielder.x, fielder.y)
|
||||||
local didOutRunner = false
|
local didOutRunner = false
|
||||||
for i, runner in pairs(self.runners) do
|
for i, runner in pairs(self.runners) do
|
||||||
|
@ -76,7 +76,7 @@ function baserunning.outEligibleRunners(self, fielder)
|
||||||
return didOutRunner
|
return didOutRunner
|
||||||
end
|
end
|
||||||
|
|
||||||
function baserunning.updateForcedRunners(self)
|
function baserunning:updateForcedRunners()
|
||||||
local stillForced = true
|
local stillForced = true
|
||||||
for _, base in ipairs(C.Bases) do
|
for _, base in ipairs(C.Bases) do
|
||||||
local runnerTargetingBase = utils.getRunnerWithNextBase(self.runners, base)
|
local runnerTargetingBase = utils.getRunnerWithNextBase(self.runners, base)
|
||||||
|
@ -93,7 +93,7 @@ function baserunning.updateForcedRunners(self)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@param deltaSeconds number
|
---@param deltaSeconds number
|
||||||
function baserunning.walkAwayOutRunners(self, deltaSeconds)
|
function baserunning:walkAwayOutRunners(deltaSeconds)
|
||||||
for i, runner in ipairs(self.outRunners) do
|
for i, runner in ipairs(self.outRunners) do
|
||||||
if runner.x < C.Screen.W + 50 and runner.y < C.Screen.H + 50 then
|
if runner.x < C.Screen.W + 50 and runner.y < C.Screen.H + 50 then
|
||||||
runner.x = runner.x + (deltaSeconds * 25)
|
runner.x = runner.x + (deltaSeconds * 25)
|
||||||
|
@ -105,7 +105,7 @@ function baserunning.walkAwayOutRunners(self, deltaSeconds)
|
||||||
end
|
end
|
||||||
|
|
||||||
---@return Runner
|
---@return Runner
|
||||||
function baserunning.newRunner(self)
|
function baserunning:newRunner()
|
||||||
local new = {
|
local new = {
|
||||||
x = C.RightHandedBattersBox.x - 60,
|
x = C.RightHandedBattersBox.x - 60,
|
||||||
y = C.RightHandedBattersBox.y + 60,
|
y = C.RightHandedBattersBox.y + 60,
|
||||||
|
@ -121,7 +121,7 @@ baserunning.batter = baserunning:newRunner()
|
||||||
|
|
||||||
---@param self table
|
---@param self table
|
||||||
---@param runnerIndex integer
|
---@param runnerIndex integer
|
||||||
function baserunning.runnerScored(self, runnerIndex)
|
function baserunning:runnerScored(runnerIndex)
|
||||||
-- TODO: outRunners/scoredRunners split
|
-- TODO: outRunners/scoredRunners split
|
||||||
self.outRunners[#self.outRunners + 1] = self.runners[runnerIndex]
|
self.outRunners[#self.outRunners + 1] = self.runners[runnerIndex]
|
||||||
table.remove(self.runners, runnerIndex)
|
table.remove(self.runners, runnerIndex)
|
||||||
|
@ -133,7 +133,7 @@ end
|
||||||
---@param appliedSpeed number
|
---@param appliedSpeed number
|
||||||
---@param deltaSeconds number
|
---@param deltaSeconds number
|
||||||
---@return boolean runnerMoved, boolean runnerScored
|
---@return boolean runnerMoved, boolean runnerScored
|
||||||
function baserunning.updateRunner(self, runner, runnerIndex, appliedSpeed, deltaSeconds)
|
function baserunning:updateRunner(runner, runnerIndex, appliedSpeed, deltaSeconds)
|
||||||
local autoRunSpeed = 20 * deltaSeconds
|
local autoRunSpeed = 20 * deltaSeconds
|
||||||
|
|
||||||
if not runner or not runner.nextBase then
|
if not runner or not runner.nextBase then
|
||||||
|
@ -188,7 +188,7 @@ end
|
||||||
--- Returns true only if at least one of the given runners moved during this update
|
--- Returns true only if at least one of the given runners moved during this update
|
||||||
---@param appliedSpeed number
|
---@param appliedSpeed number
|
||||||
---@return boolean someRunnerMoved, number runnersScored
|
---@return boolean someRunnerMoved, number runnersScored
|
||||||
function baserunning.updateRunning(self, appliedSpeed, forcedOnly, deltaSeconds)
|
function baserunning:updateRunning(appliedSpeed, forcedOnly, deltaSeconds)
|
||||||
local someRunnerMoved = false
|
local someRunnerMoved = false
|
||||||
local runnersScored = 0
|
local runnersScored = 0
|
||||||
|
|
||||||
|
|
|
@ -27,7 +27,7 @@ Field = {
|
||||||
|
|
||||||
--- Actually only benches the infield, because outfielders are far away!
|
--- Actually only benches the infield, because outfielders are far away!
|
||||||
---@param position XYPair
|
---@param position XYPair
|
||||||
function Field.benchTo(self, position)
|
function Field:benchTo(position)
|
||||||
self.fielders.first.target = position
|
self.fielders.first.target = position
|
||||||
self.fielders.second.target = position
|
self.fielders.second.target = position
|
||||||
self.fielders.shortstop.target = position
|
self.fielders.shortstop.target = position
|
||||||
|
@ -38,7 +38,7 @@ end
|
||||||
|
|
||||||
--- Resets the target positions of all fielders to their defaults (at their field positions).
|
--- Resets the target positions of all fielders to their defaults (at their field positions).
|
||||||
---@param fromOffTheField XYPair | nil If provided, also sets all runners' current position to one centralized location.
|
---@param fromOffTheField XYPair | nil If provided, also sets all runners' current position to one centralized location.
|
||||||
function Field.resetFielderPositions(self, fromOffTheField)
|
function Field:resetFielderPositions(fromOffTheField)
|
||||||
if fromOffTheField then
|
if fromOffTheField then
|
||||||
for _, fielder in pairs(self.fielders) do
|
for _, fielder in pairs(self.fielders) do
|
||||||
fielder.x = fromOffTheField.x
|
fielder.x = fromOffTheField.x
|
||||||
|
@ -76,7 +76,7 @@ end
|
||||||
---@param self table
|
---@param self table
|
||||||
---@param ballDestX number
|
---@param ballDestX number
|
||||||
---@param ballDestY number
|
---@param ballDestY number
|
||||||
function Field.haveSomeoneChase(self, ballDestX, ballDestY)
|
function Field:haveSomeoneChase(ballDestX, ballDestY)
|
||||||
local chasingFielder = utils.getNearestOf(self.fielders, ballDestX, ballDestY)
|
local chasingFielder = utils.getNearestOf(self.fielders, ballDestX, ballDestY)
|
||||||
chasingFielder.target = { x = ballDestX, y = ballDestY }
|
chasingFielder.target = { x = ballDestX, y = ballDestY }
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ end
|
||||||
---@param ball XYPair
|
---@param ball XYPair
|
||||||
---@param deltaSeconds number
|
---@param deltaSeconds number
|
||||||
---@return Fielder | nil fielderTouchingBall nil if no fielder is currently touching the ball
|
---@return Fielder | nil fielderTouchingBall nil if no fielder is currently touching the ball
|
||||||
function Field.updateFielderPositions(self, ball, deltaSeconds)
|
function Field:updateFielderPositions(ball, deltaSeconds)
|
||||||
local fielderTouchingBall = nil
|
local fielderTouchingBall = nil
|
||||||
for _, fielder in pairs(self.fielders) do
|
for _, fielder in pairs(self.fielders) do
|
||||||
local isTouchingBall = updateFielderPosition(deltaSeconds, fielder, ball)
|
local isTouchingBall = updateFielderPosition(deltaSeconds, fielder, ball)
|
||||||
|
@ -127,7 +127,7 @@ end
|
||||||
---@param targetBase Base
|
---@param targetBase Base
|
||||||
---@param throwBall ThrowBall
|
---@param throwBall ThrowBall
|
||||||
---@param throwFlyMs number
|
---@param throwFlyMs number
|
||||||
function Field.playerThrowTo(self, targetBase, throwBall, throwFlyMs)
|
function Field:playerThrowTo(targetBase, throwBall, throwFlyMs)
|
||||||
local maxTryTimeMs = 5000
|
local maxTryTimeMs = 5000
|
||||||
actionQueue:upsert('playerThrowTo', maxTryTimeMs, function()
|
actionQueue:upsert('playerThrowTo', maxTryTimeMs, function()
|
||||||
return playerThrowToImpl(self, targetBase, throwBall, throwFlyMs)
|
return playerThrowToImpl(self, targetBase, throwBall, throwFlyMs)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import 'CoreLibs/graphics.lua'
|
||||||
import 'CoreLibs/object.lua'
|
import 'CoreLibs/object.lua'
|
||||||
import 'CoreLibs/timer.lua'
|
import 'CoreLibs/timer.lua'
|
||||||
import 'CoreLibs/ui.lua'
|
import 'CoreLibs/ui.lua'
|
||||||
|
-- stylua: ignore end
|
||||||
|
|
||||||
--- @alias Fielder {
|
--- @alias Fielder {
|
||||||
--- x: number,
|
--- x: number,
|
||||||
|
@ -18,6 +19,7 @@ import 'CoreLibs/ui.lua'
|
||||||
|
|
||||||
---@alias ThrowBall fun(destX: number, destY: number, easingFunc: EasingFunc, flyTimeMs: number | nil, floaty: boolean | nil, customBallScaler: pd_animator | nil)
|
---@alias ThrowBall fun(destX: number, destY: number, easingFunc: EasingFunc, flyTimeMs: number | nil, floaty: boolean | nil, customBallScaler: pd_animator | nil)
|
||||||
|
|
||||||
|
-- stylua: ignore start
|
||||||
import 'utils.lua'
|
import 'utils.lua'
|
||||||
import 'constants.lua'
|
import 'constants.lua'
|
||||||
import 'assets.lua'
|
import 'assets.lua'
|
||||||
|
|
Loading…
Reference in New Issue