summaryrefslogtreecommitdiff
path: root/haskell/src/SpaceTraders/Model/Waypoint.hs
blob: d80dc7a2908d33b7ac411809f2343e9855d36e1c (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
29
30
31
{-# 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 { orbits :: Maybe T.Text
                         , symbol :: T.Text
                         , waypointType :: T.Text
                         , x :: Int
                         , y :: Int
                         } deriving (Generic, Show)
instance FromJSON Waypoint where
  parseJSON = withObject "Waypoint" $ \o ->
    Waypoint <$> o .:? "orbits"
             <*> o .: "symbol"
             <*> o .: "type"
             <*> o .: "x"
             <*> o .: "y"
instance ToJSON Waypoint where
  toJSON (Waypoint o s t xx yy) = object [ "orbits" .= o
                                         , "symbol" .= s
                                         , "type" .= t
                                         , "x" .= xx
                                         , "y" .= yy ]