Fix bug in item loc when combining items, rethink centralizing item locs

This commit is contained in:
2024-09-24 18:07:25 +01:00
parent a6eb5cf982
commit 34c244a332
4 changed files with 8 additions and 3 deletions
+1 -1
View File
@@ -1 +1 @@
All good (620 modules, at 09:25:41) All good (620 modules, at 18:04:30)
+2 -1
View File
@@ -33,11 +33,12 @@ tryPutItemInInv cid flit w = case maybeInvSlot of
Just Just
( i ( i
, w , w
& updateItLocation i
& cWorld . lWorld . floorItems . unNIntMap %~ IM.delete (_unNInt $ _flItID flit) & cWorld . lWorld . floorItems . unNIntMap %~ IM.delete (_unNInt $ _flItID flit)
& cWorld . lWorld . creatures . ix cid . crInv %~ IM.insert i it & cWorld . lWorld . creatures . ix cid . crInv %~ IM.insert i it
& updateItLocation i
-- I forget whether using "at" rather than "IM.insert" here caused problems -- I forget whether using "at" rather than "IM.insert" here caused problems
-- & cWorld . lWorld . creatures . ix cid . crInv . at i ?~ it -- & cWorld . lWorld . creatures . ix cid . crInv . at i ?~ it
& cWorld . lWorld %~ crUpdateItemLocations cid
& setInvPosFromSS & setInvPosFromSS
& cWorld . lWorld %~ crUpdateItemLocations cid & cWorld . lWorld %~ crUpdateItemLocations cid
) )
+3 -1
View File
@@ -15,6 +15,8 @@ import Dodge.Item.Grammar
import Data.Maybe import Data.Maybe
import Control.Applicative import Control.Applicative
-- this assumes the creature inventory is well formed, specifically the
-- location ids
tryGetRootItemInvID :: Int -> Creature -> Maybe Int tryGetRootItemInvID :: Int -> Creature -> Maybe Int
tryGetRootItemInvID i cr = do tryGetRootItemInvID i cr = do
let adj = case invAdj' (_crInv cr) of let adj = case invAdj' (_crInv cr) of
@@ -39,7 +41,7 @@ crUpdateItemLocations crid lw = fromMaybe lw $ do
crUpdateInvidLocations :: ManipulatedObject -> Int -> LWorld -> Int -> Item -> LWorld crUpdateInvidLocations :: ManipulatedObject -> Int -> LWorld -> Int -> Item -> LWorld
crUpdateInvidLocations mo crid lw invid itm = lw crUpdateInvidLocations mo crid lw invid itm = lw
& creatures . ix crid . crInv . ix invid . itLocation .~ newloc & creatures . ix crid . crInv . ix invid . itLocation .~ newloc
& itemLocations . ix itid .~ newloc & itemLocations %~ IM.insert itid newloc
where where
itid = itm ^. itID itid = itm ^. itID
newloc = InInv crid invid (Just invid == mo ^? inInventory . imSelectedItem) newloc = InInv crid invid (Just invid == mo ^? inInventory . imSelectedItem)
+2
View File
@@ -101,6 +101,8 @@ invLDT = joinItemsInList (leftRightCombine leftIsParentCombine rightIsParentComb
-- (error ("invAdj item " ++ show (_itID itm) ++ " location:" ++ show (itm ^? itLocation . ilInvID)) ) -- (error ("invAdj item " ++ show (_itID itm) ++ " location:" ++ show (itm ^? itLocation . ilInvID)) )
-- $ itm ^? itLocation . ilInvID -- $ itm ^? itLocation . ilInvID
-- this assumes the creature inventory is well formed, specifically the
-- location ids
invAdj' :: IM.IntMap Item -> Either String (IM.IntMap (Maybe (Int,Int),[Int],[Int])) invAdj' :: IM.IntMap Item -> Either String (IM.IntMap (Maybe (Int,Int),[Int],[Int]))
invAdj' im = do invAdj' im = do
l <- mapM g $ invLDT im l <- mapM g $ invLDT im