Continue inventory refactor

This commit is contained in:
2024-11-24 22:08:36 +00:00
parent 81fcfea1be
commit 82c53fc8e3
10 changed files with 187 additions and 149 deletions
+19 -14
View File
@@ -129,15 +129,10 @@ updateCloseObjects w =
& hud . closeItems %~ f
& hud . closeInterfaces %~ g
where
-- the following should update any changed properties of flits/bts
g oldbts = intersectBy bteq cbts oldbts `btunion` cbts
f olditems = intersectBy feq citems olditems `itunion` citems
itunion = unionBy feq
btunion = unionBy bteq
feq = (==) `on` _flItID
bteq = (==) `on` _btID
cbts = filter (isclose . _btPos) activeButtons
citems =
g oldbts = intersect oldbts cbts `union` cbts
f olditems = intersect olditems citems `union` citems
cbts = fmap _btID $ filter (isclose . _btPos) activeButtons
citems = fmap _flItID .
filter (isclose . _flItPos)
. IM.elems
$ w ^. cWorld . lWorld . floorItems . unNIntMap
@@ -171,13 +166,22 @@ changeSwapClose ::
changeSwapClose f i w = fromMaybe w $ do
ss <- w ^? hud . hudElement . diSections . ix 3 . ssItems
k <- f i ss
let doswap j
| j == i= k
| j == k = i
| otherwise = j
-- updateselection = case w ^? hud . hudElement . diSelection . _Just of
-- Just (0, j) | j == k -> hud . hudElement . diSelection . _Just . _2 .~ i
-- Just (0, j) | j == i -> hud . hudElement . diSelection . _Just . _2 .~ k
-- _ -> id
return $
w
& swapAnyExtraSelection i k
& cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . ispCloseObject
.~ k
& cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . ispCloseItem
%~ doswap
& hud . closeItems %~ swapIndices i k
& hud . hudElement . diSelection . _Just . _2 .~ k
& hud . hudElement . diSelection . _Just . _2 %~ doswap
-- & updateselection
& worldEventFlags . at InventoryChange ?~ ()
-- can be specialised for when we know that item i is selected
@@ -309,6 +313,7 @@ scrollAugNextInSection w =
selectedCloseItem :: World -> Maybe FloorItem
selectedCloseItem w = do
i <-
you w ^? crManipulation . manObject . ispCloseObject
you w ^? crManipulation . manObject . ispCloseItem
<|> fmap fst (IM.lookupMin =<< w ^? hud . hudElement . diSections . ix 3 . ssItems)
w ^? hud . closeItems . ix i
flitid <- w ^? hud . closeItems . ix i . unNInt
w ^? cWorld . lWorld . floorItems . unNIntMap . ix flitid