Fix bugs in equipment allocation using hotkeys

The behaviour is still not perfect, should be able to cycle through all
options by pressing one key. There is unnecessary memory of past state
going on here
This commit is contained in:
2025-01-01 14:48:17 +00:00
parent 7dd379d4bc
commit dae0e0591c
10 changed files with 289 additions and 313 deletions
+5 -12
View File
@@ -1,13 +1,12 @@
module Dodge.Inventory.CheckSlots (
checkInvSlotsYou,
crNumFreeSlots,
crInvSize,
) where
import Control.Monad
import Dodge.Item.InvSize
import Control.Lens
import Data.Monoid
import Dodge.Base.You
import Dodge.Data.World
import qualified IntMapHelp as IM
@@ -15,19 +14,13 @@ import qualified IntMapHelp as IM
if so return Just the next slot to be used
-}
checkInvSlotsYou :: Item -> World -> Maybe Int
checkInvSlotsYou it w
| crNumFreeSlots ycr >= itInvHeight it =
Just . IM.newKey $ _crInv ycr
| otherwise = Nothing
where
ycr = you w
checkInvSlotsYou it w = do
ycr <- w ^? cWorld . lWorld . creatures . ix 0
guard $ crNumFreeSlots ycr >= itInvHeight it
Just . IM.newKey $ _crInv ycr
crNumFreeSlots :: Creature -> Int
crNumFreeSlots cr = _crInvCapacity cr - invSize (_crInv cr)
crInvSize :: Creature -> Int
crInvSize = invSize . _crInv
invSize :: IM.IntMap Item -> Int
invSize = alaf Sum foldMap itInvHeight
--invSize = sum . fmap _itInvSize
+5 -5
View File
@@ -42,15 +42,15 @@ chooseFreeSite cr = fromMaybe 0 . findIndex hasnoequipment
where
hasnoequipment ep = isNothing $ cr ^? crEquipment . ix ep
getEquipmentAllocation :: World -> EquipmentAllocation
getEquipmentAllocation w = fromMaybe DoNotMoveEquipment $ do
curpos <- you w ^? crManipulation . manObject . imSelectedItem
esite <- you w ^? crInv . ix curpos . itUse . uequipEffect . eeType
getEquipmentAllocation :: Int -> World -> EquipmentAllocation
getEquipmentAllocation invid w = fromMaybe DoNotMoveEquipment $ do
-- curpos <- you w ^? crManipulation . manObject . imSelectedItem
esite <- you w ^? crInv . ix invid . itUse . uequipEffect . eeType
i <-
w ^? rbOptions . opSel
<|> Just (chooseEquipPosition (you w) (eqSiteToPositions esite))
es <- eqSiteToPositions esite ^? ix i
return $ case you w ^? crInv . ix curpos . itLocation . ilEquipSite . _Just of
return $ case you w ^? crInv . ix invid . itLocation . ilEquipSite . _Just of
Just epos
| es == epos -> RemoveEquipment{_allocOldPos = epos}
Just epos