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
+15 -6
View File
@@ -1,11 +1,13 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-}
module Picture.Data
where
import GHC.Generics
import Data.Aeson
import Geometry.Data
import GHC.Generics
import Control.Lens
import Streaming
data Verx = Verx
@@ -15,8 +17,10 @@ data Verx = Verx
, _vxLayer :: !Layer
, _vxShadNum :: !ShadNum
}
deriving (Eq,Ord,Show,Generic,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON Verx where
toEncoding = genericToEncoding defaultOptions
instance FromJSON Verx
data Layer
= BottomLayer
| MidLayer
@@ -24,15 +28,20 @@ data Layer
| BloomNoZWrite
| DebugLayer
| FixedCoordLayer
deriving (Eq,Ord,Enum,Bounded,Show,Generic,Read)
deriving (Eq,Ord,Enum,Bounded,Show,Read,Generic)
instance ToJSON Layer where
toEncoding = genericToEncoding defaultOptions
instance FromJSON Layer
layerNum :: Layer -> Int
layerNum = fromEnum
numLayers :: Int
numLayers = length [minBound::Layer .. maxBound]
--TODO use synonyms for layer numbers
newtype ShadNum = ShadNum { _unShadNum :: Int }
deriving (Eq,Ord,Show,Generic,Read)
deriving (Eq,Ord,Show,Read,Generic)
instance ToJSON ShadNum where
toEncoding = genericToEncoding defaultOptions
instance FromJSON ShadNum
polyNum, polyzNum, bezNum, textNum, arcNum, ellNum :: ShadNum
{-# INLINE polyNum #-}
{-# INLINE polyzNum #-}