From 9c5c80fb3a87acaa853710b88a4a5f0a6658ac81 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Mon, 28 Oct 2019 08:18:48 +0100 Subject: [PATCH] Still working on the protocol : remove useless PlayerStatus type --- src/Hanafuda/Message.hs | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/Hanafuda/Message.hs b/src/Hanafuda/Message.hs index bcc99b0..35556ac 100644 --- a/src/Hanafuda/Message.hs +++ b/src/Hanafuda/Message.hs @@ -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}