Fix inventory bug

This commit is contained in:
2023-01-02 11:33:33 +00:00
parent f3b14f9a22
commit 6c1862b2a1
+12 -15
View File
@@ -25,19 +25,19 @@ module Dodge.Inventory (
invDimColor, invDimColor,
) where ) where
import Dodge.Reloading
import Color import Color
import Dodge.Inventory.Color
import qualified Data.Map.Strict as M import qualified Data.Map.Strict as M
import Data.Maybe import Data.Maybe
import Dodge.Base import Dodge.Base
import Dodge.Data.World
import Dodge.Data.Config import Dodge.Data.Config
import Dodge.Data.World
import Dodge.Euse import Dodge.Euse
import Dodge.Inventory.CheckSlots import Dodge.Inventory.CheckSlots
import Dodge.Inventory.CloseObject import Dodge.Inventory.CloseObject
import Dodge.Inventory.Color
import Dodge.Inventory.ItemSpace import Dodge.Inventory.ItemSpace
import Dodge.ItEffect import Dodge.ItEffect
import Dodge.Reloading
import Geometry import Geometry
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
import LensHelp import LensHelp
@@ -104,9 +104,9 @@ augmentedInvSizes = trimapAugmentInv itSlotsTaken 1 closeObjectSize
trimapAugmentInv :: (Item -> a) -> a -> (Either FloorItem Button -> a) -> World -> IM.IntMap a trimapAugmentInv :: (Item -> a) -> a -> (Either FloorItem Button -> a) -> World -> IM.IntMap a
trimapAugmentInv f x g w = trimapAugmentInv f x g w =
IM.insert n x $ IM.insert n x $
IM.union IM.union
(f <$> yourInv w) (f <$> yourInv w)
(IM.fromAscList $ zip [n + 1 ..] $ map g $ w ^. hud . closeObjects) (IM.fromAscList $ zip [n + 1 ..] $ map g $ w ^. hud . closeObjects)
where where
n = length $ yourInv w n = length $ yourInv w
@@ -166,8 +166,7 @@ updateCloseObjects w =
& cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ updateinvsel & cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ updateinvsel
where where
updateinvsel curinvsel updateinvsel curinvsel
-- | length (augmentedInvSizes w) <= curinvsel = max 0 $ length (augmentedInvSizes w) - 1 | length (augmentedInvSizes w) <= curinvsel = max 0 $ length (augmentedInvSizes w) - 1
| length (augmentedInvSizes w) <= curinvsel = max 0 $ length (augmentedInvSizes w)
| otherwise = curinvsel | otherwise = curinvsel
filt = filter $ \obj -> dist ypos (closeObjPos obj) < 40 && hasButtonLOS ypos (closeObjPos obj) w filt = filter $ \obj -> dist ypos (closeObjPos obj) < 40 && hasButtonLOS ypos (closeObjPos obj) w
ypos = _crPos $ you w ypos = _crPos $ you w
@@ -332,7 +331,7 @@ changeSwapInvSel k w
| yourInvSel w > n = | yourInvSel w > n =
w w
& cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos .~ ico' & cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos .~ ico'
& hud . closeObjects %~ swapIndices (i - (n+1)) (ico' - (n+1)) & hud . closeObjects %~ swapIndices (i - (n + 1)) (ico' - (n + 1))
| otherwise = w | otherwise = w
where where
updatecreature = updatecreature =
@@ -357,12 +356,10 @@ changeSwapInvSel k w
numCO = length $ w ^. hud . closeObjects numCO = length $ w ^. hud . closeObjects
changeAugInvSel :: Int -> World -> World changeAugInvSel :: Int -> World -> World
changeAugInvSel i w changeAugInvSel i w =
| n == 0 = w w
| otherwise = & cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ (`mod` n) . subtract i
w & cWorld . lWorld . creatures . ix 0 . crInvSel . iselAction .~ NoInvSelAction
& cWorld . lWorld . creatures . ix 0 . crInvSel . iselPos %~ (`mod` n) . subtract i
& cWorld . lWorld . creatures . ix 0 . crInvSel . iselAction .~ NoInvSelAction
where where
n = length (yourInv w) + length (w ^. hud . closeObjects) + 1 n = length (yourInv w) + length (w ^. hud . closeObjects) + 1