Correctly update root status of item in _ilIsRoot

This commit is contained in:
2024-11-05 18:25:30 +00:00
parent 38ab6a35da
commit 9b3518e4eb
16 changed files with 40 additions and 25 deletions
+10 -1
View File
@@ -17,6 +17,7 @@ module Dodge.Inventory (
isFilteringInv,
) where
import Dodge.SoundLogic
import Control.Applicative
import Data.Maybe
import Dodge.Base
@@ -188,7 +189,8 @@ swapInvItems f i w = fromMaybe w $ do
Just (0, j) | j == i -> hud . hudElement . diSelection . _Just . _2 .~ k
_ -> id
return $
w & cWorld . lWorld . creatures . ix 0 %~ updatecreature k
w & checkdisconnect k
& cWorld . lWorld . creatures . ix 0 %~ updatecreature k
& updateselection
& worldEventFlags . at InventoryChange ?~ ()
& cWorld . lWorld %~ crUpdateItemLocations 0
@@ -196,6 +198,13 @@ swapInvItems f i w = fromMaybe w $ do
& cWorld . lWorld %~ crUpdateItemLocations 0 -- the double application is inefficient, but necessary without further changes
-- a rethink is maybe in order
where
cpos = fromMaybe 0 $ w ^? cWorld . lWorld . creatures . ix 0 . crPos
checkdisconnect k
| a || b = soundStart InventorySound cpos disconnectItemS Nothing
| otherwise = id
where
a = maybe False not $ w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix i . itLocation . ilIsRoot
b = maybe False not $ w ^? cWorld . lWorld . creatures . ix 0 . crInv . ix k . itLocation . ilIsRoot
updatecreature k =
(crInv %~ IM.safeSwapKeys i k)
. (crManipulation . manObject . imSelectedItem .~ k)