From 5c9e0c90614deb200f8981fd04aa471dca725030 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Sat, 24 Aug 2019 22:31:03 +0200 Subject: [PATCH] Get rid of modules rendered obsolete by recent refactoring --- hanafuda-webapp.cabal | 2 -- src/JSON.hs | 27 --------------------------- src/Player.hs | 27 --------------------------- src/Server.hs | 13 ++++++------- 4 files changed, 6 insertions(+), 63 deletions(-) delete mode 100644 src/JSON.hs delete mode 100644 src/Player.hs diff --git a/hanafuda-webapp.cabal b/hanafuda-webapp.cabal index 883e88e..962e0cb 100644 --- a/hanafuda-webapp.cabal +++ b/hanafuda-webapp.cabal @@ -26,9 +26,7 @@ executable hanafudapi , Config , Messaging , Game - , JSON , Data - , Player , Server , Session -- other-extensions: diff --git a/src/JSON.hs b/src/JSON.hs deleted file mode 100644 index 10100c6..0000000 --- a/src/JSON.hs +++ /dev/null @@ -1,27 +0,0 @@ -module JSON ( - defaultOptions - , distinct - , singleLCField - ) where - -import Data.Char (toLower) -import Data.Aeson ( - Options(..) - , SumEncoding(..) - , defaultOptions - ) - -first :: (a -> a) -> [a] -> [a] -first _ [] = [] -first f (x:xs) = f x:xs - -singleLCField :: Options -singleLCField = defaultOptions { - constructorTagModifier = (toLower `first`) - , sumEncoding = ObjectWithSingleField - } - -distinct :: Options -distinct = defaultOptions { - sumEncoding = UntaggedValue - } diff --git a/src/Player.hs b/src/Player.hs deleted file mode 100644 index 7647638..0000000 --- a/src/Player.hs +++ /dev/null @@ -1,27 +0,0 @@ -{-# LANGUAGE NamedFieldPuns #-} -{-# LANGUAGE DeriveGeneric #-} -{-# LANGUAGE MultiParamTypeClasses #-} -{-# LANGUAGE GeneralizedNewtypeDeriving #-} -module Player ( - T(..) - ) where - -import Data.Text (Text) -import GHC.Generics - -data T = T { - name :: Text - } deriving (Eq, Ord, Generic) - -{- -instance FromJSON Key -instance ToJSON Key where - toEncoding = genericToEncoding JSON.defaultOptions - -instance ToJSONKey Key where - toJSONKey = toJSONKeyText (pack . \(Key n) -> show n) - -instance FromJSON Name -instance ToJSON Name where - toEncoding = genericToEncoding JSON.defaultOptions --} diff --git a/src/Server.hs b/src/Server.hs index 3cf5da0..e9b979a 100644 --- a/src/Server.hs +++ b/src/Server.hs @@ -24,11 +24,10 @@ import Data.Text (Text) import Hanafuda.KoiKoi (Game, GameID, PlayerID) import Hanafuda.Message (PlayerStatus(..), Room) import qualified Data (RW(..)) -import qualified Player (T(..)) import qualified Session (Status(..), T(..), Update) type Names = Set Text -type Players = Map PlayerID Player.T +type Players = Map PlayerID Text type Sessions = Map PlayerID Session.T type Games = Map GameID Game data T = T { @@ -54,8 +53,8 @@ instance Data.RW Games T where get = games set games server = server {games} -export :: Sessions -> PlayerID -> Player.T -> PlayerStatus -export sessions playerID player = PlayerStatus (Player.name player, alone) +export :: Sessions -> PlayerID -> Text -> PlayerStatus +export sessions playerID playerName = PlayerStatus (playerName, alone) where alone = case Session.status (sessions ! playerID) of @@ -96,7 +95,7 @@ endGame playerID = logIn :: Text -> PlayerID -> T -> Either String T logIn name playerID server = Data.update (Set.insert name) . - Data.update (insert playerID $ Player.T {Player.name}) . + Data.update (insert playerID name) . update playerID (Data.set $ Session.LoggedIn True :: Session.Update) <$> if name `member` names server then Left "This name is already registered" @@ -106,8 +105,8 @@ logOut :: PlayerID -> T -> T logOut playerID server = maybe server - (\player -> + (\playerName -> Data.update (delete playerID :: Players -> Players) $ update playerID (Data.set $ Session.LoggedIn False :: Session.Update) $ - Data.update (Set.delete $ Player.name player :: Names -> Names) server) + Data.update (Set.delete playerName :: Names -> Names) server) (players server !? playerID)