Add generic derivations and To/FromJSON instances

This commit is contained in:
2022-07-25 22:49:18 +01:00
parent f5604ef429
commit b8e8413daa
99 changed files with 1406 additions and 517 deletions
+27 -6
View File
@@ -1,37 +1,58 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StrictData #-}
module Dodge.Data.LightSource where
import GHC.Generics
import Data.Aeson
import Geometry
import Control.Lens
data LightSourceDraw = DefaultLightSourceDraw
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON LightSourceDraw where
toEncoding = genericToEncoding defaultOptions
instance FromJSON LightSourceDraw
data TLSIntensity = ConstantIntensity
| TLSFade Point3 Int
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON TLSIntensity where
toEncoding = genericToEncoding defaultOptions
instance FromJSON TLSIntensity
data TLSUpdate = DestroyTLS
| TimerTLS
| IntensityTLS TLSIntensity
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON TLSUpdate where
toEncoding = genericToEncoding defaultOptions
instance FromJSON TLSUpdate
data LSParam = LSParam
{ _lsPos :: !Point3
, _lsRad :: !Float
, _lsCol :: !Point3
}
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON LSParam where
toEncoding = genericToEncoding defaultOptions
instance FromJSON LSParam
data LightSource = LS
{ _lsID :: Int
, _lsParam :: LSParam
, _lsDir :: Float
, _lsPict :: LightSourceDraw --LightSource -> Picture
}
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON LightSource where
toEncoding = genericToEncoding defaultOptions
instance FromJSON LightSource
data TempLightSource = TLS
{ _tlsParam :: LSParam
, _tlsUpdate :: TLSUpdate --TempLightSource -> Maybe TempLightSource
, _tlsTime :: Int
}
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON TempLightSource where
toEncoding = genericToEncoding defaultOptions
instance FromJSON TempLightSource
makeLenses ''LSParam
makeLenses ''LightSource
makeLenses ''TempLightSource