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
+19 -5
View File
@@ -3,6 +3,8 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DeriveGeneric #-}
module Dodge.Data.Wall where
import GHC.Generics
import Data.Aeson
import Dodge.Data.Material
import Geometry
import Color
@@ -26,15 +28,24 @@ data Wall = Wall
, _wlHeight :: Float
, _wlMaterial :: Material
}
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON Wall where
toEncoding = genericToEncoding defaultOptions
instance FromJSON Wall
data Opacity
= SeeThrough
| SeeAbove
| DrawnWall {_opDraw :: WallDraw } -- Wall -> SPic
| Opaque
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON Opacity where
toEncoding = genericToEncoding defaultOptions
instance FromJSON Opacity
data WallDraw = DrawForceField
deriving (Eq,Ord,Show,Read,Enum,Bounded)
deriving (Eq,Ord,Show,Read,Enum,Bounded,Generic)
instance ToJSON WallDraw where
toEncoding = genericToEncoding defaultOptions
instance FromJSON WallDraw
data WallStructure
= StandaloneWall
| DoorPart { _wsDoor :: Int }
@@ -44,7 +55,10 @@ data WallStructure
{ _wlStCreature :: Int
-- , _wlStDamCreature :: Damage -> Wall -> Int -> World -> World
}
deriving (Eq,Ord,Show,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON WallStructure where
toEncoding = genericToEncoding defaultOptions
instance FromJSON WallStructure
makeLenses ''Wall
makeLenses ''WallStructure
makeLenses ''Opacity
makeLenses ''WallStructure