Use NewIntMap InvInt for crInv

This commit is contained in:
2025-08-25 10:21:59 +01:00
parent 25e64d5378
commit 3f6f1b4019
38 changed files with 437 additions and 406 deletions
+4 -3
View File
@@ -4,6 +4,7 @@ module Dodge.Inventory.CheckSlots (
maxInvSlots,
) where
import NewInt
import Control.Monad
import Dodge.Item.InvSize
import Control.Lens
@@ -14,11 +15,11 @@ import qualified IntMapHelp as IM
{- | checks whether or not an item will fit in your inventory
if so return Just the next slot to be used
-}
checkInvSlotsYou :: Item -> World -> Maybe Int
checkInvSlotsYou :: Item -> World -> Maybe (NewInt InvInt)
checkInvSlotsYou it w = do
ycr <- w ^? cWorld . lWorld . creatures . ix 0
guard $ crNumFreeSlots (w ^. cWorld . lWorld . items) ycr >= itInvHeight it
Just . IM.newKey $ _crInv ycr
Just . NInt . IM.newKey . _unNIntMap $ _crInv ycr
crNumFreeSlots :: IM.IntMap Item -> Creature -> Int
--crNumFreeSlots cr = _crInvCapacity cr - invSize (_crInv cr)
@@ -29,5 +30,5 @@ crNumFreeSlots m cr = maxInvSlots - invSize (fmap f (_crInv cr))
maxInvSlots :: Int
maxInvSlots = 25
invSize :: IM.IntMap Item -> Int
invSize :: NewIntMap InvInt Item -> Int
invSize = alaf Sum foldMap itInvHeight