Cleanup
This commit is contained in:
+75
-71
@@ -1,105 +1,109 @@
|
||||
module Dodge.Item.Display
|
||||
( itemDisplay
|
||||
, selectedItemDisplay
|
||||
, itemString
|
||||
)
|
||||
where
|
||||
import Dodge.Module
|
||||
import Dodge.Data
|
||||
import Dodge.Inventory.ItemSpace
|
||||
import Padding
|
||||
import LensHelp
|
||||
module Dodge.Item.Display (
|
||||
itemDisplay,
|
||||
selectedItemDisplay,
|
||||
itemString,
|
||||
) where
|
||||
|
||||
import Data.Maybe
|
||||
import Data.Sequence
|
||||
import Dodge.Data
|
||||
import Dodge.Inventory.ItemSpace
|
||||
import Dodge.Module
|
||||
import LensHelp
|
||||
import Padding
|
||||
|
||||
itemDisplay :: Item -> [String]
|
||||
itemDisplay it = itemDisplayWithNumber (showConsumption (_itUse it)) it
|
||||
|
||||
itemDisplayWithNumber :: String -> Item -> [String]
|
||||
itemDisplayWithNumber numberstr it =
|
||||
Prelude.take (itSlotsTaken it) $
|
||||
(midPadL 15 ' ' thename (' ' : numberstr) ++ theparam) :
|
||||
catMaybes [maybeWarmupStatus it, maybeRateStatus it]
|
||||
++ moduleStrings it
|
||||
++ repeat "*"
|
||||
where
|
||||
thename = itemBaseName it
|
||||
theparam =
|
||||
fromMaybe []
|
||||
. listToMaybe
|
||||
$ mapMaybe
|
||||
($ it)
|
||||
[ maybeModeStatus
|
||||
]
|
||||
|
||||
itemString :: Item -> String
|
||||
itemString = head . itemDisplay
|
||||
|
||||
itemBaseName :: Item -> String
|
||||
itemBaseName it = case _iyBase $ _itType it of
|
||||
itemBaseName it = case _iyBase $ _itType it of
|
||||
CRAFT str -> show str
|
||||
HELD hit -> case hit ^? xNum of
|
||||
Just i -> takeWhile (/=' ') (show hit) ++ show i
|
||||
HELD hit -> case hit ^? xNum of
|
||||
Just i -> takeWhile (/= ' ') (show hit) ++ show i
|
||||
Nothing -> show hit
|
||||
x -> show x
|
||||
|
||||
itemDisplayWithNumber :: String -> Item -> [String]
|
||||
itemDisplayWithNumber numberstr it = Prelude.take (itSlotsTaken it) $
|
||||
(midPadL 15 ' ' thename (' ' : numberstr) ++ theparam)
|
||||
: catMaybes [maybeWarmupStatus it,maybeRateStatus it]
|
||||
++ moduleStrings it ++ repeat "*"
|
||||
where
|
||||
thename = itemBaseName it
|
||||
theparam = fromMaybe []
|
||||
. listToMaybe
|
||||
$ mapMaybe ($ it)
|
||||
[ maybeModeStatus
|
||||
]
|
||||
LEFT lit -> show lit
|
||||
EQUIP eit -> show eit
|
||||
Consumable cit -> show cit
|
||||
|
||||
selectedItemDisplay :: Creature -> Item -> [String]
|
||||
selectedItemDisplay cr it = itemDisplayWithNumber (showSelectedConsumption cr (_itConsumption it)) it
|
||||
selectedItemDisplay cr it = itemDisplayWithNumber (showSelectedConsumption cr (_itUse it)) it
|
||||
|
||||
{- | Displays the item name, ammo if loaded, and any selected '_itCharMode'. -}
|
||||
-- TODO make work on remote launchers
|
||||
itemDisplay :: Item -> [String]
|
||||
itemDisplay it = itemDisplayWithNumber (showConsumption (_itConsumption it)) it
|
||||
-- | Displays the item name, ammo if loaded, and any selected '_itCharMode'.
|
||||
showSelectedConsumption :: Creature -> ItemUse -> String
|
||||
showSelectedConsumption cr iu = case iu of
|
||||
RightUse{} -> showReloadProgress cr (_heldConsumption iu)
|
||||
LeftUse{} -> showAutoRechargeProgress (_leftConsumption iu)
|
||||
EquipUse{} -> ""
|
||||
_ -> show $ iu ^?! useAmount . getItAmount -- partial, be careful if adding new data constructors
|
||||
|
||||
showSelectedConsumption :: Creature -> ItemConsumption -> String
|
||||
showSelectedConsumption cr ic = case ic of
|
||||
LoadableAmmo{} -> showReloadProgress cr ic
|
||||
AutoRecharging {} -> showAutoRechargeProgress ic
|
||||
ChargeableAmmo{} -> show $ _wpCharge ic
|
||||
ItemItselfConsumable{} -> show (_icAmount ic)
|
||||
NoConsumption -> ""
|
||||
showAutoRechargeProgress :: LeftConsumption -> String
|
||||
showAutoRechargeProgress lc = case lc of
|
||||
AutoRecharging{}
|
||||
| _arLoaded lc < _arMax lc -> show (_arProgress lc) ++ "C" ++ show (_arLoaded lc)
|
||||
| otherwise -> show (_arLoaded lc)
|
||||
ChargeableAmmo{} -> show (_wpCharge lc)
|
||||
|
||||
showAutoRechargeProgress :: ItemConsumption -> String
|
||||
showAutoRechargeProgress ic
|
||||
| l < _arMax ic = show (_arProgress ic) ++ "C" ++ show l
|
||||
| otherwise = show l
|
||||
where
|
||||
l = _arLoaded ic
|
||||
|
||||
showReloadProgress :: Creature -> ItemConsumption -> String
|
||||
showReloadProgress :: Creature -> HeldConsumption -> String
|
||||
showReloadProgress cr ic = case cr ^?! crInvSel . iselAction of
|
||||
ReloadAction i la _ -> show i ++ showLoadActionType la (_laLoaded ic)
|
||||
_ -> case ic ^? laProgress . _Just . ix 0 of
|
||||
Nothing -> show $ _laLoaded ic
|
||||
Just la -> show (_actionTime la) ++ showLoadActionType la (_laLoaded ic)
|
||||
|
||||
showLoadProgress :: Int -> Maybe [LoadAction] -> String
|
||||
showLoadProgress x mlas = case mlas ^? _Just . ix 0 of
|
||||
Just la -> show (_actionTime la) ++ showLoadActionType la x
|
||||
Nothing -> show x
|
||||
showConsumption :: ItemUse -> String
|
||||
showConsumption iu = case iu of
|
||||
RightUse{} -> showReloadProgress' (_heldConsumption iu)
|
||||
LeftUse{} -> showAutoRechargeProgress (_leftConsumption iu)
|
||||
EquipUse{} -> ""
|
||||
_ -> show $ iu ^?! useAmount . getItAmount
|
||||
|
||||
showConsumption :: ItemConsumption -> String
|
||||
showConsumption ic = case ic of
|
||||
LoadableAmmo{} -> showLoadProgress (_laLoaded ic) (_laProgress ic)
|
||||
AutoRecharging {} -> showAutoRechargeProgress ic
|
||||
ChargeableAmmo{} -> show $ _wpCharge ic
|
||||
ItemItselfConsumable{} -> show (_icAmount ic)
|
||||
NoConsumption -> ""
|
||||
showReloadProgress' :: HeldConsumption -> String
|
||||
showReloadProgress' ic = case ic ^? laProgress . _Just . ix 0 of
|
||||
Nothing -> show $ _laLoaded ic
|
||||
Just la -> show (_actionTime la) ++ showLoadActionType la (_laLoaded ic)
|
||||
|
||||
showLoadActionType :: LoadAction -> Int -> String
|
||||
showLoadActionType la x = case la of
|
||||
LoadEject {} -> "E"
|
||||
LoadInsert {} -> "L"
|
||||
LoadAdd {} -> "A" ++ show x
|
||||
LoadPrime {} -> "P"
|
||||
LoadEject{} -> "E"
|
||||
LoadInsert{} -> "L"
|
||||
LoadAdd{} -> "A" ++ show x
|
||||
LoadPrime{} -> "P"
|
||||
|
||||
maybeWarmupStatus :: Item -> Maybe String
|
||||
maybeWarmupStatus it = case it ^? itUse . useDelay . warmMax of
|
||||
Nothing -> Nothing
|
||||
Just m -> case m - (_warmTime . _useDelay $ _itUse it) of
|
||||
x | x <= 1 -> Just "*WARM"
|
||||
| otherwise -> let n = show x
|
||||
in Just $ Prelude.take (5 - Prelude.length n) "*WARM" ++ n
|
||||
Just m -> case m - (_warmTime . _useDelay $ _itUse it) of
|
||||
x
|
||||
| x <= 1 -> Just "*WARM"
|
||||
| otherwise ->
|
||||
let n = show x
|
||||
in Just $ Prelude.take (5 - Prelude.length n) "*WARM" ++ n
|
||||
|
||||
maybeModeStatus :: Item -> Maybe String
|
||||
maybeModeStatus it = case it ^? itAttachment of
|
||||
Just AttachCharMode {_atCharMode = (c :<| _)} -> Just [' ',c]
|
||||
Just AttachMode {_atMode = i} -> Just $ show i
|
||||
_ -> Nothing
|
||||
maybeModeStatus it = case it ^? itUse . heldScroll of
|
||||
Just HeldScrollCharMode{_hsCharMode = (c :<| _)} -> Just [' ', c]
|
||||
Just HeldScrollInt{_hsInt = i} -> Just $ show i
|
||||
_ -> Nothing
|
||||
|
||||
maybeRateStatus :: Item -> Maybe String
|
||||
maybeRateStatus it = case it ^? itUse . useDelay . rateMaxMax of
|
||||
|
||||
Reference in New Issue
Block a user