summaryrefslogtreecommitdiff
path: root/haskell/src/SpaceTraders/Model/System.hs
blob: a673b566079634d63715bcbbb63c5199c4c1b4e5 (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
32
33
34
35
36
{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE OverloadedStrings #-}

module SpaceTraders.Model.System
  ( System(..)
  ) where

import           Data.Aeson
import qualified Data.Text                   as T
import           GHC.Generics

import           SpaceTraders.Model.Waypoint (Waypoint)

data System = System { sectorSymbol :: T.Text
                     , symbol       :: T.Text
                     , systemType   :: T.Text
                     , x            :: Int
                     , y            :: Int
                     , waypoints    :: [Waypoint]
                     --, factions :: [Faction]
                     } deriving (Generic, Show)
instance FromJSON System where
  parseJSON = withObject "System" $ \o ->
    System <$> o .: "sectorSymbol"
           <*> o .: "symbol"
           <*> o .: "type"
           <*> o .: "x"
           <*> o .: "y"
           <*> o .: "waypoints"
instance ToJSON System where
  toJSON (System ss s t xx yy w) = object [ "sectorSymbol" .= ss
                                          , "symbol" .= s
                                          , "type" .= t
                                          , "x" .= xx
                                          , "y" .= yy
                                          , "waypoints" .= w ]