summaryrefslogtreecommitdiff
path: root/haskell/src/SpaceTraders/Model/Waypoint.hs
blob: b32af7535262f07fee00ae5b0adc4c87ff091e12 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
  toJSON (Waypoint o s t xx yy) = object [ "symbol" .= s
                                         , "type" .= t
                                         , "x" .= xx
                                         , "y" .= yy ]