Refactor triplet to Selection datatype

This commit is contained in:
2025-08-26 18:13:27 +01:00
parent 9034c409e1
commit b87c3380b8
16 changed files with 127 additions and 135 deletions
+11 -11
View File
@@ -9,6 +9,7 @@ module Dodge.DisplayInventory (
toggleCombineInv,
) where
import Dodge.Data.HUD
import Dodge.Inventory.CheckSlots
import NewInt
import Control.Applicative
@@ -16,7 +17,6 @@ import Control.Lens
import Control.Monad
import Data.IntMap.Merge.Strict
import qualified Data.IntMap.Strict as IM
import Data.IntSet (IntSet)
import Data.Maybe
import Data.Monoid
import Dodge.Base.You
@@ -55,7 +55,7 @@ updateCombineSections w cfig =
(getAvailableListLines secondColumnParams cfig)
(IM.fromDistinctAscList [(-1, sfclose),(0, sclose')])
where
filtcurs = w ^? hud . subInventory . ciSelection . _Just . _1 == Just (-1)
filtcurs = w ^? hud . subInventory . ciSelection . _Just . slSec == Just (-1)
(sfclose, sclose) =
filterSectionsPair
filtcurs
@@ -97,14 +97,14 @@ checkInventorySelectionExists w
| isJust $ w ^? hud . diSections . ix i . ssItems . ix j = w
| otherwise = scrollAugNextInSection w
where
(i, j, _) = fromMaybe (1, -1, mempty) $ w ^? hud . diSelection . _Just
Sel i j _ = fromMaybe (Sel 1 (-1) mempty) $ w ^? hud . diSelection . _Just
checkCombineSelectionExists :: SubInventory -> SubInventory
checkCombineSelectionExists si
| Just sss <- si ^? ciSections
, Just (i, j, _) <- si ^? ciSelection . _Just <|> Just (0, 0, mempty)
, Sel i j _ <- fromMaybe (Sel 0 0 mempty) $ si ^? ciSelection . _Just
, isNothing $ si ^? ciSections . ix i . ssItems . ix j =
si & ciSelection ?~ (0, -1, mempty)
si & ciSelection ?~ Sel 0 (-1) mempty
& ciSelection
%~ scrollSelectionSections (-1) sss
| otherwise = si
@@ -136,11 +136,11 @@ updateDisplaySections w cfig =
)
where
mselpos = w ^? hud . diSelection . _Just
invfiltcurs = mselpos ^? _Just . _1 == Just (-1)
invfiltcurs = mselpos ^? _Just . slSec == Just (-1)
(sfinv, sinv) =
filterSectionsPair invfiltcurs plainRegex invitems "INVENTORY" $
w ^? hud . diInvFilter . _Just
closefiltcurs = mselpos ^? _Just . _1 == Just 2
closefiltcurs = mselpos ^? _Just . slSec == Just 2
(sfclose, sclose) =
filterSectionsPair closefiltcurs plainRegex closeitms "NEARBY ITEMS" $
w ^? hud . diCloseFilter . _Just
@@ -241,7 +241,7 @@ doSectionSize extraavailable mintaken is sss done = fromMaybe done $ do
updateSectionsPositioning ::
(Int -> Int) -> -- for determining each sections indent
Maybe (Int, Int, IntSet) ->
Maybe Selection ->
Int ->
IM.IntMap (IM.IntMap (SelectionItem a)) ->
IM.IntMap (SelectionSection a) ->
@@ -251,13 +251,13 @@ updateSectionsPositioning h mselpos allavailablelines lsss sss =
where
offsets = fmap _ssOffset sss
m k = do
(k', i, _) <- mselpos
Sel k' i _ <- mselpos
guard $ k == k'
return i
ls = lsss
-- defaults non-existing offsets to 0
g = merge (mapMissing (const ($ 0))) dropMissing (zipWithMatched (const ($)))
lk = mselpos ^.. _Just . _1
lk = mselpos ^.. _Just . slSec
ssizes = sectionsSizes allavailablelines lk $ sectionsDesiredLines ls
updateSection ::
@@ -324,7 +324,7 @@ enterCombineInv cfig w =
w & hud . subInventory
.~ CombineInventory
{ _ciSections = updateCombineSections w cfig mempty
, _ciSelection = Just (0,0,mempty)
, _ciSelection = Just (Sel 0 0 mempty)
, _ciFilter = Nothing
}
& hud . diInvFilter .~ Nothing