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

View file

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