Skip to content

Commit

Permalink
Remove player names from URL state
Browse files Browse the repository at this point in the history
These might be added back in future, when needed
  • Loading branch information
Jcparkyn committed Nov 5, 2023
1 parent 4a6b983 commit c6b5c94
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 33 deletions.
16 changes: 8 additions & 8 deletions src/Main.elm
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,6 @@ modelToUrlModel model =
|> List.filterMap (\x -> x)
in
{ turns = PlayedTurn nextTurn :: model.playedTurns
, lastPlayer =
{ name = model.selfName
}
, nextPlayer =
{ name = model.opponent.name
}
, initialSeed = model.initialSeed
}

Expand Down Expand Up @@ -406,6 +400,12 @@ urlModelToModel model flags =

finalState =
List.foldr (getNextGameState wordlist) initialState model.turns

playerName n =
"Player " ++ String.fromInt (n + 1)

turnCount =
List.length model.turns
in
Playing
{ selectedCell = Nothing
Expand All @@ -416,10 +416,10 @@ urlModelToModel model flags =
finalState.nextPlayer.rack
|> Array.map (\tile -> RackTile 0 tile Nothing)
, opponent =
{ name = model.lastPlayer.name
{ name = playerName (turnCount - 1 |> modBy 2)
, score = finalState.lastPlayer.score
}
, selfName = model.nextPlayer.name
, selfName = playerName (turnCount |> modBy 2)
, selfScore = finalState.nextPlayer.score
, playedTurns = model.turns
, initialSeed = model.initialSeed
Expand Down
27 changes: 2 additions & 25 deletions src/UrlState.elm
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module UrlState exposing (DecodeUrlError, UrlModel, UrlPlayer, decodeUrl, getNextUrlState)
module UrlState exposing (DecodeUrlError, UrlModel, decodeUrl, getNextUrlState)

import Base64
import Bytes
Expand All @@ -18,16 +18,10 @@ import UrlBase64

type alias UrlModel =
{ turns : List PlayedTurn
, nextPlayer : UrlPlayer
, lastPlayer : UrlPlayer
, initialSeed : Int
}


type alias UrlPlayer =
{ name : String }


compressToBase64 : String -> String
compressToBase64 str =
str
Expand Down Expand Up @@ -66,25 +60,10 @@ getNextUrlBody : UrlModel -> E.Value
getNextUrlBody model =
E.object
[ ( "turns", E.list encodeTurn model.turns )
, ( "np", encodePlayer model.nextPlayer )
, ( "lp", encodePlayer model.lastPlayer )
, ( "s0", E.int model.initialSeed )
]


encodePlayer : UrlPlayer -> E.Value
encodePlayer player =
E.object
[ ( "n", E.string player.name )
]


decodePlayer : Decoder UrlPlayer
decodePlayer =
D.map UrlPlayer
(D.field "n" D.string)


encodeTurn : PlayedTurn -> E.Value
encodeTurn turn =
case turn of
Expand Down Expand Up @@ -125,10 +104,8 @@ decodeTurn =

decodeModel : Decoder UrlModel
decodeModel =
D.map4 UrlModel
D.map2 UrlModel
(D.field "turns" (D.list decodeTurn))
(D.field "np" decodePlayer)
(D.field "lp" decodePlayer)
(D.field "s0" D.int)


Expand Down

0 comments on commit c6b5c94

Please sign in to comment.