From c4edae978126f81dc48032259eb317a22770ee27 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Wed, 16 Oct 2019 18:44:46 +0200 Subject: [PATCH] Define a public type for players and keep only the player's hand in private information and public game --- src/Hanafuda/Message.hs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Hanafuda/Message.hs b/src/Hanafuda/Message.hs index 86a23eb..4af735c 100644 --- a/src/Hanafuda/Message.hs +++ b/src/Hanafuda/Message.hs @@ -142,14 +142,24 @@ instance ToJSON Hanafuda.Flower where toEncoding = genericToEncoding defaultOptions data PrivateState = PrivateState { - opponent :: Player KoiKoi.Score + opponentHand :: Hanafuda.Pack , deck :: [Hanafuda.Card] } deriving Generic +data PublicPlayer = PublicPlayer { + meld :: Hanafuda.Pack + , yakus :: KoiKoi.Score + } deriving Generic + +instance FromJSON PublicPlayer +instance ToJSON PublicPlayer where + toEncoding = genericToEncoding defaultOptions + data PublicState = PublicState { mode :: KoiKoi.Mode , scores :: Scores KoiKoi.Score , month :: Hanafuda.Flower + , players :: Map PlayerID PublicPlayer , playing :: PlayerID , winning :: PlayerID , oyake :: PlayerID @@ -170,7 +180,7 @@ instance ToJSON ByteString where toEncoding = toEncoding . decodeUtf8 data PublicGame = PublicGame { - player :: Player KoiKoi.Score + playerHand :: Hanafuda.Pack , privateState :: ByteString , publicState :: PublicState , publicSignature :: ByteString @@ -184,7 +194,7 @@ data T = Relay {from :: PlayerID, message :: FromClient} | Welcome {room :: Room, key :: PlayerID} | Update {alone :: [PlayerID], paired :: [PlayerID]} - | Game {game :: PublicGame, logs :: [KoiKoi.Action]} + | Game {state :: PublicGame, logs :: [KoiKoi.Action]} | Pong | Error {error :: String} deriving (Generic)