Still working on the protocol : remove useless PlayerStatus type
This commit is contained in:
parent
816ecbc331
commit
9c5c80fb3a
1 changed files with 5 additions and 15 deletions
|
@ -6,7 +6,6 @@
|
||||||
module Hanafuda.Message (
|
module Hanafuda.Message (
|
||||||
T(..)
|
T(..)
|
||||||
, FromClient(..)
|
, FromClient(..)
|
||||||
, PlayerStatus(..)
|
|
||||||
, PrivateState(..)
|
, PrivateState(..)
|
||||||
, PublicGame(..)
|
, PublicGame(..)
|
||||||
, PublicPlayer(..)
|
, PublicPlayer(..)
|
||||||
|
@ -69,7 +68,9 @@ instance ToJSON Hanafuda.Card where
|
||||||
toEncoding = genericToEncoding defaultOptions
|
toEncoding = genericToEncoding defaultOptions
|
||||||
|
|
||||||
data FromClient =
|
data FromClient =
|
||||||
Answer {accept :: Bool, to :: PlayerID}
|
Hello
|
||||||
|
| Tadaima {myID :: PlayerID}
|
||||||
|
| Answer {accept :: Bool, to :: PlayerID}
|
||||||
| Invitation {to :: PlayerID}
|
| Invitation {to :: PlayerID}
|
||||||
| LogIn {name :: Text}
|
| LogIn {name :: Text}
|
||||||
| LogOut
|
| LogOut
|
||||||
|
@ -82,19 +83,7 @@ instance FromJSON FromClient
|
||||||
instance ToJSON FromClient where
|
instance ToJSON FromClient where
|
||||||
toEncoding = genericToEncoding defaultOptions
|
toEncoding = genericToEncoding defaultOptions
|
||||||
|
|
||||||
newtype PlayerStatus = PlayerStatus (Text, Bool) deriving (Generic, Show)
|
type Room = Map PlayerID Text
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
deriving instance Generic KoiKoi.Source
|
deriving instance Generic KoiKoi.Source
|
||||||
instance FromJSON KoiKoi.Source
|
instance FromJSON KoiKoi.Source
|
||||||
|
@ -205,6 +194,7 @@ instance ToJSON PublicGame where
|
||||||
data T =
|
data T =
|
||||||
Relay {from :: PlayerID, message :: FromClient}
|
Relay {from :: PlayerID, message :: FromClient}
|
||||||
| Welcome {room :: Room, key :: PlayerID}
|
| Welcome {room :: Room, key :: PlayerID}
|
||||||
|
| Okaeri {room :: Room}
|
||||||
| Game {state :: PublicGame, logs :: [KoiKoi.Action]}
|
| Game {state :: PublicGame, logs :: [KoiKoi.Action]}
|
||||||
| Pong
|
| Pong
|
||||||
| Error {error :: String}
|
| Error {error :: String}
|
||||||
|
|
Loading…
Reference in a new issue