diff --git a/src/Dodge/Inventory.hs b/src/Dodge/Inventory.hs index c89d92a4d..934c4a356 100644 --- a/src/Dodge/Inventory.hs +++ b/src/Dodge/Inventory.hs @@ -37,9 +37,7 @@ import NewInt -- should consider never fully destroying items, but assigning a flag saying how -- they were moved from play destroyInvItem :: Int -> NewInt InvInt -> World -> World -destroyInvItem cid invid w = - rmInvItem cid invid w & removeitloc - & removeithotkey +destroyInvItem cid invid w = rmInvItem cid invid w & removeitloc & removeithotkey where removeitloc = fromMaybe id $ do itid <- w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid @@ -97,13 +95,9 @@ rmInvItem cid invid w = itid = _crInv cr ^?! ix invid itm = w ^?! cWorld . lWorld . items . ix itid dounequipfunction = effectOnRemove itm cr - -- fromMaybe id $ do - -- rmf <- itm ^? itUse . uequipEffect . eeOnRemove - -- return $ doItmCrWdWd rmf itm cr removeAnySlotEquipment = fromMaybe id $ do epos <- - w - ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid + w ^? cWorld . lWorld . creatures . ix cid . crInv . ix invid >>= \k -> w ^? cWorld . lWorld . items . ix k . itLocation . ilEquipSite @@ -120,23 +114,22 @@ rmInvItem cid invid w = updateCloseObjects :: World -> World updateCloseObjects w = - w & hud . closeItems %~ f - & hud . closeButtons %~ g + w & hud . closeItems %~ h citems + & hud . closeButtons %~ h cbts where - g oldbts = intersect oldbts cbts `union` cbts - f olditems = intersect olditems citems `union` citems + h a b = intersect b a `union` a lw = w ^. cWorld . lWorld - citems = let is = IM.filter (isclose . _flItPos) (lw^.floorItems) - in map NInt $ IM.keys $ IM.intersection (lw ^. items) is - isclose x = dist y x < 40 && hasButtonLOS y x w - y = _crPos $ you w + citems = map NInt $ IM.keys $ IM.intersection (lw ^. items) + $ IM.filter (isclose . _flItPos) (lw^.floorItems) cbts = lw^..buttons . each . filtered canpress . filtered (isclose . _btPos) . to _btID canpress bt = case bt ^. btEvent of ButtonPress{_btOn = t} -> not t ButtonAccessTerminal tid -> fromMaybe False $ do - x <- w ^? cWorld . lWorld . terminals . ix tid . tmStatus + x <- lw ^? terminals . ix tid . tmStatus return (x /= TerminalDeactivated) _ -> True + isclose x = dist y x < 40 && hasButtonLOS y x w + y = _crPos $ you w changeSwapSel :: Int -> World -> World changeSwapSel yi w @@ -184,13 +177,6 @@ changeSwapWith f w | Just (Sel j i _) <- w ^. hud . diSelection = swapItemWith f (j,i) w | otherwise = w ---changeSwapWith :: (Int -> IM.IntMap (SelectionItem ()) -> Maybe Int) -> World -> World ---changeSwapWith f w = case w ^? hud . hudElement . diSelection . _Just of --- Just (0, i, _) -> w & swapInvItems f i --- Just (3, i, _) -> w & changeSwapOther ispCloseItem 3 f i --- Just (5, i, _) -> w & changeSwapOther ispCloseButton 5 f i --- _ -> w - invSetSelection :: Selection -> World -> World invSetSelection sel w = w @@ -200,15 +186,7 @@ invSetSelection sel w = & cWorld . lWorld %~ crUpdateItemLocations 0 invSetSelectionPos :: Int -> Int -> World -> World -invSetSelectionPos i j w = - w - & hud . diSelection %~ f - & worldEventFlags . at InventoryChange ?~ () - & setInvPosFromSS - & cWorld . lWorld %~ crUpdateItemLocations 0 - where - f Nothing = Just (Sel i j mempty) - f (Just (Sel _ _ s)) = Just (Sel i j s) +invSetSelectionPos i j = invSetSelection (Sel i j mempty) scrollAugInvSel :: Int -> World -> World scrollAugInvSel yi w diff --git a/src/Dodge/Inventory/Add.hs b/src/Dodge/Inventory/Add.hs index f33898c38..5beb7c835 100644 --- a/src/Dodge/Inventory/Add.hs +++ b/src/Dodge/Inventory/Add.hs @@ -43,7 +43,8 @@ tryPutItemInInv cid itid w = do & updateselectionextra invid where updateselectionextra i - | cid == 0 = hud . diSelection . _Just . slSet %~ IS.map (f i) + | cid == 0 = (hud . diSelection . _Just . slSet %~ IS.map (f i)) + . (hud . diSelection . _Just . slInt %~ (f i)) | otherwise = id f j i | i >= _unNInt j = i + 1 | otherwise = i diff --git a/src/Dodge/Inventory/Location.hs b/src/Dodge/Inventory/Location.hs index f7de821ba..8259a5778 100644 --- a/src/Dodge/Inventory/Location.hs +++ b/src/Dodge/Inventory/Location.hs @@ -4,7 +4,6 @@ module Dodge.Inventory.Location ( setInvPosFromSS, ) where -import Control.Applicative import Control.Lens import Data.Foldable --import Data.IntMap.Merge.Strict @@ -32,16 +31,17 @@ tryGetRootAttachedFromInvID (NInt invid) im = do -- this assumes the creature inventory is well formed, specifically the -- location ids -tryGetRootItemInvID :: IM.IntMap Item -> Int -> Creature -> Maybe Int -tryGetRootItemInvID m i cr = do +-- 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 <|> Just i + theroot ^? _1 . _Just . _1 updateRootItemID :: IM.IntMap Item -> Creature -> Creature updateRootItemID m cr = fromMaybe cr $ do i <- cr ^? crManipulation . manObject . imSelectedItem . unNInt - j <- tryGetRootItemInvID m i cr + let j = getRootItemInvID m i cr return $ cr & crManipulation . manObject . imRootSelectedItem .~ NInt j -- the following assumes that the crManipulation is correct @@ -49,7 +49,6 @@ crUpdateItemLocations :: Int -> LWorld -> LWorld crUpdateItemLocations crid lw = fromMaybe lw $ do mo <- lw ^? creatures . ix crid . crManipulation . manObject cinv <- lw ^? creatures . ix crid . crInv - --let crinv = IM.restrictKeys (lw ^. items) (IS.fromList $ IM.elems itids) let crinv = fmap (\k -> lw ^?! items . ix k) cinv return $ crSetRoots crid $ IM.foldlWithKey' (crUpdateInvidLocations mo crid) lw $ _unNIntMap crinv @@ -62,8 +61,7 @@ crSetRoots cid w = fromMaybe w $ do g w' i = w' & items . ix i . itLocation . ilIsRoot .~ False f :: LWorld -> DTree OItem -> LWorld f w' x = - w' - & items . ix (x ^. dtValue . _1 . itID . unNInt) . itLocation . ilIsRoot .~ True + w' & items . ix (x ^. dtValue . _1 . itID . unNInt) . itLocation . ilIsRoot .~ True crUpdateInvidLocations :: ManipulatedObject -> @@ -74,7 +72,7 @@ crUpdateInvidLocations :: LWorld crUpdateInvidLocations mo crid lw invid itm = lw - & creatures . ix crid . crInv . ix (NInt invid) .~ itid -- . itLocation .~ newloc + & creatures . ix crid . crInv . ix (NInt invid) .~ itid & items . ix itid .~ (itm & itLocation .~ newloc) where itid = itm ^. itID . unNInt @@ -85,8 +83,7 @@ crUpdateInvidLocations mo crid lw invid itm = , _ilIsRoot = Just (NInt invid) == mo ^? imRootSelectedItem , _ilIsSelected = Just (NInt invid) == mo ^? imSelectedItem , _ilIsAttached = invid `IS.member` (mo ^. imAttachedItems) - , _ilEquipSite = do - lw ^? items . ix itid . itLocation . ilEquipSite . _Just + , _ilEquipSite = lw ^? items . ix itid . itLocation . ilEquipSite . _Just } -- this should be looked at, as it is sometimes used in functions that need not diff --git a/tags b/tags index 1129a94ba..9503e460a 100644 --- a/tags +++ b/tags @@ -244,7 +244,7 @@ CombineInventoryChange src/Dodge/Data/World.hs 32;" C ComsSS src/Dodge/Data/Scenario.hs 98;" C ConcurrentEffect src/Loop/Data.hs 6;" t ConcurrentEffect src/Loop/Data.hs 11;" C -Configuration src/Dodge/Data/Config.hs 38;" t +Config src/Dodge/Data/Config.hs 38;" t ConstFloat src/Dodge/Data/GenFloat.hs 11;" C ConsumableItemType src/Dodge/Data/Item/Combine.hs 116;" t ContextDT src/Dodge/Data/DoubleTree.hs 84;" t @@ -2841,9 +2841,9 @@ centroid src/Geometry/Polygon.hs 136;" f centroidNum src/Geometry/Polygon.hs 139;" f chainCreatureUpdates src/Dodge/Creature/ChainUpdates.hs 6;" f chainPairs src/Geometry.hs 363;" f -changeSwapOther src/Dodge/Inventory.hs 148;" f -changeSwapSel src/Dodge/Inventory.hs 141;" f -changeSwapWith src/Dodge/Inventory.hs 182;" f +changeSwapOther src/Dodge/Inventory.hs 144;" f +changeSwapSel src/Dodge/Inventory.hs 137;" f +changeSwapWith src/Dodge/Inventory.hs 178;" f charToTuple src/Picture/Base.hs 317;" f charToTupleGrad src/Picture/Text.hs 18;" f chartreuse src/Color.hs 24;" f @@ -3026,14 +3026,14 @@ crNumFreeSlots src/Dodge/Inventory/CheckSlots.hs 25;" f crOnWall src/Dodge/WallCreatureCollisions.hs 86;" f crRad src/Dodge/Creature/Radius.hs 7;" f crSafeDistFromTarg src/Dodge/Creature/Test.hs 74;" f -crSetRoots src/Dodge/Inventory/Location.hs 56;" f +crSetRoots src/Dodge/Inventory/Location.hs 54;" f crShape src/Dodge/Creature/Shape.hs 8;" f crSpring src/Dodge/Update.hs 881;" f crStratConMatches src/Dodge/Creature/Test.hs 79;" f crStrength src/Dodge/Creature/Statistics.hs 25;" f crUpdate' src/Dodge/Creature/Update.hs 57;" f -crUpdateInvidLocations src/Dodge/Inventory/Location.hs 68;" f -crUpdateItemLocations src/Dodge/Inventory/Location.hs 48;" f +crUpdateInvidLocations src/Dodge/Inventory/Location.hs 65;" f +crUpdateItemLocations src/Dodge/Inventory/Location.hs 47;" f crVocalizationSound src/Dodge/Creature/Vocalization.hs 13;" f crWarningSounds src/Dodge/Creature/Vocalization.hs 23;" f crWlPbHit src/Dodge/WorldEvent/ThingsHit.hs 41;" f @@ -3045,7 +3045,7 @@ createFlIt src/Dodge/Placement/PlaceSpot.hs 185;" f createForceField src/Dodge/ForceField.hs 7;" f createGas src/Dodge/Gas.hs 8;" f createHeadLamp src/Dodge/Euse.hs 56;" f -createItemYou src/Dodge/Inventory/Add.hs 60;" f +createItemYou src/Dodge/Inventory/Add.hs 61;" f createLightMap src/Render.hs 26;" f createPathGrid src/Dodge/Room/Path.hs 21;" f createProjectile src/Dodge/HeldUse.hs 1313;" f @@ -3212,12 +3212,12 @@ deleteWallFromZones src/Dodge/Wall/Zone.hs 23;" f deleteWallID src/Dodge/Wall/Delete.hs 13;" f deleteWallIDs src/Dodge/Wall/Delete.hs 28;" f denormalEdges src/Polyhedra.hs 136;" f -destroyAllInvItems src/Dodge/Inventory.hs 54;" f +destroyAllInvItems src/Dodge/Inventory.hs 52;" f destroyBlock src/Dodge/Block.hs 52;" f destroyCreature src/Dodge/Creature/Update.hs 94;" f destroyDoor src/Dodge/Block.hs 80;" f destroyInvItem src/Dodge/Inventory.hs 39;" f -destroyItem src/Dodge/Inventory.hs 63;" f +destroyItem src/Dodge/Inventory.hs 61;" f destroyLS src/Dodge/LightSource.hs 32;" f destroyLSFlashAt src/Dodge/LightSource.hs 42;" f destroyMachine src/Dodge/Machine/Destroy.hs 13;" f @@ -3711,6 +3711,7 @@ getPJStabiliser src/Dodge/HeldUse.hs 1288;" f getPretty src/AesonHelp.hs 8;" f getPromptTM src/Dodge/Terminal/Type.hs 6;" f getRootItemBounds src/Dodge/Render/HUD.hs 96;" f +getRootItemInvID src/Dodge/Inventory/Location.hs 34;" f getSelectedCloseObj src/Dodge/SelectedClose.hs 14;" f getSmoothScrollValue src/Dodge/SmoothScroll.hs 21;" f getSplitString src/Dodge/Debug/Terminal.hs 126;" f @@ -3904,14 +3905,14 @@ invItemEffs src/Dodge/Creature/State.hs 62;" f invItemLocUpdate src/Dodge/Creature/State.hs 70;" f invRootMap src/Dodge/Item/Grammar.hs 226;" f invSelectionItem src/Dodge/Inventory/SelectionList.hs 32;" f -invSetSelection src/Dodge/Inventory.hs 194;" f -invSetSelectionPos src/Dodge/Inventory.hs 202;" f +invSetSelection src/Dodge/Inventory.hs 183;" f +invSetSelectionPos src/Dodge/Inventory.hs 191;" f invShiftPointBy src/Dodge/ShiftPoint.hs 8;" f invSize src/Dodge/Inventory/CheckSlots.hs 33;" f inventoryX src/Dodge/Creature.hs 113;" f -inverseSelNumPos src/Dodge/SelectionSections.hs 197;" f -inverseSelSecYint src/Dodge/SelectionSections.hs 168;" f -inverseSelSecYintXPosCheck src/Dodge/SelectionSections.hs 181;" f +inverseSelNumPos src/Dodge/SelectionSections.hs 193;" f +inverseSelSecYint src/Dodge/SelectionSections.hs 164;" f +inverseSelSecYintXPosCheck src/Dodge/SelectionSections.hs 177;" f inverseShockwaveAt src/Dodge/WorldEvent/Shockwave.hs 43;" f invertEncircleDistP src/Dodge/Creature/Boid.hs 14;" f invertIntMap src/IntMapHelp.hs 99;" f @@ -4453,8 +4454,8 @@ pesNearRect src/Dodge/Zoning/Pathing.hs 40;" f pesNearSeg src/Dodge/Zoning/Pathing.hs 37;" f picFormat src/Polyhedra.hs 23;" f picMap src/Picture/Base.hs 67;" f -pickUpItem src/Dodge/Inventory/Add.hs 68;" f -pickUpItemAt src/Dodge/Inventory/Add.hs 73;" f +pickUpItem src/Dodge/Inventory/Add.hs 69;" f +pickUpItemAt src/Dodge/Inventory/Add.hs 74;" f pickUpS src/Dodge/SoundLogic/ExternallyGeneratedSounds.hs 624;" f pincerP src/Dodge/Creature/Boid.hs 61;" f pincerP' src/Dodge/Creature/Boid.hs 94;" f @@ -4578,7 +4579,7 @@ polygonWire src/Picture/Base.hs 63;" f polysToPic src/Polyhedra.hs 130;" f popScreen src/Dodge/Menu/PushPop.hs 6;" f posRms src/Dodge/Tree/Shift.hs 44;" f -posSelSecYint src/Dodge/SelectionSections.hs 151;" f +posSelSecYint src/Dodge/SelectionSections.hs 147;" f positionRoomsFromTree src/Dodge/Tree/Shift.hs 35;" f postGenerationProcessing src/Dodge/LevelGen.hs 34;" f postUniverseLoadSideEffect src/Dodge/WorldLoad.hs 11;" f @@ -4803,7 +4804,7 @@ rightPadNoSquash src/Padding.hs 23;" f rlPosDir src/Dodge/RoomLink.hs 94;" f rlauncherPic src/Dodge/Item/Draw/SPic.hs 409;" f rmInLinks src/Dodge/RoomLink.hs 138;" f -rmInvItem src/Dodge/Inventory.hs 75;" f +rmInvItem src/Dodge/Inventory.hs 73;" f rmLinksOfType src/Dodge/RoomLink.hs 135;" f rmOutLinks src/Dodge/RoomLink.hs 138;" f roomC src/Dodge/Room/Room.hs 38;" f @@ -4895,8 +4896,8 @@ screenPolygon src/Dodge/Base/Window.hs 17;" f screenPolygonBord src/Dodge/Base/Window.hs 27;" f screenPosAbs src/Dodge/ScreenPos.hs 15;" f screenToWorldPos src/Dodge/Base/Coordinate.hs 51;" f -scrollAugInvSel src/Dodge/Inventory.hs 213;" f -scrollAugNextInSection src/Dodge/Inventory.hs 226;" f +scrollAugInvSel src/Dodge/Inventory.hs 194;" f +scrollAugNextInSection src/Dodge/Inventory.hs 207;" f scrollDebugInfoInt src/Dodge/Debug.hs 71;" f scrollRBOption src/Dodge/Update/Scroll.hs 217;" f scrollSelectionSections src/Dodge/SelectionSections.hs 28;" f @@ -4923,8 +4924,8 @@ selNumPosCardinal src/Dodge/Render/HUD.hs 473;" f selSecDrawCursor src/Dodge/Render/List.hs 126;" f selSecDrawCursorAt src/Dodge/Render/List.hs 104;" f selSecSelCol src/Dodge/Render/HUD.hs 504;" f -selSecSelSize src/Dodge/SelectionSections.hs 147;" f -selSecYint src/Dodge/SelectionSections.hs 156;" f +selSecSelSize src/Dodge/SelectionSections.hs 143;" f +selSecYint src/Dodge/SelectionSections.hs 152;" f selectCreatureDebugItem src/Dodge/Debug.hs 55;" f selectedItemScroll src/Dodge/Update/Scroll.hs 51;" f sensAboveDoor src/Dodge/Room/SensorDoor.hs 52;" f @@ -4949,7 +4950,7 @@ setFallback src/Dodge/PlacementSpot.hs 132;" f setInLinks src/Dodge/RoomLink.hs 51;" f setInLinksByType src/Dodge/RoomLink.hs 54;" f setInLinksPD src/Dodge/RoomLink.hs 74;" f -setInvPosFromSS src/Dodge/Inventory/Location.hs 95;" f +setInvPosFromSS src/Dodge/Inventory/Location.hs 91;" f setLayer src/Picture/Base.hs 139;" f setLinkType src/Dodge/RoomLink.hs 60;" f setLinkTypePD src/Dodge/RoomLink.hs 67;" f @@ -5151,9 +5152,9 @@ squareDecoration src/Dodge/Placement/TopDecoration.hs 41;" f squashIntersectCirclePoint src/Dodge/WallCreatureCollisions.hs 112;" f squashNormalizeV src/Geometry/Vector.hs 157;" f ssLookupDown src/Dodge/SelectionSections.hs 82;" f -ssLookupGE' src/Dodge/SelectionSections.hs 140;" f +ssLookupGE' src/Dodge/SelectionSections.hs 136;" f ssLookupGT src/Dodge/SelectionSections.hs 123;" f -ssLookupGT' src/Dodge/SelectionSections.hs 133;" f +ssLookupGT' src/Dodge/SelectionSections.hs 129;" f ssLookupLE' src/Dodge/SelectionSections.hs 111;" f ssLookupLT src/Dodge/SelectionSections.hs 98;" f ssLookupLT' src/Dodge/SelectionSections.hs 104;" f @@ -5205,7 +5206,7 @@ swapAnyExtraSelection src/Dodge/Inventory/Swap.hs 56;" f swapInOutLinks src/Dodge/RoomLink.hs 80;" f swapIndices src/ListHelp.hs 50;" f swapInvItems src/Dodge/Inventory/Swap.hs 21;" f -swapItemWith src/Dodge/Inventory.hs 171;" f +swapItemWith src/Dodge/Inventory.hs 167;" f swarmCrit src/Dodge/Creature/SwarmCrit.hs 10;" f swarmUsingCenter src/Dodge/Creature/Boid.hs 172;" f switchDoor src/Dodge/Placement/Instance/Door.hs 96;" f @@ -5392,13 +5393,12 @@ tryCombine src/Dodge/Update/Input/InGame.hs 542;" f tryDrawToCapacitor src/Dodge/Creature/State.hs 150;" f tryDropSelected src/Dodge/Update/Input/InGame.hs 137;" f tryGetChannel src/Sound.hs 97;" f -tryGetRootAttachedFromInvID src/Dodge/Inventory/Location.hs 23;" f -tryGetRootItemInvID src/Dodge/Inventory/Location.hs 35;" f +tryGetRootAttachedFromInvID src/Dodge/Inventory/Location.hs 22;" f tryMeleeAttack src/Dodge/Creature/ReaderUpdate.hs 38;" f tryPickupSelected src/Dodge/Update/Input/InGame.hs 144;" f tryPlay src/Sound.hs 84;" f tryPutItemInInv src/Dodge/Inventory/Add.hs 24;" f -tryPutItemInInvAt src/Dodge/Inventory/Add.hs 52;" f +tryPutItemInInvAt src/Dodge/Inventory/Add.hs 53;" f trySeedFromClipboard src/Dodge/Menu.hs 91;" f trySpin src/Dodge/Projectile/Update.hs 170;" f trySynthBullet src/Dodge/Creature/State.hs 166;" f @@ -5455,7 +5455,7 @@ updateBulVel src/Dodge/Bullet.hs 56;" f updateBullet src/Dodge/Bullet.hs 21;" f updateBullets src/Dodge/Update.hs 576;" f updateCamera src/Dodge/Update/Camera.hs 30;" f -updateCloseObjects src/Dodge/Inventory.hs 121;" f +updateCloseObjects src/Dodge/Inventory.hs 118;" f updateCloud src/Dodge/Update.hs 814;" f updateClouds src/Dodge/Update.hs 682;" f updateCombinePositioning src/Dodge/DisplayInventory.hs 39;" f @@ -5530,7 +5530,7 @@ updateRadarSweeps src/Dodge/Update.hs 676;" f updateRandNode src/TreeHelp.hs 108;" f updateRenderSplit appDodge/Main.hs 110;" f updateRightParentSF src/Dodge/Item/Grammar.hs 181;" f -updateRootItemID src/Dodge/Inventory/Location.hs 41;" f +updateRootItemID src/Dodge/Inventory/Location.hs 40;" f updateScopeZoom src/Dodge/Update/Scroll.hs 77;" f updateScrollTestValue src/Dodge/ScrollValue.hs 6;" f updateSection src/Dodge/DisplayInventory.hs 263;" f