diff options
author | Julien Dessaux | 2023-07-04 19:37:50 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-07-04 19:37:50 +0200 |
commit | 78c5467c4ac39869314c686d1d026482e7b3fd8f (patch) | |
tree | 154bc89cd8f9ea87e93d7d638e41f6557daddf22 /haskell/src/SpaceTraders/Model | |
parent | [haskell] Implemented contract (diff) | |
download | spacetraders-78c5467c4ac39869314c686d1d026482e7b3fd8f.tar.gz spacetraders-78c5467c4ac39869314c686d1d026482e7b3fd8f.tar.bz2 spacetraders-78c5467c4ac39869314c686d1d026482e7b3fd8f.zip |
[haskell] Implemented ship
Diffstat (limited to '')
-rw-r--r-- | haskell/src/SpaceTraders/Model/Cargo.hs | 17 | ||||
-rw-r--r-- | haskell/src/SpaceTraders/Model/Fuel.hs | 21 | ||||
-rw-r--r-- | haskell/src/SpaceTraders/Model/Inventory.hs | 17 | ||||
-rw-r--r-- | haskell/src/SpaceTraders/Model/Nav.hs | 20 | ||||
-rw-r--r-- | haskell/src/SpaceTraders/Model/Route.hs | 40 | ||||
-rw-r--r-- | haskell/src/SpaceTraders/Model/Ship.hs | 28 |
6 files changed, 143 insertions, 0 deletions
diff --git a/haskell/src/SpaceTraders/Model/Cargo.hs b/haskell/src/SpaceTraders/Model/Cargo.hs new file mode 100644 index 0000000..126fc63 --- /dev/null +++ b/haskell/src/SpaceTraders/Model/Cargo.hs @@ -0,0 +1,17 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE OverloadedStrings #-} + +module SpaceTraders.Model.Cargo + ( Cargo(..) + ) where + +import Data.Aeson +import GHC.Generics + +import SpaceTraders.Model.Inventory(Inventory) + +data Cargo = Cargo { capacity :: Int + , inventory :: [Inventory] + , units :: Int + } deriving (FromJSON, Generic, Show, ToJSON) diff --git a/haskell/src/SpaceTraders/Model/Fuel.hs b/haskell/src/SpaceTraders/Model/Fuel.hs new file mode 100644 index 0000000..ca17ebb --- /dev/null +++ b/haskell/src/SpaceTraders/Model/Fuel.hs @@ -0,0 +1,21 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE OverloadedStrings #-} + +module SpaceTraders.Model.Fuel + ( Consumed(..) + , Fuel(..) + ) where + +import Data.Aeson +import Data.Time +import GHC.Generics + +data Consumed = Consumed { amount :: Int + , timestamp :: UTCTime + } deriving (FromJSON, Generic, Show, ToJSON) + +data Fuel = Fuel { capacity :: Int + , consumed :: Consumed + , current :: Int + } deriving (FromJSON, Generic, Show, ToJSON) diff --git a/haskell/src/SpaceTraders/Model/Inventory.hs b/haskell/src/SpaceTraders/Model/Inventory.hs new file mode 100644 index 0000000..db74ddb --- /dev/null +++ b/haskell/src/SpaceTraders/Model/Inventory.hs @@ -0,0 +1,17 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE OverloadedStrings #-} + +module SpaceTraders.Model.Inventory + ( Inventory(..) + ) where + +import Data.Aeson +import GHC.Generics +import qualified Data.Text as T + +data Inventory = Inventory { description :: T.Text + , name :: T.Text + , symbol :: T.Text + , units :: Int + } deriving (FromJSON, Generic, Show, ToJSON) diff --git a/haskell/src/SpaceTraders/Model/Nav.hs b/haskell/src/SpaceTraders/Model/Nav.hs new file mode 100644 index 0000000..1c23ca1 --- /dev/null +++ b/haskell/src/SpaceTraders/Model/Nav.hs @@ -0,0 +1,20 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE OverloadedStrings #-} + +module SpaceTraders.Model.Nav + ( Nav(..) + ) where + +import Data.Aeson +import GHC.Generics +import qualified Data.Text as T + +import SpaceTraders.Model.Route + +data Nav = Nav { flightMode :: T.Text + , route :: Route + , status :: T.Text + , systemSymbol :: T.Text + , waypointSymbol :: T.Text + } deriving (FromJSON, Generic, Show, ToJSON) 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 ) diff --git a/haskell/src/SpaceTraders/Model/Ship.hs b/haskell/src/SpaceTraders/Model/Ship.hs new file mode 100644 index 0000000..4228dca --- /dev/null +++ b/haskell/src/SpaceTraders/Model/Ship.hs @@ -0,0 +1,28 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE DeriveGeneric #-} +{-# LANGUAGE OverloadedStrings #-} + +module SpaceTraders.Model.Ship + ( Ship(..) + ) where + +import Data.Aeson +import GHC.Generics +import qualified Data.Text as T + +import SpaceTraders.Model.Cargo +import SpaceTraders.Model.Fuel +import SpaceTraders.Model.Nav + +data Ship = Ship { cargo :: Cargo + --, crew :: Crew + --, engine :: Engine + --, frame :: Frame + , fuel :: Fuel + --, modules :: [Module] + --, mounts :: [Mount] + , nav :: Nav + --, reactor :: Reactor + --, registration :: Registration + , symbol :: T.Text + } deriving (FromJSON, Generic, Show, ToJSON) |