Fix bug in manObject update when dropping items

This commit is contained in:
2026-05-14 21:46:08 +01:00
parent c70097f1e1
commit 17f8707f62
8 changed files with 55 additions and 78 deletions
+1 -1
View File
@@ -215,7 +215,7 @@ youDropItem w = fromMaybe w $ do
guard $ not $ w ^. cWorld . lWorld . lInvLock
return $ case cr ^. crStance . posture of
Aiming{} -> throwItem w
AtEase -> dropItem cr curpos w
AtEase -> setInvPosFromSS $ dropItem cr curpos w
where
cr = you w
mi = do
+1 -1
View File
@@ -235,7 +235,7 @@ shineTargetLaser cr loc w = fromMaybe (w & pointittarg . itTgPos .~ Nothing) $ d
magitid <- mag ^? dtValue . _1 . itID . unNInt
return $
w
& worldEventFlags . at InventoryChange ?~ ()
& worldEventFlags . at InventoryChange ?~ () -- why?
& cWorld . lWorld . items
. ix magitid
. itConsumables
+4 -21
View File
@@ -89,19 +89,12 @@ rmInvItem cid invid w =
& removeAnySlotEquipment
& cWorld . lWorld . items . ix itid . itLocation . ilEquipSite .~ Nothing
& updateselection
& updateselectionextra
& uprootitem
-- & uprootitem
--revise1 & pointcid %~ updateRootItemID (w ^. cWorld . lWorld . items)
& worldEventFlags . at InventoryChange ?~ ()
where
uprootitem w' = updateRootItemID (w ^. cWorld . lWorld . items) (w'^?!cWorld.lWorld.creatures.ix 0) w'
-- uprootitem w' = updateRootItemID (w ^. cWorld . lWorld . items) (w'^?!cWorld.lWorld.creatures.ix 0) w'
pointcid = cWorld . lWorld . creatures . ix cid
updateselectionextra
-- | cid == 0 = hud . diSelection . _Just . slSet %~ IS.foldl' h mempty
| otherwise = id
-- h x i | i > _unNInt invid = IS.insert (i-1) x
-- | i < _unNInt invid = IS.insert i x
-- | otherwise = x
updateselection
| cid == 0 && (w ^? hud .diSelection._Just) == Just (Sel 0 (invid^.unNInt)) =
--revise2 | cid == 0 && w ^? hud . manObject . imSelectedItem == Just invid =
@@ -113,21 +106,11 @@ rmInvItem cid invid w =
itm = w ^?! cWorld . lWorld . items . ix itid
dounequipfunction = effectOnRemove itm cr
removeAnySlotEquipment = fromMaybe id $ do
epos <-
itm
^? itLocation
. ilEquipSite
. _Just
epos <- itm ^? itLocation . ilEquipSite . _Just
return $ pointcid . crEquipment . at epos .~ Nothing
-- return $ pointcid . crEquipment .~ mempty
maxk = fmap fst $ IM.lookupMax $ _unNIntMap $ cr ^. crInv
f inv =
let (xs, ys) = IM.split (_unNInt invid) $ _unNIntMap inv
in NIntMap $ xs `IM.union` IM.mapKeysMonotonic (subtract 1) ys
-- the following might not work if a non-player creature drops their last item
g x
| x > invid || Just x == fmap NInt maxk = max 0 $ x - 1
| otherwise = x
updateCloseObjects :: World -> World
updateCloseObjects w =
@@ -298,7 +281,7 @@ invSetSelection sel w =
w
& hud . diSelection ?~ sel
& worldEventFlags . at InventoryChange ?~ ()
& setInvPosFromSS
& setInvPosFromSS -- is this necessary here?
& crUpdateItemLocations 0
--revise1 & cWorld . lWorld %~ crUpdateItemLocations 0
+15 -16
View File
@@ -1,5 +1,5 @@
module Dodge.Inventory.Location (
updateRootItemID,
-- updateRootItemID,
crUpdateItemLocations,
setInvPosFromSS,
) where
@@ -7,7 +7,6 @@ module Dodge.Inventory.Location (
import Dodge.Item.AimStance
import Control.Lens
import Data.Foldable
--import Data.IntMap.Merge.Strict
import qualified Data.IntSet as IS
import Data.Maybe
import Dodge.Base.You
@@ -30,21 +29,21 @@ tryGetRootAttachedFromInvID (NInt invid) im = do
t <- imroots ^? ix theroot . _2
return (theroot, foldMap (IS.singleton . (^?! itLocation . ilInvID . unNInt)) t)
-- this assumes the creature inventory is well formed, specifically the
-- location ids
-- note the item intmap is all items
getRootItemInvID :: IM.IntMap Item -> Int -> Creature -> Int
getRootItemInvID m i cr = fromMaybe i $ do
let adj = invAdj $ fmap (\k -> m ^?! ix k) (_crInv cr)
theroot <- adj ^? ix i
theroot ^? _1 . _Just . _1
---- this assumes the creature inventory is well formed, specifically the
---- location ids
---- note the item intmap is all items
--getRootItemInvID :: IM.IntMap Item -> Int -> Creature -> Int
--getRootItemInvID m i cr = fromMaybe i $ do
-- let adj = invAdj $ fmap (\k -> m ^?! ix k) (_crInv cr)
-- theroot <- adj ^? ix i
-- theroot ^? _1 . _Just . _1
updateRootItemID :: IM.IntMap Item -> Creature -> World -> World
updateRootItemID m cr w = fromMaybe w $ do
Sel 0 i <- w^?hud.diSelection._Just
--revise2 i <- w^?hud . manObject . imSelectedItem . unNInt
let j = getRootItemInvID m i cr
return $ w & hud . manObject . hiRootSelectedItem .~ NInt j
--updateRootItemID :: IM.IntMap Item -> Creature -> World -> World
--updateRootItemID m cr w = fromMaybe w $ do
-- Sel 0 i <- w^?hud.diSelection._Just
----revise2 i <- w^?hud . manObject . imSelectedItem . unNInt
-- let j = getRootItemInvID m i cr
-- return $ w & hud . manObject . hiRootSelectedItem .~ NInt j
-- the following assumes that the crManipulation is correct
crUpdateItemLocations :: Int -> World -> World
+4 -1
View File
@@ -58,7 +58,10 @@ crs :: Universe -> [Creature]
crs u = u ^.. uvWorld . cWorld . lWorld . creatures . each
testStringInit :: Universe -> [String]
testStringInit u = u ^.. uvWorld . hud . diSections . each . ssSet . to show
testStringInit u =
u ^. uvWorld . hud . manObject . to prettyShort
<>
u ^.. uvWorld . hud . diSections . each . ssSet . to show
--testStringInit u = u ^. uvWorld . cWorld . lWorld . creatures . ix 5 . crActionPlan . to prettyShort
--[show . getSum $ foldMap (Sum . crslime) (crs u)]
-- u ^.. tocrs . each . crType . slimeSplitTimer . to show
+1
View File
@@ -129,6 +129,7 @@ updateWorldEventFlags u =
updateWorldEventFlag :: WorldEventFlag -> Universe -> Universe
updateWorldEventFlag wef = case wef of
InventoryChange -> id -- updateInventoryPositioning
-- setInvPosFromSS ?
-- for now update inventory positioning every tick
CombineInventoryChange -> updateCombinePositioning
+8 -17
View File
@@ -60,7 +60,7 @@ updateUseInputInGame u = updateFunctionKeys $ case u ^. uvWorld . hud . subInven
f x y i = u
& uvWorld . hud %~ dodisplayregexinput x y i
& uvWorld . worldEventFlags . at InventoryChange ?~ ()
& uvWorld %~ setInvPosFromSS
& uvWorld %~ setInvPosFromSS -- not sure if this is necessary
dodisplayregexinput filterprism filterlens x di = fromMaybe di $ do
sss <- di ^? diSections
msel <- di ^? diSelection
@@ -153,6 +153,7 @@ tryDropSelected mpos w = do
xs <- selectionSet w
let xmin = IS.findMin xs
return
. setInvPosFromSS
. (hud . diSelection ?~ Sel 3 (j - xmin))
. foldl' (flip $ dropItem cr) w
. IS.toDescList
@@ -491,27 +492,17 @@ updateBackspaceRegex w = case di ^? subInventory of
Just NoSubInventory{}
| secfocus (-1) 0 ->
w
& hud
%~ trybackspace (-1) diInvFilter diInvFilter diSelection
& worldEventFlags
. at InventoryChange
?~ ()
& hud %~ trybackspace (-1) diInvFilter diInvFilter diSelection
& worldEventFlags . at InventoryChange ?~ ()
Just NoSubInventory{}
| secfocus 2 3 ->
w
& hud
%~ trybackspace 2 diCloseFilter diCloseFilter diSelection
& worldEventFlags
. at InventoryChange
?~ ()
& hud %~ trybackspace 2 diCloseFilter diCloseFilter diSelection
& worldEventFlags . at InventoryChange ?~ ()
Just CombineInventory{} ->
w
& hud
. subInventory
%~ trybackspace (-1) ciFilter ciFilter ciSelection
& worldEventFlags
. at InventoryChange
?~ ()
& hud . subInventory %~ trybackspace (-1) ciFilter ciFilter ciSelection
& worldEventFlags . at InventoryChange ?~ ()
_ -> w
where
secfocus a b = fromMaybe False $ do
+21 -21
View File
@@ -2879,10 +2879,10 @@ centerVaultRoom src/Dodge/Room/Procedural.hs 271;" f
centroid src/Geometry/Polygon.hs 192;" f
centroidNum src/Geometry/Polygon.hs 195;" f
chainPairs src/Geometry.hs 360;" f
changeSwapOther src/Dodge/Inventory.hs 254;" f
changeSwapSel src/Dodge/Inventory.hs 223;" f
changeSwapSelSet src/Dodge/Inventory.hs 158;" f
changeSwapWith src/Dodge/Inventory.hs 288;" f
changeSwapOther src/Dodge/Inventory.hs 237;" f
changeSwapSel src/Dodge/Inventory.hs 206;" f
changeSwapSelSet src/Dodge/Inventory.hs 141;" f
changeSwapWith src/Dodge/Inventory.hs 274;" f
charToTuple src/Picture/Base.hs 312;" f
charToTupleGrad src/Picture/Text.hs 18;" f
chartreuse src/Color.hs 51;" f
@@ -2948,7 +2948,7 @@ clipZoom src/Dodge/Update/Camera.hs 241;" f
clipboardCr src/Dodge/Debug.hs 91;" f
clockCycle src/Dodge/Clock.hs 7;" f
closeButtonToSelectionItem src/Dodge/Inventory/SelectionList.hs 237;" f
closeItemDist src/Dodge/Inventory.hs 155;" f
closeItemDist src/Dodge/Inventory.hs 138;" f
closeItemToSelectionItem src/Dodge/Inventory/SelectionList.hs 221;" f
closeItemToTextPictures src/Dodge/Inventory/SelectionList.hs 260;" f
closeObjectInfo src/Dodge/Render/HUD.hs 221;" f
@@ -2966,7 +2966,7 @@ cognizantVoc src/Dodge/Creature/Perception.hs 68;" f
colCrWall src/Dodge/WallCreatureCollisions.hs 27;" f
colCrsWalls src/Dodge/WallCreatureCollisions.hs 19;" f
collectDamageTypes src/Dodge/Damage.hs 54;" f
collectInvItems src/Dodge/Inventory.hs 213;" f
collectInvItems src/Dodge/Inventory.hs 196;" f
collide3 src/Dodge/Base/Collide.hs 142;" f
collide3Chasm src/Dodge/Base/Collide.hs 126;" f
collide3Chasms src/Dodge/Base/Collide.hs 118;" f
@@ -3008,7 +3008,7 @@ compressionScale src/Dodge/Creature/State/WalkCycle.hs 69;" f
compressor src/Dodge/Item/Ammo.hs 74;" f
computerBeepingS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 716;" f
conEffects src/Dodge/Concurrent.hs 12;" f
concurrentIS src/Dodge/Inventory.hs 205;" f
concurrentIS src/Dodge/Inventory.hs 188;" f
connectItemS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 802;" f
constructEdges src/Polyhedra.hs 31;" f
constructEdgesList src/Polyhedra.hs 40;" f
@@ -3976,8 +3976,8 @@ invItemEffs src/Dodge/Creature/State.hs 91;" f
invItemLocUpdate src/Dodge/Creature/State.hs 99;" f
invRootMap src/Dodge/Item/Grammar.hs 237;" f
invSelectionItem src/Dodge/Inventory/SelectionList.hs 33;" f
invSetSelection src/Dodge/Inventory.hs 293;" f
invSetSelectionPos src/Dodge/Inventory.hs 302;" f
invSetSelection src/Dodge/Inventory.hs 279;" f
invSetSelectionPos src/Dodge/Inventory.hs 288;" f
invShiftPointBy src/Dodge/ShiftPoint.hs 17;" f
invSize src/Dodge/Inventory/CheckSlots.hs 33;" f
inventoryX src/Dodge/Creature.hs 103;" f
@@ -4406,8 +4406,8 @@ multGunCrit src/Dodge/Creature.hs 68;" f
multiArrow src/Picture/Composite.hs 11;" f
multiLookupTrie src/SimpleTrie.hs 57;" f
multiLookupTrieI src/SimpleTrie.hs 66;" f
multiSelScroll src/Dodge/Inventory.hs 230;" f
multiSelScroll' src/Dodge/Inventory.hs 237;" f
multiSelScroll src/Dodge/Inventory.hs 213;" f
multiSelScroll' src/Dodge/Inventory.hs 220;" f
muout src/Dodge/RoomLink.hs 144;" f
muzFlareAt src/Dodge/HeldUse.hs 702;" f
muzzlePos src/Dodge/HeldUse.hs 787;" f
@@ -4977,8 +4977,8 @@ screenPolygon src/Dodge/Base/Window.hs 18;" f
screenPolygonBord src/Dodge/Base/Window.hs 28;" f
screenPosAbs src/Dodge/ScreenPos.hs 16;" f
screenToWorldPos src/Dodge/Base/Coordinate.hs 45;" f
scrollAugInvSel src/Dodge/Inventory.hs 305;" f
scrollAugNextInSection src/Dodge/Inventory.hs 320;" f
scrollAugInvSel src/Dodge/Inventory.hs 291;" f
scrollAugNextInSection src/Dodge/Inventory.hs 306;" f
scrollRBOption src/Dodge/Update/Scroll.hs 142;" f
scrollSelectionSections src/Dodge/SelectionSections.hs 30;" f
scrollTimeBack src/Dodge/Update.hs 245;" f
@@ -5086,8 +5086,8 @@ shiftChildren src/Dodge/Tree/Compose.hs 45;" f
shiftDraw src/Dodge/Render/ShapePicture.hs 111;" f
shiftInBy src/Dodge/PlacementSpot.hs 254;" f
shiftInvItems src/Dodge/Update/Input/InGame.hs 317;" f
shiftInvItemsDown src/Dodge/Inventory.hs 189;" f
shiftInvItemsUp src/Dodge/Inventory.hs 199;" f
shiftInvItemsDown src/Dodge/Inventory.hs 172;" f
shiftInvItemsUp src/Dodge/Inventory.hs 182;" f
shiftLinkBy src/Dodge/Room/Link.hs 89;" f
shiftPSBy src/Dodge/Placement/Shift.hs 12;" f
shiftPathBy src/Dodge/Room/Link.hs 94;" f
@@ -5099,8 +5099,8 @@ shiftRelativeToPS src/Dodge/Placement/Shift.hs 18;" f
shiftRoomBy src/Dodge/Room/Link.hs 38;" f
shiftRoomShiftBy src/Dodge/Room/Link.hs 83;" f
shiftRoomShiftToLink src/Dodge/Room/Link.hs 74;" f
shiftSetDown src/Dodge/Inventory.hs 182;" f
shiftSetUp src/Dodge/Inventory.hs 176;" f
shiftSetDown src/Dodge/Inventory.hs 165;" f
shiftSetUp src/Dodge/Inventory.hs 159;" f
shiftTile src/Dodge/Room/Link.hs 49;" f
shineTargetLaser src/Dodge/Creature/State.hs 229;" f
shineTorch src/Dodge/Creature/State.hs 266;" f
@@ -5130,7 +5130,7 @@ showInventoryPathing src/Dodge/Item/Display.hs 87;" f
showManObj src/Dodge/TestString.hs 129;" f
showMuzzlePositions src/Dodge/Debug.hs 320;" f
showTerminalError src/Dodge/Debug/Terminal.hs 80;" f
showTimeFlow src/Dodge/TestString.hs 144;" f
showTimeFlow src/Dodge/TestString.hs 145;" f
shrinkPolyOnEdges src/Geometry/Polygon.hs 198;" f
shrinkVert src/Geometry/Polygon.hs 202;" f
shuffle src/RandomHelp.hs 68;" f
@@ -5323,8 +5323,8 @@ swapAnyExtraSelection src/Dodge/Inventory/Swap.hs 61;" f
swapInOutLinks src/Dodge/RoomLink.hs 99;" f
swapIndices src/ListHelp.hs 50;" f
swapInvItems src/Dodge/Inventory/Swap.hs 23;" f
swapItemWith src/Dodge/Inventory.hs 277;" f
swapSelSet src/Dodge/Inventory.hs 163;" f
swapItemWith src/Dodge/Inventory.hs 261;" f
swapSelSet src/Dodge/Inventory.hs 146;" f
swarmCrit src/Dodge/Creature/SwarmCrit.hs 10;" f
swarmUsingCenter src/Dodge/Creature/Boid.hs 174;" f
symmetricDifference src/Dodge/Update/Input/InGame.hs 226;" f
@@ -5590,7 +5590,7 @@ updateCamera src/Dodge/Update/Camera.hs 34;" f
updateCarriage src/Dodge/Creature/State/WalkCycle.hs 22;" f
updateCarriage' src/Dodge/Creature/State/WalkCycle.hs 27;" f
updateChaseCrit src/Dodge/Creature/Update.hs 371;" f
updateCloseObjects src/Dodge/Inventory.hs 132;" f
updateCloseObjects src/Dodge/Inventory.hs 115;" f
updateCloud src/Dodge/Update.hs 921;" f
updateClouds src/Dodge/Update.hs 785;" f
updateCombinePositioning src/Dodge/DisplayInventory.hs 42;" f