From 7d2a4bf439830a9b8e8ef552b2937fad1eb6dc3b Mon Sep 17 00:00:00 2001 From: justin Date: Sun, 24 Nov 2024 22:36:00 +0000 Subject: [PATCH] Cleanup --- ghcidOutput | 2 +- src/Dodge/Inventory.hs | 82 +++++++++++++++++++++++++++--------------- 2 files changed, 54 insertions(+), 30 deletions(-) diff --git a/ghcidOutput b/ghcidOutput index f762640f4..ae7b37f81 100644 --- a/ghcidOutput +++ b/ghcidOutput @@ -1 +1 @@ -All good (593 modules, at 22:07:48) +All good (593 modules, at 22:35:05) diff --git a/src/Dodge/Inventory.hs b/src/Dodge/Inventory.hs index eeb2dd77e..3b9dc32e9 100644 --- a/src/Dodge/Inventory.hs +++ b/src/Dodge/Inventory.hs @@ -86,8 +86,6 @@ rmInvItem cid invid w = & pointcid %~ updateRootItemID & worldEventFlags . at InventoryChange ?~ () where - -- & updateCreatureItemLocations cid - pointcid = cWorld . lWorld . creatures . ix cid updateselectionextra | cid == 0 = hud . hudElement . diSelectionExtra .~ mempty @@ -95,10 +93,8 @@ rmInvItem cid invid w = updateselection | cid == 0 && cr ^? crManipulation . manObject . imSelectedItem == Just invid = scrollAugInvSel (-1) . scrollAugInvSel 1 -- . updateInventorySectionItems - -- id -- . updateInventorySectionItems | otherwise = pointcid . crManipulation . manObject . imSelectedItem %~ g - cr = w ^?! cWorld . lWorld . creatures . ix cid itm = _crInv cr IM.! invid dounequipfunction = fromMaybe id $ do @@ -132,8 +128,9 @@ updateCloseObjects w = 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) + citems = + fmap _flItID + . filter (isclose . _flItPos) . IM.elems $ w ^. cWorld . lWorld . floorItems . unNIntMap isclose pos = dist ypos pos < 40 && hasButtonLOS ypos pos w @@ -142,46 +139,71 @@ updateCloseObjects w = filter ((/=) BtNoLabel . _btState) . IM.elems $ w ^. cWorld . lWorld . buttons - -- updatecursorposifnecessary = - -- case w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . ispCloseObject of - -- Just i - -- | i >= length newcloseobjects -> scrollAugInvSel 1 - -- | isNothing (w ^? hud . hudElement . diSections . ix 3 . ssItems . ix i) -> - -- scrollAugInvSel (-1) - -- _ -> id + +-- updatecursorposifnecessary = +-- case w ^? cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . ispCloseObject of +-- Just i +-- | i >= length newcloseobjects -> scrollAugInvSel 1 +-- | isNothing (w ^? hud . hudElement . diSections . ix 3 . ssItems . ix i) -> +-- scrollAugInvSel (-1) +-- _ -> id changeSwapSel :: Int -> World -> World changeSwapSel yi w - | yi == 0 = w - | yi > 0 = foldl' (&) w $ replicate yi (changeSwapWith $ f IM.cycleLT) + -- | yi == 0 = w + | yi >= 0 = foldl' (&) w $ replicate yi (changeSwapWith $ f IM.cycleLT) | otherwise = foldl' (&) w $ replicate (negate yi) (changeSwapWith $ f IM.cycleGT) where f g i m = fst <$> g i m -changeSwapClose :: +--changeSwapClose :: +-- (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) -> +-- Int -> +-- World -> +-- World +--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 +-- return $ +-- w +-- & swapAnyExtraSelection i k +-- & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . ispCloseItem +-- %~ doswap +-- & hud . closeItems %~ swapIndices i k +-- & hud . hudElement . diSelection . _Just . _2 %~ doswap +-- & worldEventFlags . at InventoryChange ?~ () + +--changeSwapClose' :: +-- (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) -> +-- Int -> +-- World -> +-- World + +changeSwapOther :: + ((Int -> Identity Int) -> ManipulatedObject -> Identity ManipulatedObject) -> + Int -> (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) -> Int -> World -> World -changeSwapClose f i w = fromMaybe w $ do - ss <- w ^? hud . hudElement . diSections . ix 3 . ssItems +changeSwapOther manlens n f i w = fromMaybe w $ do + ss <- w ^? hud . hudElement . diSections . ix n . ssItems k <- f i ss - let doswap j - | j == i= k - | j == k = i + 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 . ispCloseItem + & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject . manlens %~ doswap & hud . closeItems %~ swapIndices i k & hud . hudElement . diSelection . _Just . _2 %~ doswap --- & updateselection & worldEventFlags . at InventoryChange ?~ () -- can be specialised for when we know that item i is selected @@ -269,13 +291,15 @@ swapItemWith :: World swapItemWith f (j, i) w = case j of 0 -> w & swapInvItems f i - 3 -> w & changeSwapClose f i + 3 -> w & changeSwapOther ispCloseItem 3 f i + 5 -> w & changeSwapOther ispCloseButton 5 f i _ -> w changeSwapWith :: (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) -> World -> World changeSwapWith f w = case w ^? hud . hudElement . diSelection . _Just of Just (0, i) -> w & swapInvItems f i - Just (3, i) -> w & changeSwapClose f i + Just (3, i) -> w & changeSwapOther ispCloseItem 3 f i + Just (5, i) -> w & changeSwapOther ispCloseButton 5 f i _ -> w augInvDirectSelect :: (Int, Int) -> World -> World