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
+20 -6
View File
@@ -1,15 +1,17 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE StrictData #-}
module Dodge.Data.Prop
where
import GHC.Generics
import Data.Aeson
import Dodge.Data.WorldEffect
import Shape.Data
import Color
import qualified Linear.Quaternion as Q
import qualified Quaternion as Q
import Geometry.Data
import ShapePicture.Data
import Control.Lens
data PropDraw = PropDrawSPic SPic
| PropDrawMovingShapeCol Shape
| PropDrawMovingShape PropDraw
@@ -19,7 +21,10 @@ data PropDraw = PropDrawSPic SPic
| PropLampCover Float
| PropDrawToggle PropDraw
| PropDrawGib Float
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON PropDraw where
toEncoding = genericToEncoding defaultOptions
instance FromJSON PropDraw
data PropUpdate -- = UpdatePropZ
= PropUpdateAnd PropUpdate PropUpdate
-- | UpdateShapeProp
@@ -33,11 +38,17 @@ data PropUpdate -- = UpdatePropZ
| PropUpdatePosition WdP2f
| PropUpdateWhen WdBl PropUpdate
| PropUpdateIf WdBl PropUpdate PropUpdate
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON PropUpdate where
toEncoding = genericToEncoding defaultOptions
instance FromJSON PropUpdate
data PrWdLsLs = PrWdLsId
| PrWdLsSetPosition WdP2f Point3
| PrWdLsSetColor Point3
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON PrWdLsLs where
toEncoding = genericToEncoding defaultOptions
instance FromJSON PrWdLsLs
data Prop
= PropZ
{ _prPos :: Point2
@@ -61,5 +72,8 @@ data Prop
, _prRot :: Float
, _prToggle :: Bool
}
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON Prop where
toEncoding = genericToEncoding defaultOptions
instance FromJSON Prop
makeLenses ''Prop