From e521a1572aad3ca08a2723e96626342975375d2b Mon Sep 17 00:00:00 2001 From: justin Date: Sat, 16 May 2026 12:37:04 +0100 Subject: [PATCH] Remove _ilIsSelected --- src/Dodge/Creature/Impulse/UseItem.hs | 6 +++++- src/Dodge/Creature/State.hs | 18 +++++++++++++----- src/Dodge/Data/Item/Location.hs | 6 ++---- src/Dodge/Inventory/Add.hs | 2 +- src/Dodge/Inventory/Location.hs | 2 +- src/Dodge/Item/BackgroundEffect.hs | 16 ++++++++++++---- 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/Dodge/Creature/Impulse/UseItem.hs b/src/Dodge/Creature/Impulse/UseItem.hs index 3a7be3b9a..a1380b17c 100644 --- a/src/Dodge/Creature/Impulse/UseItem.hs +++ b/src/Dodge/Creature/Impulse/UseItem.hs @@ -2,6 +2,7 @@ module Dodge.Creature.Impulse.UseItem (useItem) where +import qualified Data.IntSet as IS import Dodge.Euse import NewInt import Control.Lens @@ -28,7 +29,10 @@ useItem invid pt w = fmap (worldEventFlags . at InventoryChange ?~ ()) $ do useItemLoc :: Creature -> LocationDT OItem -> Int -> World -> Maybe World useItemLoc cr loc pt w | aimuse - , fromMaybe False $ loc ^? locDT . dtValue . _1 . itLocation . ilIsAttached + , fromMaybe False $ do + i <- loc ^? locDT . dtValue . _1 . itLocation . ilInvID . unNInt + is <- w ^? hud . manObject . hiAttachedItems + return $ i `IS.member` is , Aiming{} <- cr ^. crStance . posture = return $ gadgetEffect pt loc cr w | GadgetPlatformSF <- sf = diff --git a/src/Dodge/Creature/State.hs b/src/Dodge/Creature/State.hs index 8bf393912..afd4e9ea9 100644 --- a/src/Dodge/Creature/State.hs +++ b/src/Dodge/Creature/State.hs @@ -4,6 +4,7 @@ module Dodge.Creature.State ( invItemEffs, ) where +import qualified Data.IntSet as IS import Dodge.Creature.Radius import qualified Data.IntMap.Strict as IM import Linear @@ -106,19 +107,23 @@ invItemLocUpdate cr loc w = doAnyEquipmentEffect loc cr $ case itm ^. itType of HELD MINIGUNX{} -> coolMinigun itm w HELD MACHINEPISTOL{} -> coolMachinePistol cr itm w LASER | loc ^. locDT . dtValue . _2 == WeaponTargetingSF - , itm ^? itLocation . ilIsAttached == Just True -> shineTargetLaser cr loc w + , isattached -> shineTargetLaser cr loc w HELD LED - | itm ^? itLocation . ilIsAttached == Just True -> shineTorch cr loc w + | isattached -> shineTorch cr loc w TARGETING tt - | itm ^? itLocation . ilIsAttached == Just True -> updateItemTargeting tt cr itm w + | isattached -> updateItemTargeting tt cr itm w ARHUD - | itm ^? itLocation . ilIsAttached == Just True -> drawARHUD loc w + | isattached -> drawARHUD loc w _ -> w where haspulse = w ^? cWorld . lWorld . creatures . ix 0 . crType . avatarPulse . pulseProgress == Just 0 itm = loc ^. locDT . dtValue . _1 + isattached = fromMaybe False $ do + i <- itm ^? itLocation . ilInvID . unNInt + is <- w ^? hud . manObject . hiAttachedItems + return $ i `IS.member` is coolMinigun :: Item -> World -> World coolMinigun itm @@ -312,7 +317,10 @@ updateItemTargeting tt cr itm w = case tt of where pointittarg = cWorld . lWorld . items . ix itid . itTargeting itid = itm ^. itID . unNInt - isattached = itm ^?! itLocation . ilIsAttached + isattached = fromMaybe False $ do + i <- itm ^? itLocation . ilInvID . unNInt + is <- w ^? hud . manObject . hiAttachedItems + return $ i `IS.member` is rbpressed = SDL.ButtonRight `M.member` _mouseButtons (_input w) setRBCreatureTargeting :: Creature -> World -> ItemTargeting -> ItemTargeting diff --git a/src/Dodge/Data/Item/Location.hs b/src/Dodge/Data/Item/Location.hs index 1910c2d12..10a7606fb 100644 --- a/src/Dodge/Data/Item/Location.hs +++ b/src/Dodge/Data/Item/Location.hs @@ -31,7 +31,7 @@ data ItemLocation , _ilInvID :: NewInt InvInt , _ilIsRoot :: Bool -- of any item , _ilIsSelected :: Bool - , _ilIsAttached :: Bool -- to selected item. question: downwards and upwards? +-- , _ilIsAttached :: Bool -- to selected item. question: downwards and upwards? , _ilEquipSite :: Maybe EquipSite } | OnTurret {_ilTuID :: Int} @@ -40,14 +40,12 @@ data ItemLocation deriving (Eq, Show, Ord, Read) --Generic, Flat) instance ShortShow ItemLocation where - shortShow (InInv cid invid rootb selb attb esite) = + shortShow (InInv cid invid rootb selb esite) = "InInv:cid" <> shortShow cid <> "invid" <> shortShow (_unNInt invid) <> "root" <> shortShow rootb <> "sel" <> shortShow selb - <> "att" - <> shortShow attb <> shortShow (fmap (SString . show) esite) shortShow x = show x diff --git a/src/Dodge/Inventory/Add.hs b/src/Dodge/Inventory/Add.hs index dea7455f3..743740eb0 100644 --- a/src/Dodge/Inventory/Add.hs +++ b/src/Dodge/Inventory/Add.hs @@ -31,7 +31,7 @@ tryPutItemInInv mcipos itid w = do , _ilInvID = invid , _ilIsRoot = False , _ilIsSelected = False - , _ilIsAttached = False +-- , _ilIsAttached = False , _ilEquipSite = Nothing } return $ (invid,) $ diff --git a/src/Dodge/Inventory/Location.hs b/src/Dodge/Inventory/Location.hs index f785bf4f0..95e420978 100644 --- a/src/Dodge/Inventory/Location.hs +++ b/src/Dodge/Inventory/Location.hs @@ -60,7 +60,7 @@ crUpdateInvidLocations mo w invid itm = , _ilInvID = NInt invid , _ilIsRoot = Just (NInt invid) == mo ^? hiRootSelectedItem , _ilIsSelected = Just (Sel 0 invid) == w ^? hud . diSelection . _Just - , _ilIsAttached = invid `IS.member` (mo ^. hiAttachedItems) +-- , _ilIsAttached = invid `IS.member` (mo ^. hiAttachedItems) , _ilEquipSite = w ^? cWorld . lWorld . items . ix itid . itLocation . ilEquipSite . _Just } diff --git a/src/Dodge/Item/BackgroundEffect.hs b/src/Dodge/Item/BackgroundEffect.hs index 9cf257219..5ad746e37 100644 --- a/src/Dodge/Item/BackgroundEffect.hs +++ b/src/Dodge/Item/BackgroundEffect.hs @@ -7,6 +7,7 @@ module Dodge.Item.BackgroundEffect ( removeShieldWall, ) where +import NewInt import Linear import Control.Lens import Dodge.Creature.Radius @@ -19,6 +20,8 @@ import Dodge.Wall.Create import Dodge.Wall.Delete import Dodge.Wall.Move import Geometry.Vector +import qualified Data.IntSet as IS +import Data.Maybe cancelExamineInventory :: World -> World cancelExamineInventory = hud . subInventory %~ f @@ -44,11 +47,16 @@ rootAndAttNotEff :: Creature -> World -> World -rootAndAttNotEff f g it +rootAndAttNotEff f g it cr w | it ^? itLocation . ilIsRoot == Just True - && it ^? itLocation . ilIsAttached == Just True - = f it - | otherwise = g it + && isattached + = f it cr w + | otherwise = g it cr w + where + isattached = fromMaybe False $ do + i <- it ^? itLocation . ilInvID . unNInt + is <- w ^? hud . manObject . hiAttachedItems + return $ i `IS.member` is createShieldWall :: Item -> Creature -> World -> World createShieldWall it cr w = case it ^? itParams . flatShieldWlMIX . _Just of