Allow for stacking of items and combining sensibly

This commit is contained in:
2021-12-03 17:18:06 +00:00
parent b2a9192fe4
commit b41e3e3637
24 changed files with 166 additions and 159 deletions
+6 -5
View File
@@ -20,6 +20,7 @@ module Dodge.Inventory
import Dodge.Data
import Dodge.Inventory.CloseObject
import Dodge.Inventory.CheckSlots
import Dodge.Inventory.ItemSpace
import Dodge.Base
import Dodge.Base.Collide
import Geometry
@@ -38,8 +39,8 @@ import Control.Lens
rmInvItem :: Int -- ^ Creature id
-> Int -- ^ Inventory position
-> World -> World
rmInvItem cid invid w = case w ^? creatures . ix cid . crInv . ix invid . itAmount of
Just x | x > 1 -> w & creatures . ix cid . crInv . ix invid . itAmount %~ subtract 1
rmInvItem cid invid w = case w ^? creatures . ix cid . crInv . ix invid . itConsumption . itAmount' of
Just x | x > 1 -> w & creatures . ix cid . crInv . ix invid . itConsumption . itAmount' %~ subtract 1
_ -> w & creatures . ix cid . crInv %~ f
& creatures . ix cid . crInvSel %~ g
& creatures . ix cid . crLeftInvSel . _Just %~ g
@@ -54,7 +55,7 @@ rmSelectedInvItem :: Int -> World -> World
rmSelectedInvItem cid w = rmInvItem cid (_crInvSel (_creatures w IM.! cid)) w
augmentedInvSizes :: World -> IM.IntMap Int
augmentedInvSizes = bimapAugmentInv _itInvSize closeObjectSize
augmentedInvSizes = bimapAugmentInv itSlotsTaken closeObjectSize
bimapAugmentInv :: (Item -> a) -> (Either FloorItem Button -> a) -> World -> IM.IntMap a
bimapAugmentInv f g w = IM.union
@@ -66,7 +67,7 @@ invSelSize i w = fromMaybe 1 $ augmentedInvSizes w IM.!? i
closeObjectSize :: Either FloorItem Button -> Int
closeObjectSize e = case e of
Left flit -> _itInvSize $ _flIt flit
Left flit -> itSlotsTaken $ _flIt flit
Right _ -> 1
@@ -150,7 +151,7 @@ bestCloseObjectIndex :: World -> Maybe Int
bestCloseObjectIndex w = findIndex f $ _closeObjects w
where
f (Right _) = True
f (Left flit) = _itInvSize (_flIt flit) <= _crInvCapacity ycr - crInvSize ycr
f (Left flit) = itSlotsTaken (_flIt flit) <= _crInvCapacity ycr - crInvSize ycr
ycr = you w
selectedCloseObject :: World -> Maybe (Int,Either FloorItem Button)