Follow renaming (Key -> ID) in hanafuda lib

This commit is contained in:
Tissevert 2019-08-24 14:53:46 +02:00
parent be593c72d9
commit d52b101bcf
1 changed files with 14 additions and 14 deletions

View File

@ -24,21 +24,21 @@ import Data.Text (Text)
import qualified Data.Text as Text (pack, unpack)
import GHC.Generics (Generic)
import qualified Hanafuda (Card(..), Flower(..), Pack, cardsOfPack, empty, packOfCards)
import Hanafuda.Key (Key(..), getKey)
import Hanafuda.KoiKoi (PlayerKey, GameBlueprint(..))
import Hanafuda.ID (ID(..), getID)
import Hanafuda.KoiKoi (PlayerID, GameBlueprint(..))
import qualified Hanafuda.KoiKoi as KoiKoi (
Action(..), Game(..), Mode(..), Move(..), Score, Source(..), Step(..), Yaku(..)
)
import Hanafuda.Player (Player(..), Players(..))
deriving instance Generic PlayerKey
instance FromJSON PlayerKey
instance FromJSONKey PlayerKey where
fromJSONKey = FromJSONKeyText (Key . read . Text.unpack)
instance ToJSON PlayerKey where
deriving instance Generic PlayerID
instance FromJSON PlayerID
instance FromJSONKey PlayerID where
fromJSONKey = FromJSONKeyText (ID . read . Text.unpack)
instance ToJSON PlayerID where
toEncoding = genericToEncoding defaultOptions
instance ToJSONKey PlayerKey where
toJSONKey = toJSONKeyText (Text.pack . getKey)
instance ToJSONKey PlayerID where
toJSONKey = toJSONKeyText (Text.pack . getID)
first :: (a -> a) -> [a] -> [a]
first _ [] = []
@ -63,7 +63,7 @@ instance ToJSON Hanafuda.Card where
data FromClient =
Answer {accept :: Bool}
| Invitation {to :: PlayerKey}
| Invitation {to :: PlayerID}
| LogIn {name :: Text}
| LogOut
| Play {move :: KoiKoi.Move}
@ -87,7 +87,7 @@ instance ToJSON PlayerStatus where
toEncoding (PlayerStatus (name, alone)) =
pairs ("name" .= name <> "alone" .= alone)
type Room = Map PlayerKey PlayerStatus
type Room = Map PlayerID PlayerStatus
deriving instance Generic KoiKoi.Source
instance FromJSON KoiKoi.Source
@ -147,9 +147,9 @@ instance ToJSON PublicGame where
toEncoding = genericToEncoding defaultOptions
data T =
Relay {from :: PlayerKey, message :: FromClient}
| Welcome {room :: Room, key :: PlayerKey}
| Update {alone :: [PlayerKey], paired :: [PlayerKey]}
Relay {from :: PlayerID, message :: FromClient}
| Welcome {room :: Room, key :: PlayerID}
| Update {alone :: [PlayerID], paired :: [PlayerID]}
| Game {game :: PublicGame, logs :: [KoiKoi.Action]}
| Pong
| Error {error :: String}