[haskell] Implemented ship
This commit is contained in:
parent
b3d57cb6ad
commit
78c5467c4a
10 changed files with 169 additions and 8 deletions
17
haskell/src/SpaceTraders/Model/Cargo.hs
Normal file
17
haskell/src/SpaceTraders/Model/Cargo.hs
Normal file
|
@ -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)
|
21
haskell/src/SpaceTraders/Model/Fuel.hs
Normal file
21
haskell/src/SpaceTraders/Model/Fuel.hs
Normal file
|
@ -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)
|
17
haskell/src/SpaceTraders/Model/Inventory.hs
Normal file
17
haskell/src/SpaceTraders/Model/Inventory.hs
Normal file
|
@ -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)
|
20
haskell/src/SpaceTraders/Model/Nav.hs
Normal file
20
haskell/src/SpaceTraders/Model/Nav.hs
Normal file
|
@ -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)
|
40
haskell/src/SpaceTraders/Model/Route.hs
Normal file
40
haskell/src/SpaceTraders/Model/Route.hs
Normal file
|
@ -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 )
|
28
haskell/src/SpaceTraders/Model/Ship.hs
Normal file
28
haskell/src/SpaceTraders/Model/Ship.hs
Normal file
|
@ -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)
|
Loading…
Add table
Add a link
Reference in a new issue