-- selene: allow(unscoped_variables)
C = {}

C.Screen = {
    W = playdate.display.getWidth(),
    H = playdate.display.getHeight(),
}

C.Center = utils.xy(C.Screen.W / 2, C.Screen.H / 2)

C.StrikeZoneStartX = C.Center.x - 16
C.StrikeZoneEndX = C.StrikeZoneStartX + 24
C.StrikeZoneStartY = C.Screen.H - 35

--- @alias Base {
---   x: number,
---   y: number,
--- }

---@type Base[]
C.Bases = {
    utils.xy(C.Screen.W * 0.93, C.Screen.H * 0.52),
    utils.xy(C.Screen.W * 0.47, C.Screen.H * 0.19),
    utils.xy(C.Screen.W * 0.03, C.Screen.H * 0.52),
    utils.xy(C.Screen.W * 0.474, C.Screen.H * 0.79),
}

C.First, C.Second, C.Third, C.Home = 1, 2, 3, 4
C.FieldHeight = C.Bases[C.Home].y - C.Bases[C.Second].y

-- Pseudo-base for batter to target
C.RightHandedBattersBox = {
    x = C.Bases[C.Home].x - 35,
    y = C.Bases[C.Home].y,
}

---@type table<Base, Base | nil>
C.NextBaseMap = {
    [C.RightHandedBattersBox] = nil, -- Runner should not escape the box before a hit!
    [C.Bases[C.First]] = C.Bases[C.Second],
    [C.Bases[C.Second]] = C.Bases[C.Third],
    [C.Bases[C.Third]] = C.Bases[C.Home],
}

--- Angle to align the bat to
C.CrankOffsetDeg = 90

C.DanceBounceMs = 500
C.DanceBounceCount = 4

--- Used to draw the ball well out of bounds, and
--- generally as a check for whether or not it's in play.
C.BallOffscreen = 999

C.PitchAfterSeconds = 7
C.PitchFlyMs = 1050
C.PitchStartX = 195
C.PitchStartY, C.PitchEndY = 105, 240

--- The max distance at which a fielder can tag out a runner.
C.TagDistance = 15

C.BallCatchHitbox = 3

--- The max distance at which a runner can be considered on base.
C.BaseHitbox = 10

C.BattingPower = 20

C.SmallestBallRadius = 6

C.BatLength = 50

-- TODO: enums implemented this way are probably going to be difficult to serialize!

---@alias OffenseState table
--- An enum for what state the offense is in
---@type table<string, OffenseState>
C.Offense = {
    batting = {},
    running = {},
    walking = {},
}

---@alias Side table
--- An enum for which side (offense or defense) a team is on.
---@type table<string, Side>
C.Sides = {
    offense = {},
    defense = {},
}

C.PitcherStartPos = {
    x = C.Screen.W * 0.48,
    y = C.Screen.H * 0.40,
}

C.ThrowMeterMax = 15
C.ThrowMeterDrainPerSec = 150

--- Controls how hard the ball can be hit, and
--- how fast the ball can be thrown.
C.CrankPower = 10

C.PitchPower = 0.3

--- How fast baserunners move after a walk
C.WalkedRunnerSpeed = 10

C.ResetFieldersAfterSeconds = 7
