blob: 9f0776c8d1115bd6a077dcf72231c7458c5e8135 (
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
|
{-# 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 ]
|