Skip to content

Commit

Permalink
Rename types
Browse files Browse the repository at this point in the history
  • Loading branch information
w0rm committed Nov 17, 2023
1 parent 7da4d67 commit 1f8f533
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 39 deletions.
74 changes: 37 additions & 37 deletions src/Game.elm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ type alias Model =

type State
= PlacingBall BallInHand PoolWithBallInHand
| Playing PlayingMouse Cue (Pool EightBall.AwaitingPlayerShot)
| Shooting AimingCue Shot (Pool EightBall.AwaitingPlayerShot)
| Simulating (List ( Posix, ShotEvent )) (Pool EightBall.AwaitingPlayerShot)
| GameOver Player (Pool EightBall.AwaitingStart)

Expand All @@ -86,8 +86,8 @@ type PoolWithBallInHand
| Anywhere (Pool EightBall.AwaitingPlaceBallInHand)


type alias Cue =
{ elevation : Angle
type alias Shot =
{ cueElevation : Angle
, shootPressedAt : Maybe Posix

-- polar coordinates of the hit point on the surface of the cue ball
Expand All @@ -96,17 +96,17 @@ type alias Cue =
}


initialCue : Cue
initialCue =
{ elevation = Angle.degrees 5
initialShot : Shot
initialShot =
{ cueElevation = Angle.degrees 5
, shootPressedAt = Nothing
, hitRelativeAzimuth = Angle.degrees 0
, hitElevation = Angle.degrees 0
}


type PlayingMouse
= HoveringCueBall { hitRelativeAzimuth : Angle, hitElevation : Angle }
type AimingCue
= TargetingCueBall { hitRelativeAzimuth : Angle, hitElevation : Angle }
| ElevatingCue (Point2d Pixels ScreenCoordinates)
| OutsideOfCueBall

Expand Down Expand Up @@ -225,7 +225,7 @@ view ({ world, ballTextures, roughnessTexture, window } as model) =
PlacingBall OutsideOfTable (BehindHeadString _) ->
Bodies.areaBehindTheHeadStringEntity :: entities

Playing _ cue _ ->
Shooting _ cue _ ->
let
axis =
cueAxis (cueBallPosition model.world) model.azimuth cue
Expand Down Expand Up @@ -267,8 +267,8 @@ view ({ world, ballTextures, roughnessTexture, window } as model) =

{-| Axis from the hit point on the cue ball along the cue
-}
cueAxis : Point3d Meters WorldCoordinates -> Timeline Angle -> Cue -> Axis3d Meters WorldCoordinates
cueAxis ballPosition cameraAzimuthTimeline { hitRelativeAzimuth, elevation, hitElevation } =
cueAxis : Point3d Meters WorldCoordinates -> Timeline Angle -> Shot -> Axis3d Meters WorldCoordinates
cueAxis ballPosition cameraAzimuthTimeline { hitRelativeAzimuth, cueElevation, hitElevation } =
let
cameraAzimuth =
angleFromTimeline cameraAzimuthTimeline
Expand All @@ -284,7 +284,7 @@ cueAxis ballPosition cameraAzimuthTimeline { hitRelativeAzimuth, elevation, hitE
Point3d.translateIn pointDirection Bodies.ballRadius ballPosition

axisDirection =
Direction3d.xyZ cameraAzimuth elevation
Direction3d.xyZ cameraAzimuth cueElevation
in
Axis3d.through pointOnCueBall axisDirection

Expand Down Expand Up @@ -340,7 +340,7 @@ canShoot axis world =
viewShootingStrength : Model -> Html Msg
viewShootingStrength { state, time, window } =
case state of
Playing _ { shootPressedAt } _ ->
Shooting _ { shootPressedAt } _ ->
case shootPressedAt of
Nothing ->
Html.text ""
Expand Down Expand Up @@ -395,10 +395,10 @@ currentCursor state =
PlacingBall (OnTable _ _) _ ->
"none"

Playing (HoveringCueBall _) _ _ ->
Shooting (TargetingCueBall _) _ _ ->
"pointer"

Playing (ElevatingCue _) _ _ ->
Shooting (ElevatingCue _) _ _ ->
"ns-resize"

Simulating _ _ ->
Expand All @@ -416,7 +416,7 @@ currentPlayer state =
PlacingBall _ (BehindHeadString pool) ->
EightBall.currentPlayer pool

Playing _ _ pool ->
Shooting _ _ pool ->
EightBall.currentPlayer pool

Simulating _ pool ->
Expand Down Expand Up @@ -444,7 +444,7 @@ currentTarget state =
PlacingBall _ (BehindHeadString pool) ->
EightBall.currentTarget pool

Playing _ _ pool ->
Shooting _ _ pool ->
EightBall.currentTarget pool

Simulating _ pool ->
Expand Down Expand Up @@ -543,7 +543,7 @@ update msg model =
cueBallPosition newModel.world
in
{ newModel
| state = Playing OutsideOfCueBall initialCue newPool
| state = Shooting OutsideOfCueBall initialShot newPool
, focalPoint = Animator.go Animator.quickly newFocalPoint newModel.focalPoint
}

Expand Down Expand Up @@ -598,7 +598,7 @@ update msg model =
EightBall.placeBallInHand model.time pool
in
{ model
| state = Playing OutsideOfCueBall initialCue newPool
| state = Shooting OutsideOfCueBall initialShot newPool
, world = World.add (Body.moveTo position Bodies.cueBall) model.world
, focalPoint = Animator.go Animator.quickly position model.focalPoint
}
Expand All @@ -608,15 +608,15 @@ update msg model =
PlacingBall (OnTable CannotPlace _) _ ->
model

Playing (HoveringCueBall { hitRelativeAzimuth, hitElevation }) cue pool ->
Shooting (TargetingCueBall { hitRelativeAzimuth, hitElevation }) cue pool ->
let
newCue =
{ cue
| hitRelativeAzimuth = hitRelativeAzimuth
, hitElevation = hitElevation
}
in
{ model | state = Playing (ElevatingCue mousePosition) newCue pool }
{ model | state = Shooting (ElevatingCue mousePosition) newCue pool }

_ ->
{ model | orbiting = Just mousePosition }
Expand Down Expand Up @@ -648,34 +648,34 @@ update msg model =
in
{ model | state = PlacingBall newBallInHand pool }

Playing (ElevatingCue originalPosition) cue pool ->
Shooting (ElevatingCue originalPosition) cue pool ->
let
newElevation =
cueElevation originalPosition mousePosition model.zoom cue.elevation
elevateCue originalPosition mousePosition model.zoom cue.cueElevation

newCue =
{ cue | elevation = newElevation }
{ cue | cueElevation = newElevation }
in
{ model | state = Playing (ElevatingCue mousePosition) newCue pool }
{ model | state = Shooting (ElevatingCue mousePosition) newCue pool }

Playing _ cue pool ->
Shooting _ cue pool ->
let
mouseRay =
Camera3d.ray (camera model) model.window mousePosition

newMouse =
hoverCueBall mouseRay model.world model.azimuth
in
{ model | state = Playing newMouse cue pool }
{ model | state = Shooting newMouse cue pool }

_ ->
model

MouseUp ->
case model.state of
Playing _ cue pool ->
Shooting _ cue pool ->
{ model
| state = Playing OutsideOfCueBall cue pool
| state = Shooting OutsideOfCueBall cue pool
, orbiting = Nothing
}

Expand All @@ -684,7 +684,7 @@ update msg model =

ShootPressed ->
case model.state of
Playing mouse cue pool ->
Shooting mouse cue pool ->
let
axis =
cueAxis (cueBallPosition model.world) model.azimuth cue
Expand All @@ -697,7 +697,7 @@ update msg model =
newCue =
{ cue | shootPressedAt = Just model.time }
in
{ model | state = Playing mouse newCue pool }
{ model | state = Shooting mouse newCue pool }

else
model
Expand All @@ -707,7 +707,7 @@ update msg model =

ShootReleased ->
case model.state of
Playing mouse cue pool ->
Shooting mouse cue pool ->
let
axis =
cueAxis (cueBallPosition model.world) model.azimuth cue
Expand All @@ -722,13 +722,13 @@ update msg model =
}

_ ->
{ model | state = Playing mouse { cue | shootPressedAt = Nothing } pool }
{ model | state = Shooting mouse { cue | shootPressedAt = Nothing } pool }

_ ->
model


hoverCueBall : Axis3d Meters WorldCoordinates -> World Id -> Timeline Angle -> PlayingMouse
hoverCueBall : Axis3d Meters WorldCoordinates -> World Id -> Timeline Angle -> AimingCue
hoverCueBall mouseRay world azimuthTimeline =
case World.raycast mouseRay world of
Just { body, normal } ->
Expand Down Expand Up @@ -758,7 +758,7 @@ hoverCueBall mouseRay world azimuthTimeline =
Quantity.lessThan (Angle.degrees 90) (Quantity.abs hitRelativeAzimuth)
in
if Body.data body == CueBall && hoveringFrontHemisphere then
HoveringCueBall
TargetingCueBall
{ hitRelativeAzimuth = hitRelativeAzimuth
, hitElevation = hitElevation
}
Expand Down Expand Up @@ -803,8 +803,8 @@ mouseOrbiting originalPosition newPosition model =
The precision depends on the zoom level.
-}
cueElevation : Point2d Pixels ScreenCoordinates -> Point2d Pixels ScreenCoordinates -> Timeline Float -> Angle -> Angle
cueElevation originalPosition newPosition zoomTimeline elevation =
elevateCue : Point2d Pixels ScreenCoordinates -> Point2d Pixels ScreenCoordinates -> Timeline Float -> Angle -> Angle
elevateCue originalPosition newPosition zoomTimeline elevation =
let
radiansInPixels =
orbitingPrecision zoomTimeline
Expand Down
3 changes: 1 addition & 2 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ viewCurrentStatus gameModel assetsPath =
]
[ Html.node "style"
[]
[ Html.text (fontStyle assetsPath)
]
[ Html.text (fontStyle assetsPath) ]
, case gameModel.state of
Game.GameOver _ _ ->
viewGameOver gameModel
Expand Down

0 comments on commit 1f8f533

Please sign in to comment.