summaryrefslogtreecommitdiff
path: root/haskell/src/SpaceTraders/Model/Waypoint.hs
blob: 458df21d041b65a1cd69b1bbc17ebba06723143d (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 s t xx yy) = object [ "symbol" .= s
                                       , "type" .= t
                                       , "x" .= xx
                                       , "y" .= yy ]