diff options
Diffstat (limited to 'haskell/src/SpaceTraders/Model/Waypoint.hs')
-rw-r--r-- | haskell/src/SpaceTraders/Model/Waypoint.hs | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/haskell/src/SpaceTraders/Model/Waypoint.hs b/haskell/src/SpaceTraders/Model/Waypoint.hs new file mode 100644 index 0000000..d18cc11 --- /dev/null +++ b/haskell/src/SpaceTraders/Model/Waypoint.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE OverloadedStrings #-} + +module SpaceTraders.Model.Waypoint + ( Waypoint(..) + ) where + +import Data.Aeson +import qualified Data.Text as T +import GHC.Generics + +data Waypoint = Waypoint { symbol :: T.Text + , waypointType :: T.Text + , x :: Int + , y :: Int + } deriving (Generic, Show) +instance FromJSON Waypoint where + parseJSON = withObject "Waypoint" $ \o -> + Waypoint <$> o .: "symbol" + <*> o .: "type" + <*> o .: "x" + <*> o .: "y" +instance ToJSON Waypoint where + toEncoding (Waypoint s t xx yy) = pairs ( "symbol" .= s + <> "type" .= t + <> "x" .= xx + <> "y" .= yy ) |