Separate selected item from extra selected items

This commit is contained in:
2024-11-22 15:34:14 +00:00
parent bc2c9c9369
commit 13f5dd09c8
6 changed files with 154 additions and 103 deletions
+1 -12
View File
@@ -16,22 +16,11 @@ import qualified IntMapHelp as IM
checkInvSlotsYou :: Item -> World -> Maybe Int
checkInvSlotsYou it w
| crNumFreeSlots ycr >= _itInvSize it =
Just $ findItemSlot (_crInv ycr)
Just . IM.newKey $ _crInv ycr
| otherwise = Nothing
where
ycr = you w
-- Assumes that the item is singular.
-- Do not want to stack floor items for now
findItemSlot :: IM.IntMap Item -> Int
findItemSlot = maybe 0 ((+ 1) . fst) . IM.lookupMax
--findItemSlot it inv = case it ^? itUse . useAmount of
-- Just _ ->
-- fromMaybe newslot $ IM.findIndex (\it' -> _itType it == _itType it') inv
-- _ -> newslot
-- where
-- newslot = maybe 0 ((+ 1) . fst) $ IM.lookupMax inv
crNumFreeSlots :: Creature -> Int
crNumFreeSlots cr = _crInvCapacity cr - invSize (_crInv cr)