From 78c5467c4ac39869314c686d1d026482e7b3fd8f Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 4 Jul 2023 19:37:50 +0200 Subject: [haskell] Implemented ship --- haskell/src/SpaceTraders/Model/Route.hs | 40 +++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 haskell/src/SpaceTraders/Model/Route.hs (limited to 'haskell/src/SpaceTraders/Model/Route.hs') diff --git a/haskell/src/SpaceTraders/Model/Route.hs b/haskell/src/SpaceTraders/Model/Route.hs new file mode 100644 index 0000000..959edff --- /dev/null +++ b/haskell/src/SpaceTraders/Model/Route.hs @@ -0,0 +1,40 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE OverloadedStrings #-} + +module SpaceTraders.Model.Route + ( Route(..) + , RouteEndpoint(..) + ) where + +import Control.Monad +import Data.Aeson +import Data.Time +import GHC.Generics +import qualified Data.Text as T + +data Route = Route { arrival :: UTCTime + , departure :: RouteEndpoint + , departureTime :: UTCTime + , destination :: RouteEndpoint + } deriving (FromJSON, Generic, Show, ToJSON) + +data RouteEndpoint = RouteEndpoint { routeEndpointType :: T.Text + , symbol :: T.Text + , systemSymbol :: T.Text + , x :: Int + , y :: Int + } deriving (Generic, Show) +instance FromJSON RouteEndpoint where + parseJSON (Object o) = RouteEndpoint <$> o .: "type" + <*> o .: "symbol" + <*> o .: "systemSymbol" + <*> o .: "x" + <*> o .: "y" + parseJSON _ = mzero +instance ToJSON RouteEndpoint where + toEncoding (RouteEndpoint t s ss xx yy) = pairs ( "type" .= t + <> "symbol" .= s + <> "systemSymbol" .= ss + <> "x" .= xx + <> "y" .= yy ) -- cgit v1.2.3