1
0
Fork 0

[haskell] refactoring

This commit is contained in:
Julien Dessaux 2024-03-22 01:13:34 +01:00
parent d668eac4a6
commit 7e27a0a7ea
Signed by: adyxax
GPG key ID: F92E51B86E07177E
26 changed files with 289 additions and 311 deletions

View file

@ -1,19 +1,18 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module SpaceTraders.Model.Agent
( Agent(..)
) where
import Data.Aeson
import GHC.Generics
import qualified Data.Text as T
import Data.Aeson
import qualified Data.Text as T
import GHC.Generics
data Agent = Agent { accountId :: T.Text
, credits :: Integer
data Agent = Agent { accountId :: T.Text
, credits :: Integer
--, faction :: Faction
, headquarters :: T.Text
, headquarters :: T.Text
, startingFaction :: T.Text
, symbol :: T.Text
, symbol :: T.Text
} deriving (Eq, FromJSON, Generic, Show, ToJSON)

View file

@ -1,17 +1,16 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module SpaceTraders.Model.Cargo
( Cargo(..)
) where
import Data.Aeson
import GHC.Generics
import Data.Aeson
import GHC.Generics
import SpaceTraders.Model.Inventory(Inventory)
import SpaceTraders.Model.Inventory (Inventory)
data Cargo = Cargo { capacity :: Int
data Cargo = Cargo { capacity :: Int
, inventory :: [Inventory]
, units :: Int
, units :: Int
} deriving (FromJSON, Generic, Show, ToJSON)

View file

@ -1,21 +1,20 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module SpaceTraders.Model.Fuel
( Consumed(..)
, Fuel(..)
) where
import Data.Aeson
import Data.Time
import GHC.Generics
import Data.Aeson
import Data.Time
import GHC.Generics
data Consumed = Consumed { amount :: Int
data Consumed = Consumed { amount :: Int
, timestamp :: UTCTime
} deriving (FromJSON, Generic, Show, ToJSON)
data Fuel = Fuel { capacity :: Int
, consumed :: Consumed
, current :: Int
, current :: Int
} deriving (FromJSON, Generic, Show, ToJSON)

View file

@ -1,17 +1,16 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module SpaceTraders.Model.Inventory
( Inventory(..)
) where
import Data.Aeson
import GHC.Generics
import qualified Data.Text as T
import Data.Aeson
import qualified Data.Text as T
import GHC.Generics
data Inventory = Inventory { description :: T.Text
, name :: T.Text
, symbol :: T.Text
, units :: Int
, name :: T.Text
, symbol :: T.Text
, units :: Int
} deriving (FromJSON, Generic, Show, ToJSON)

View file

@ -1,20 +1,19 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module SpaceTraders.Model.Nav
( Nav(..)
) where
import Data.Aeson
import GHC.Generics
import qualified Data.Text as T
import Data.Aeson
import qualified Data.Text as T
import GHC.Generics
import SpaceTraders.Model.Route
import SpaceTraders.Model.Route
data Nav = Nav { flightMode :: T.Text
, route :: Route
, status :: T.Text
, systemSymbol :: T.Text
data Nav = Nav { flightMode :: T.Text
, route :: Route
, status :: T.Text
, systemSymbol :: T.Text
, waypointSymbol :: T.Text
} deriving (FromJSON, Generic, Show, ToJSON)

View file

@ -1,34 +1,33 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE DeriveGeneric #-}
module SpaceTraders.Model.Ship
( Ship(..)
) where
import Data.Aeson
import GHC.Generics
import qualified Data.Text as T
import Data.Aeson
import qualified Data.Text as T
import GHC.Generics
import SpaceTraders.Model.Cargo
import SpaceTraders.Model.Fuel
import SpaceTraders.Model.Nav
import SpaceTraders.Model.Cargo
import SpaceTraders.Model.Fuel
import SpaceTraders.Model.Nav
data Ship = Ship { cargo :: Cargo
data Ship = Ship { cargo :: Cargo
, cooldown :: Cooldown
--, crew :: Crew
--, engine :: Engine
--, frame :: Frame
, fuel :: Fuel
, fuel :: Fuel
--, modules :: [Module]
--, mounts :: [Mount]
, nav :: Nav
, nav :: Nav
--, reactor :: Reactor
--, registration :: Registration
, symbol :: T.Text
, symbol :: T.Text
} deriving (FromJSON, Generic, Show, ToJSON)
data Cooldown = Cooldown { shipSymbol :: T.Text
, totalSeconds :: Int
data Cooldown = Cooldown { shipSymbol :: T.Text
, totalSeconds :: Int
, remainingSeconds :: Int
} deriving (FromJSON, Generic, Show, ToJSON)

View file

@ -1,23 +1,22 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module SpaceTraders.Model.System
( System(..)
) where
import Data.Aeson
import qualified Data.Text as T
import GHC.Generics
import Data.Aeson
import qualified Data.Text as T
import GHC.Generics
import SpaceTraders.Model.Waypoint(Waypoint)
import SpaceTraders.Model.Waypoint (Waypoint)
data System = System { sectorSymbol :: T.Text
, symbol :: T.Text
, systemType :: T.Text
, x :: Int
, y :: Int
, waypoints :: [Waypoint]
, symbol :: T.Text
, systemType :: T.Text
, x :: Int
, y :: Int
, waypoints :: [Waypoint]
--, factions :: [Faction]
} deriving (Generic, Show)
instance FromJSON System where

View file

@ -1,20 +1,19 @@
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module SpaceTraders.Model.Waypoint
( Waypoint(..)
) where
import Data.Aeson
import qualified Data.Text as T
import GHC.Generics
import Data.Aeson
import qualified Data.Text as T
import GHC.Generics
data Waypoint = Waypoint { orbits :: Maybe T.Text
, symbol :: T.Text
data Waypoint = Waypoint { orbits :: Maybe T.Text
, symbol :: T.Text
, waypointType :: T.Text
, x :: Int
, y :: Int
, x :: Int
, y :: Int
} deriving (Generic, Show)
instance FromJSON Waypoint where
parseJSON = withObject "Waypoint" $ \o ->