From 31a74b9ac0a5ffd0b4d06217b45e964d244cb386 Mon Sep 17 00:00:00 2001 From: justin Date: Sat, 4 Jan 2025 15:56:40 +0000 Subject: [PATCH] Add strict tuples --- src/Dodge/DisplayInventory.hs | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/Dodge/DisplayInventory.hs b/src/Dodge/DisplayInventory.hs index c1b5dea2b..0aec5d03d 100644 --- a/src/Dodge/DisplayInventory.hs +++ b/src/Dodge/DisplayInventory.hs @@ -8,6 +8,7 @@ module Dodge.DisplayInventory ( toggleCombineInv, ) where +import qualified Data.Strict.Tuple as STup import Control.Applicative import Control.Lens import Control.Monad @@ -90,10 +91,9 @@ updateInventoryPositioning u = %~ checkInventorySelectionExists checkInventorySelectionExists :: World -> World -checkInventorySelectionExists w = - case w ^? hud . hudElement . diSections . ix i . ssItems . ix j of - Nothing -> scrollAugNextInSection w - _ -> w +checkInventorySelectionExists w + | isJust $ w ^? hud . hudElement . diSections . ix i . ssItems . ix j = w + | otherwise = scrollAugNextInSection w where (i, j, _) = fromMaybe (1, -1, mempty) $ w ^? hud . hudElement . diSelection . _Just @@ -279,14 +279,8 @@ updateSectionsPositioning f h mselpos allavailablelines lsss sss = ls = IM.fromList lsss -- defaults non-existing offsets to 0 g = merge (mapMissing (const ($ 0))) dropMissing (zipWithMatched (const ($))) - --lk = maybe [] ((: []) . fst) mselpos lk = mselpos ^.. _Just . _1 - ssizes = - sectionsSizes - allavailablelines - f - lk - $ sectionsDesiredLines ls + ssizes = sectionsSizes allavailablelines f lk $ sectionsDesiredLines ls updateSection :: Int -> @@ -300,7 +294,7 @@ updateSection indent mcsel sis availablelines oldoffset = { _ssItems = sis , _ssOffset = offset , _ssShownItems = - tweakfirst . tweaklast . map snd $ + tweakfirst . tweaklast . map (^. _2) $ take availablelines shownstrings , _ssIndent = indent } @@ -335,10 +329,10 @@ updateSection indent mcsel sis availablelines oldoffset = allstrings = foldMap listSelectionColorPicture sis shownstrings = drop offset allstrings -listSelectionColorPicture :: SelectionItem a -> [(Color, Picture)] +listSelectionColorPicture :: SelectionItem a -> [STup.Pair Color Picture] listSelectionColorPicture si = g <$> _siPictures si where - g str = (_siColor si, translate lindent 0 . color (_siColor si) $ text str) + g str = _siColor si STup.:!: translate lindent 0 (color (_siColor si) $ text str) lindent = 100 * fromIntegral (_siOffX si) regexList :: String -> [String] -> Bool