Skip to content

Commit

Permalink
Reset selection cursor when resetting rack
Browse files Browse the repository at this point in the history
  • Loading branch information
Jcparkyn committed Dec 24, 2023
1 parent 0a6aef2 commit 901b734
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Model
type alias PlayingModel =
{ selectedCell : Maybe Point
, selectDirection : SelectDirection
, lastManualSelectedCell : Maybe Point -- For resetting the cursor to an intuitive position
, board : PostTurnBoardState
, bag : List Tile
, rack : RackState
Expand Down Expand Up @@ -208,6 +209,7 @@ init flags url _ =
( Playing
{ selectedCell = Nothing
, selectDirection = Right
, lastManualSelectedCell = Nothing
, board = initialBoard
, bag = initialState.bag
, rack =
Expand Down Expand Up @@ -423,6 +425,7 @@ urlModelToModel model flags =
Playing
{ selectedCell = Nothing
, selectDirection = Right
, lastManualSelectedCell = Nothing
, board = finalState.board
, bag = finalState.bag
, rack =
Expand Down Expand Up @@ -458,7 +461,7 @@ updatePlaying msg model =
( withPlacedTile model rackIndex, Cmd.none )

ResetRack ->
( { model | rack = resetRackState model.rack }, Cmd.none )
( { model | rack = resetRackState model.rack, selectedCell = model.lastManualSelectedCell }, Cmd.none )

ShuffleRack ->
( model, Random.generate NewRackOrder shuffleRackGenerator )
Expand Down Expand Up @@ -496,6 +499,7 @@ withSelection model point =
Preview _ ->
{ model
| selectedCell = Just point
, lastManualSelectedCell = Just point
, rack =
model.rack
|> Array.map
Expand All @@ -511,6 +515,7 @@ withSelection model point =
Empty ->
{ model
| selectedCell = Just point
, lastManualSelectedCell = Just point
, selectDirection =
if model.selectedCell == Just point then
swapDirection model.selectDirection
Expand Down

0 comments on commit 901b734

Please sign in to comment.