From d54d97b84d819c7dec8893c85a7931c7431096bc Mon Sep 17 00:00:00 2001 From: Tissevert Date: Thu, 15 Aug 2019 23:38:05 +0200 Subject: [PATCH] Taking stuff out of Game and Message to declare them in the new APILanguage lib --- src/Game.hs | 16 ---------------- src/Message.hs | 27 --------------------------- 2 files changed, 43 deletions(-) diff --git a/src/Game.hs b/src/Game.hs index 2b9cb47..2904580 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -28,13 +28,9 @@ import qualified Hanafuda.Player (Player(..), Players(..)) import qualified Hanafuda.KoiKoi (Action(..), Game(..), Environment, Mode(..), Move(..), Score, Source(..), Step(..), Yaku(..), new, play) import GHC.Generics -deriving instance Generic Hanafuda.Card deriving instance Generic Hanafuda.Flower -deriving instance Generic Hanafuda.KoiKoi.Action deriving instance Generic Hanafuda.KoiKoi.Mode -deriving instance Generic Hanafuda.KoiKoi.Move deriving instance Generic Hanafuda.KoiKoi.Yaku -deriving instance Generic Hanafuda.KoiKoi.Source deriving instance Generic Hanafuda.KoiKoi.Step deriving instance Generic1 (Hanafuda.Player.Player Player.Key) deriving instance Generic1 (Hanafuda.Player.Players Player.Key) @@ -46,26 +42,14 @@ deriving instance Generic T instance ToJSON T where toEncoding = genericToEncoding JSON.defaultOptions -instance FromJSON Hanafuda.Card -instance ToJSON Hanafuda.Card - instance ToJSON Hanafuda.Flower instance ToJSON Hanafuda.Pack where toJSON = toJSON . Hanafuda.cardsOfPack toEncoding = toEncoding . Hanafuda.cardsOfPack -instance ToJSON Hanafuda.KoiKoi.Action - instance ToJSON Hanafuda.KoiKoi.Mode -instance FromJSON Hanafuda.KoiKoi.Move where - parseJSON = genericParseJSON JSON.singleLCField -instance ToJSON Hanafuda.KoiKoi.Move where - toEncoding = genericToEncoding JSON.singleLCField - -instance ToJSON Hanafuda.KoiKoi.Source - instance ToJSON Hanafuda.KoiKoi.Step where toEncoding = genericToEncoding JSON.defaultOptions diff --git a/src/Message.hs b/src/Message.hs index 5ef1771..1720ef0 100644 --- a/src/Message.hs +++ b/src/Message.hs @@ -30,33 +30,6 @@ import qualified App (Context(..), T, connection, debug, server) import qualified Hanafuda.KoiKoi as KoiKoi (Action, Game(..), Move(..)) import GHC.Generics (Generic) -data FromClient = - Answer {accept :: Bool} - | Invitation {to :: Player.Key} - | LogIn {name :: Text} - | LogOut - | Play {move :: KoiKoi.Move} - | Quit - | Ping - deriving (Generic) - -instance ToJSON FromClient where - toEncoding = genericToEncoding defaultOptions -instance FromJSON FromClient where - parseJSON = genericParseJSON defaultOptions - -data T = - Relay {from :: Player.Key, message :: FromClient} - | Welcome {room :: Server.T, key :: Player.Key} - | Update {alone :: [Player.Key], paired :: [Player.Key]} - | Game {game :: Value, logs :: [KoiKoi.Action]} - | Pong - | Error {error :: String} - deriving (Generic) - -instance ToJSON T where - toEncoding = genericToEncoding defaultOptions - sendTo :: [Player.Key] -> T -> App.T () sendTo playerKeys obj = do sessions <- getSessions <$> App.server