summaryrefslogtreecommitdiff
path: root/haskell/src/SpaceTraders/Model/System.hs
blob: dacd27a3cbb1f9b7e31c1fc2ea2daed34e88f1ea (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
37
{-# LANGUAGE DeriveAnyClass #-}
{-# 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
  toEncoding (System ss s t xx yy w) = pairs ( "sectorSymbol" .= ss
                                          <> "symbol" .= s
                                          <> "type" .= t
                                          <> "x" .= xx
                                          <> "y" .= yy
                                          <> "waypoints" .= w )