{-# LANGUAGE PatternSynonyms #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Swarm.Util.Location (Location, pattern Location, Heading, origin, Affine (..)) where
import Data.Aeson (FromJSONKey, ToJSONKey)
import Data.Int (Int32)
import Data.Yaml (FromJSON (parseJSON), ToJSON (toJSON))
import Linear (V2 (..))
import Linear.Affine (Affine (..), Point (..), origin)
type Location = Point V2 Int32
pattern Location :: Int32 -> Int32 -> Location
pattern $bLocation :: Int32 -> Int32 -> Location
$mLocation :: forall {r}. Location -> (Int32 -> Int32 -> r) -> ((# #) -> r) -> r
Location x y = P (V2 x y)
{-# COMPLETE Location #-}
type Heading = V2 Int32
deriving instance ToJSON (V2 Int32)
deriving instance FromJSON (V2 Int32)
deriving instance FromJSONKey (V2 Int32)
deriving instance ToJSONKey (V2 Int32)
instance FromJSON Location where
parseJSON :: Value -> Parser Location
parseJSON = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall (f :: * -> *) a. f a -> Point f a
P forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. FromJSON a => Value -> Parser a
parseJSON
instance ToJSON Location where
toJSON :: Location -> Value
toJSON (P V2 Int32
v) = forall a. ToJSON a => a -> Value
toJSON V2 Int32
v