Improve item location code, including some error detection

This commit is contained in:
2024-09-23 14:33:14 +01:00
parent 3a08cf93f5
commit 43b365185d
8 changed files with 93 additions and 47 deletions
-10
View File
@@ -18,16 +18,6 @@ import Dodge.FloorItem
import Dodge.Inventory.CheckSlots
import qualified IntMapHelp as IM
--putItemInInvID :: Int -> Int -> World -> (Maybe Int, World)
--putItemInInvID cid flid w = fromMaybe (Nothing, w) $ do
-- flit <- w ^? cWorld . lWorld . floorItems . ix flid
-- (i, w') <- tryPutItemInInv cid flit w
-- return (Just i, w')
--putItemInInvSlot :: Int -> Item -> IM.IntMap Item -> IM.IntMap Item
--putItemInInvSlot = IM.insert
----putItemInInvSlot = IM.insertWith (const $ itUse . useAmount +~ 1)
tryPutItemIDInInv :: Int -> Int -> World -> Maybe (Int, World)
tryPutItemIDInInv cid flitid w = do
flit <- w ^? cWorld . lWorld . floorItems . ix flitid
+8 -1
View File
@@ -1,4 +1,9 @@
module Dodge.Inventory.Location
(updateRootItemID
, crUpdateItemLocations
, setInvPosFromSS
, tryGetRootItemInvID
)
where
import Dodge.Base.You
import Dodge.Data.SelectionList
@@ -12,7 +17,9 @@ import Control.Applicative
tryGetRootItemInvID :: Int -> Creature -> Maybe Int
tryGetRootItemInvID i cr = do
let adj = invAdj (_crInv cr)
let adj = case invAdj' (_crInv cr) of
Left str -> error $ "tryToGetRootItemInvID: "++ str
Right x -> x
thetree <- adj ^? ix i -- to check that the index does point to SOME item in the inventory
thetree ^? _1 . _Just . _1 <|> Just i