From 355c7d08be8a42ddf1f842c42ac4b1a2887492eb Mon Sep 17 00:00:00 2001 From: Tissevert Date: Sat, 8 Dec 2018 18:15:12 +0100 Subject: [PATCH] Take Gender out into a separate module to share it with Characters --- pokeNeige.cabal | 1 + src/Character.hs | 2 ++ src/Gender.hs | 13 +++++++++++++ src/Pokemon.hs | 7 +------ 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 src/Gender.hs diff --git a/pokeNeige.cabal b/pokeNeige.cabal index 6d1de64..ab228b9 100644 --- a/pokeNeige.cabal +++ b/pokeNeige.cabal @@ -26,6 +26,7 @@ executable pokeNeige , Character , Config , Game + , Gender , Item , Message , Message.Client diff --git a/src/Character.hs b/src/Character.hs index 37eeabe..04ebc45 100644 --- a/src/Character.hs +++ b/src/Character.hs @@ -10,12 +10,14 @@ module Character ( import Data.Aeson (ToJSON(..), FromJSON(..), genericToEncoding, genericParseJSON, defaultOptions) import Data.Vector (Vector) import GHC.Generics (Generic) +import Gender (Gender(..)) import qualified Pokemon (T) import Tool.Array (Array, malloc) data Character = Character { name :: String , skin :: FilePath + , gender :: Gender , pokemons :: Array Pokemon.T } deriving (Generic) diff --git a/src/Gender.hs b/src/Gender.hs new file mode 100644 index 0000000..d9b17df --- /dev/null +++ b/src/Gender.hs @@ -0,0 +1,13 @@ +{-# LANGUAGE DeriveGeneric #-} +module Gender ( + Gender(..) + ) where + +import Data.Aeson (ToJSON(..), FromJSON(..), genericToEncoding, defaultOptions) +import GHC.Generics (Generic) + +data Gender = M | F | NB deriving (Generic) + +instance ToJSON Gender where + toEncoding = genericToEncoding defaultOptions +instance FromJSON Gender diff --git a/src/Pokemon.hs b/src/Pokemon.hs index 7552ace..6c24193 100644 --- a/src/Pokemon.hs +++ b/src/Pokemon.hs @@ -6,17 +6,12 @@ module Pokemon ( import Data.Aeson (ToJSON(..), FromJSON(..), genericToEncoding, genericParseJSON, defaultOptions) import GHC.Generics (Generic) +import Gender (Gender) import qualified Pokemon.Species as Species (Key) import Pokemon.Status (Status) import qualified Pokemon.Move as Move (Key) import Tool.Array (Array) -data Gender = M | F | NB deriving (Generic) - -instance ToJSON Gender where - toEncoding = genericToEncoding defaultOptions -instance FromJSON Gender - data T = T { nick :: Maybe String , species :: Species.Key