Add generic derivations and To/FromJSON instances
This commit is contained in:
@@ -1,15 +1,18 @@
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE StrictData #-}
|
||||
module Dodge.Creature.Memory.Data
|
||||
where
|
||||
import GHC.Generics
|
||||
import Data.Aeson
|
||||
import Geometry.Data
|
||||
|
||||
import Control.Lens
|
||||
|
||||
data Memory = Memory
|
||||
{ _soundsToInvestigate :: [Point2]
|
||||
, _nodesSearched :: [Int]
|
||||
}
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON Memory where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON Memory
|
||||
makeLenses ''Memory
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE StrictData #-}
|
||||
module Dodge.Creature.Perception.Data
|
||||
@@ -20,10 +21,11 @@ module Dodge.Creature.Perception.Data
|
||||
, auDist
|
||||
)
|
||||
where
|
||||
import GHC.Generics
|
||||
import Data.Aeson
|
||||
import Control.Lens
|
||||
import Dodge.Data.FloatFunction
|
||||
import qualified IntMapHelp as IM
|
||||
|
||||
data Perception = Perception
|
||||
{ _cpVigilance :: Vigilance
|
||||
, _cpAttention :: Attention
|
||||
@@ -31,38 +33,50 @@ data Perception = Perception
|
||||
, _cpVision :: Vision
|
||||
, _cpAudition :: Audition
|
||||
}
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON Perception where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON Perception
|
||||
data Vision = Eyes
|
||||
{ _viFOV :: FloatFloat
|
||||
, _viDist :: FloatFloat
|
||||
}
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON Vision where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON Vision
|
||||
newtype Audition = Ears
|
||||
{ _auDist :: FloatFloat
|
||||
}
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON Audition where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON Audition
|
||||
data Vigilance
|
||||
= Comatose
|
||||
| Asleep
|
||||
| Lethargic
|
||||
| Vigilant
|
||||
| Overstrung
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON Vigilance where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON Vigilance
|
||||
data Attention
|
||||
= AttentiveTo {_getAttentiveTo :: IM.IntMap Awareness }
|
||||
| Fixated {_getFixated :: Int }
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON Attention where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON Attention
|
||||
data Awareness
|
||||
= Suspicious Float
|
||||
| Cognizant Float
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
makeLenses ''Attention
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON Awareness where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON Awareness
|
||||
makeLenses ''Perception
|
||||
makeLenses ''Vision
|
||||
makeLenses ''Audition
|
||||
makeLenses ''Attention
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE StrictData #-}
|
||||
module Dodge.Creature.Stance.Data
|
||||
where
|
||||
import GHC.Generics
|
||||
import Data.Aeson
|
||||
import Geometry.Data
|
||||
|
||||
import Control.Lens
|
||||
@@ -10,8 +13,10 @@ data Stance = Stance
|
||||
,_posture :: Posture
|
||||
,_strideLength :: Int
|
||||
}
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON Stance where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON Stance
|
||||
data Carriage
|
||||
= Walking
|
||||
{ _strideAmount :: Int
|
||||
@@ -21,19 +26,25 @@ data Carriage
|
||||
| Floating
|
||||
| Flying
|
||||
| Boosting Point2
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON Carriage where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON Carriage
|
||||
data FootForward
|
||||
= LeftForward
|
||||
| RightForward
|
||||
| WasLeftForward
|
||||
| WasRightForward
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON FootForward where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON FootForward
|
||||
data Posture = Aiming
|
||||
| AtEase
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON Posture where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON Posture
|
||||
makeLenses ''Stance
|
||||
makeLenses ''Carriage
|
||||
makeLenses ''Posture
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
{-# LANGUAGE DeriveGeneric #-}
|
||||
{-# LANGUAGE TemplateHaskell #-}
|
||||
{-# LANGUAGE StrictData #-}
|
||||
module Dodge.Creature.State.Data
|
||||
where
|
||||
import GHC.Generics
|
||||
import Data.Aeson
|
||||
--import Geometry
|
||||
import Geometry.Data
|
||||
import Color
|
||||
@@ -12,11 +15,17 @@ data CreatureDropType
|
||||
= DropAll
|
||||
| DropAmount Int
|
||||
| DropSpecific [Int]
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON CreatureDropType where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON CreatureDropType
|
||||
data CrSpState
|
||||
= Barrel { _piercedPoints :: [Point2]}
|
||||
| GenCr
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON CrSpState where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON CrSpState
|
||||
data Faction
|
||||
= GenericFaction Int
|
||||
| ZombieFaction
|
||||
@@ -26,7 +35,10 @@ data Faction
|
||||
| NoFaction
|
||||
| ColorFaction Color
|
||||
| PlayerFaction
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON Faction where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON Faction
|
||||
data CrGroup
|
||||
= LoneWolf
|
||||
| Swarm
|
||||
@@ -35,5 +47,9 @@ data CrGroup
|
||||
}
|
||||
| CrGroupID { _crGroupID :: Int }
|
||||
| ShieldGroup
|
||||
deriving (Eq,Ord,Show,Read)
|
||||
deriving (Eq,Ord,Show,Read,Generic)
|
||||
instance ToJSON CrGroup where
|
||||
toEncoding = genericToEncoding defaultOptions
|
||||
instance FromJSON CrGroup
|
||||
makeLenses ''CrSpState
|
||||
makeLenses ''CrGroup
|
||||
|
||||
@@ -9,6 +9,7 @@ import LensHelp
|
||||
|
||||
import Data.Maybe
|
||||
import Data.Strict.IntMap.Autogen.Merge.Strict
|
||||
--import Data.IntMap.Merge.Strict
|
||||
|
||||
getCrDexterity :: Creature -> Int
|
||||
getCrDexterity cr = _dexterity (_crStatistics cr)
|
||||
|
||||
Reference in New Issue
Block a user