Add generic derivations and To/FromJSON instances
This commit is contained in:
+15
-6
@@ -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 #-}
|
||||
|
||||
Reference in New Issue
Block a user