Define a public type for players and keep only the player's hand in private information and public game

This commit is contained in:
Tissevert 2019-10-16 18:44:46 +02:00
parent 65a7c26b5a
commit c4edae9781

View file

@ -142,14 +142,24 @@ instance ToJSON Hanafuda.Flower where
toEncoding = genericToEncoding defaultOptions toEncoding = genericToEncoding defaultOptions
data PrivateState = PrivateState { data PrivateState = PrivateState {
opponent :: Player KoiKoi.Score opponentHand :: Hanafuda.Pack
, deck :: [Hanafuda.Card] , deck :: [Hanafuda.Card]
} deriving Generic } 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 { data PublicState = PublicState {
mode :: KoiKoi.Mode mode :: KoiKoi.Mode
, scores :: Scores KoiKoi.Score , scores :: Scores KoiKoi.Score
, month :: Hanafuda.Flower , month :: Hanafuda.Flower
, players :: Map PlayerID PublicPlayer
, playing :: PlayerID , playing :: PlayerID
, winning :: PlayerID , winning :: PlayerID
, oyake :: PlayerID , oyake :: PlayerID
@ -170,7 +180,7 @@ instance ToJSON ByteString where
toEncoding = toEncoding . decodeUtf8 toEncoding = toEncoding . decodeUtf8
data PublicGame = PublicGame { data PublicGame = PublicGame {
player :: Player KoiKoi.Score playerHand :: Hanafuda.Pack
, privateState :: ByteString , privateState :: ByteString
, publicState :: PublicState , publicState :: PublicState
, publicSignature :: ByteString , publicSignature :: ByteString
@ -184,7 +194,7 @@ data T =
Relay {from :: PlayerID, message :: FromClient} Relay {from :: PlayerID, message :: FromClient}
| Welcome {room :: Room, key :: PlayerID} | Welcome {room :: Room, key :: PlayerID}
| Update {alone :: [PlayerID], paired :: [PlayerID]} | Update {alone :: [PlayerID], paired :: [PlayerID]}
| Game {game :: PublicGame, logs :: [KoiKoi.Action]} | Game {state :: PublicGame, logs :: [KoiKoi.Action]}
| Pong | Pong
| Error {error :: String} | Error {error :: String}
deriving (Generic) deriving (Generic)