Still working on the protocol : remove useless PlayerStatus type

This commit is contained in:
Tissevert 2019-10-28 08:18:48 +01:00
parent 816ecbc331
commit 9c5c80fb3a

View file

@ -6,7 +6,6 @@
module Hanafuda.Message (
T(..)
, FromClient(..)
, PlayerStatus(..)
, PrivateState(..)
, PublicGame(..)
, PublicPlayer(..)
@ -69,7 +68,9 @@ instance ToJSON Hanafuda.Card where
toEncoding = genericToEncoding defaultOptions
data FromClient =
Answer {accept :: Bool, to :: PlayerID}
Hello
| Tadaima {myID :: PlayerID}
| Answer {accept :: Bool, to :: PlayerID}
| Invitation {to :: PlayerID}
| LogIn {name :: Text}
| LogOut
@ -82,19 +83,7 @@ instance FromJSON FromClient
instance ToJSON FromClient where
toEncoding = genericToEncoding defaultOptions
newtype PlayerStatus = PlayerStatus (Text, Bool) deriving (Generic, Show)
instance FromJSON PlayerStatus where
parseJSON = withObject "PlayerStatus" $ \v -> fmap PlayerStatus . (,)
<$> v .: "name"
<*> v .: "alone"
instance ToJSON PlayerStatus where
toJSON (PlayerStatus (name, alone)) =
object ["name" .= name, "alone" .= alone]
toEncoding (PlayerStatus (name, alone)) =
pairs ("name" .= name <> "alone" .= alone)
type Room = Map PlayerID PlayerStatus
type Room = Map PlayerID Text
deriving instance Generic KoiKoi.Source
instance FromJSON KoiKoi.Source
@ -205,6 +194,7 @@ instance ToJSON PublicGame where
data T =
Relay {from :: PlayerID, message :: FromClient}
| Welcome {room :: Room, key :: PlayerID}
| Okaeri {room :: Room}
| Game {state :: PublicGame, logs :: [KoiKoi.Action]}
| Pong
| Error {error :: String}