module Dodge.Item.Display ( itemDisplay, selectedItemDisplay, itemString, ) where import Data.Maybe import Data.Sequence import Dodge.Data.Creature 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 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 (_heldConsumption iu) LeftUse{} -> showAutoRechargeProgress (_leftConsumption iu) EquipUse{} -> "" _ -> 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 -> HeldConsumption -> String showReloadProgress cr ic = case cr ^? crInvSel . isel . iselAction of Just (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) showConsumption :: ItemUse -> String showConsumption iu = case iu of HeldUse{} -> showReloadProgress' (_heldConsumption iu) LeftUse{} -> showAutoRechargeProgress (_leftConsumption iu) EquipUse {_equipEffect = ee} -> showEUseNumber ee _ -> show $ iu ^?! useAmount . getItAmount showEUseNumber :: EquipEffect -> String showEUseNumber ee = case _eeUse ee of EFuelSource x _ -> show x _ -> "" 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" 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))