Files
loop/src/Dodge/Item/Display.hs
T

135 lines
4.7 KiB
Haskell

module Dodge.Item.Display (
itemDisplay,
selectedItemDisplay,
itemString,
itemBaseName,
) where
import Dodge.Item.Info
import Data.Maybe
import Data.Sequence
import Dodge.Data.Creature
import Dodge.Item.SlotsTaken
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
NoItemType -> show "NoItemType"
CRAFT str -> show str
HELD hit -> case hit ^? xNum of
Just i -> takeWhile (/= ' ') (show hit) ++ show i
Nothing -> show hit
LEFT lit -> show lit
EQUIP eit -> show eit
Consumable cit -> show cit
selectedItemDisplay :: Creature -> Item -> [String]
selectedItemDisplay cr it = itemDisplayWithNumber (showSelectedConsumption cr (_itUse it)) it
-- | Displays the item name, ammo if loaded, and any selected '_itCharMode'.
showSelectedConsumption :: Creature -> ItemUse -> String
showSelectedConsumption cr iu = case iu of
HeldUse{} -> showReloadProgress cr (iu ^?! heldConsumption . laSource)
LeftUse{} -> showAutoRechargeProgress (_leftConsumption iu)
EquipUse{_equipEffect = ee} -> showEquipmentNumber ee
_ -> show $ iu ^?! useAmount . getItAmount -- partial, be careful if adding new data constructors
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)
showReloadProgress :: Creature -> AmmoSource -> String
showReloadProgress cr ic = case cr ^? crManipulation . manObject . inInventory . iselAction of
Just (ReloadAction i la) -> show i ++ showLoadActionType la ic
_ -> case ic of
InternalSource ia -> case ia ^? iaProgress . _Just . ix 0 of
Nothing -> show $ ia ^. iaLoaded
Just la -> show (_actionTime la) ++ showLoadActionType la ic
ExternalSource ea -> fromMaybe "X" $ do
i <- ea ^? _Just
itm <- cr ^? crInv . ix i
return $ show $ itemBaseName itm
showConsumption :: ItemUse -> String
showConsumption iu = case iu of
HeldUse{} -> showReloadProgress' (_heldConsumption iu)
LeftUse{} -> showAutoRechargeProgress (_leftConsumption iu)
EquipUse{_equipEffect = ee} -> showEquipmentNumber ee
_ -> show $ iu ^?! useAmount . getItAmount
showEquipmentNumber :: EquipEffect -> String
showEquipmentNumber ee = case _eeUse ee of
EFuelSource x _ -> show x
EAmmoSource {_euseAmmoAmount = x} -> showIntKMG' x
EBatterySource {_euseBatteryAmount = x} -> show x
_ -> ""
showReloadProgress' :: HeldConsumption -> String
showReloadProgress' ic = case ic ^? laSource of
Just (InternalSource ia) -> case ia ^? iaProgress . _Just . ix 0 of
Nothing -> fromMaybe "" $ do
x <- ic ^? laSource . _InternalSource . iaLoaded
return $ show x
Just la -> show (_actionTime la) ++ showLoadActionType la (_laSource ic)
Just (ExternalSource ea) -> fromMaybe "X" $ do
i <- ea ^? _Just
return $ show i
_ -> ""
showLoadActionType :: LoadAction -> AmmoSource -> String
showLoadActionType la as = case la of
LoadEject{} -> "E"
LoadInsert{} -> "L"
LoadAdd{} -> "A" ++ x
LoadPrime{} -> "P"
where
x = maybe "" show $ as ^? _InternalSource . iaLoaded
maybeWarmupStatus :: Item -> Maybe String
maybeWarmupStatus it = case it ^? itUse . heldDelay . warmMax of
Nothing -> Nothing
Just m -> case m - (_warmTime . _heldDelay $ _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 ^? itUse . heldScroll of
Just HeldScrollCharMode{_hsCharMode = (c :<| _)} -> Just [' ', c]
_ -> Nothing
maybeRateStatus :: Item -> Maybe String
maybeRateStatus it = case it ^? itUse . heldDelay . rateMaxMax of
Nothing -> Nothing
_ -> Just $ leftPad 3 ' ' (show (_rateMax . _heldDelay $ _itUse it))