83 lines
1.9 KiB
Haskell
83 lines
1.9 KiB
Haskell
{-# LANGUAGE DeriveGeneric #-}
|
|
{-# LANGUAGE ScopedTypeVariables #-}
|
|
{-# LANGUAGE StrictData #-}
|
|
{-# LANGUAGE TemplateHaskell #-}
|
|
{-# LANGUAGE FlexibleInstances #-}
|
|
{-# OPTIONS_GHC -fno-warn-orphans #-}
|
|
|
|
{- |
|
|
WARNING: orphan instances concerning Aeson classes and FGL datatypes have been introduced.
|
|
The warnings have been disabled.
|
|
-}
|
|
module Dodge.Data.PathGraph where
|
|
|
|
import LinearHelp
|
|
import Control.Lens
|
|
import Data.Aeson
|
|
import Data.Graph.Inductive
|
|
import Data.Map.Strict (Map)
|
|
import qualified Data.Set as Set
|
|
import Data.Store
|
|
import Data.Store.TH
|
|
import GHC.Generics
|
|
import Geometry.Data
|
|
import TH.Derive
|
|
|
|
data PathGraph = PathGraph
|
|
{ _pgGraph :: Gr Point2 PathEdge
|
|
, _pgNodeMap :: Map Point2 Int
|
|
, _pgNodeCount :: Int
|
|
, _pgEdgeMap :: Map (V2 Point2) (Int, Int, PathEdge)
|
|
}
|
|
deriving (Eq, Show, Read, Generic)
|
|
|
|
instance ToJSON PathGraph where
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
instance FromJSON PathGraph
|
|
|
|
data PathEdge = PathEdge
|
|
{ _peStart :: Point2
|
|
, _peEnd :: Point2
|
|
, _peDist :: Float
|
|
, _peObstacles :: Set.Set EdgeObstacle
|
|
}
|
|
deriving (Eq, Ord, Show, Read, Generic)
|
|
|
|
instance ToJSON PathEdge where
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
instance FromJSON PathEdge
|
|
|
|
data EdgeObstacle
|
|
= BlockObstacle
|
|
| DoorObstacle
|
|
| AutoDoorObstacle
|
|
| WallObstacle
|
|
deriving (Eq, Ord, Show, Read, Bounded, Enum, Generic)
|
|
|
|
instance ToJSON EdgeObstacle where
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
instance FromJSON EdgeObstacle
|
|
|
|
instance (ToJSON a, ToJSON b) => ToJSON (Gr a b) where
|
|
toEncoding = genericToEncoding defaultOptions
|
|
|
|
instance (FromJSON a, FromJSON b) => FromJSON (Gr a b)
|
|
|
|
makeLenses ''PathGraph
|
|
makeLenses ''PathEdge
|
|
|
|
{- FOURMOLU_DISABLE -}
|
|
$($(derive [d|
|
|
instance Deriving (Store EdgeObstacle)
|
|
|]))
|
|
$($(derive [d|
|
|
instance Deriving (Store PathEdge)
|
|
|]))
|
|
$($(derive [d|
|
|
instance Deriving (Store (Gr Point2 PathEdge))
|
|
|]))
|
|
{- FOURMOLU_ENABLE -}
|