diff --git a/src/Dodge/Data/Item/Location.hs b/src/Dodge/Data/Item/Location.hs index 6cbbcae29..ebc52b3c0 100644 --- a/src/Dodge/Data/Item/Location.hs +++ b/src/Dodge/Data/Item/Location.hs @@ -29,8 +29,8 @@ data ItemLocation = InInv { _ilCrID :: Int , _ilInvID :: NewInt InvInt - , _ilIsRoot :: Bool -- of any item - , _ilIsSelected :: Bool +-- , _ilIsRoot :: Bool -- of any item +-- , _ilIsSelected :: Bool --- , _ilIsAttached :: Bool -- to selected item. question: downwards and upwards? , _ilEquipSite :: Maybe EquipSite } @@ -40,12 +40,9 @@ data ItemLocation deriving (Eq, Show, Ord, Read) --Generic, Flat) instance ShortShow ItemLocation where - shortShow (InInv cid invid rootb selb esite) = + shortShow (InInv cid invid esite) = "InInv:cid" <> shortShow cid <> "invid" <> shortShow (_unNInt invid) - <> "root" - <> shortShow rootb - <> "sel" - <> shortShow selb + <> "esite" <> shortShow (fmap (SString . show) esite) shortShow x = show x diff --git a/src/Dodge/Inventory/Add.hs b/src/Dodge/Inventory/Add.hs index 743740eb0..b12683c97 100644 --- a/src/Dodge/Inventory/Add.hs +++ b/src/Dodge/Inventory/Add.hs @@ -29,8 +29,8 @@ tryPutItemInInv mcipos itid w = do let itloc = InInv { _ilCrID = 0 , _ilInvID = invid - , _ilIsRoot = False - , _ilIsSelected = False +-- , _ilIsRoot = False +-- , _ilIsSelected = False -- , _ilIsAttached = False , _ilEquipSite = Nothing } diff --git a/src/Dodge/Inventory/Location.hs b/src/Dodge/Inventory/Location.hs index 95e420978..3bd020351 100644 --- a/src/Dodge/Inventory/Location.hs +++ b/src/Dodge/Inventory/Location.hs @@ -37,15 +37,16 @@ crUpdateItemLocations lw = fromMaybe lw $ do return $ crSetRoots $ IM.foldlWithKey' (crUpdateInvidLocations mo) lw $ _unNIntMap crinv crSetRoots :: World -> World -crSetRoots w = fromMaybe w $ do - inv <- w ^? cWorld . lWorld . creatures . ix 0 . crInv - let cinv = invIMDT $ fmap (\i -> w ^?! cWorld . lWorld . items . ix i) inv - return $ foldl' f (foldl' g w inv) cinv - where - g w' i = w' & cWorld . lWorld . items . ix i . itLocation . ilIsRoot .~ False - f :: World -> DTree OItem -> World - f w' x = - w' & cWorld . lWorld . items . ix (x ^. dtValue . _1 . itID . unNInt) . itLocation . ilIsRoot .~ True +crSetRoots w = fromMaybe w Nothing +-- $ do +-- inv <- w ^? cWorld . lWorld . creatures . ix 0 . crInv +-- let cinv = invIMDT $ fmap (\i -> w ^?! cWorld . lWorld . items . ix i) inv +-- return $ foldl' f (foldl' g w inv) cinv +-- where +-- g w' i = w' & cWorld . lWorld . items . ix i . itLocation . ilIsRoot .~ False +-- f :: World -> DTree OItem -> World +-- f w' x = +-- w' & cWorld . lWorld . items . ix (x ^. dtValue . _1 . itID . unNInt) . itLocation . ilIsRoot .~ True crUpdateInvidLocations :: ManipulatedObject -> World -> Int -> Item -> World crUpdateInvidLocations mo w invid itm = @@ -58,8 +59,8 @@ crUpdateInvidLocations mo w invid itm = InInv { _ilCrID = 0 , _ilInvID = NInt invid - , _ilIsRoot = Just (NInt invid) == mo ^? hiRootSelectedItem - , _ilIsSelected = Just (Sel 0 invid) == w ^? hud . diSelection . _Just +-- , _ilIsRoot = Just (NInt invid) == mo ^? hiRootSelectedItem +-- , _ilIsSelected = Just (Sel 0 invid) == w ^? hud . diSelection . _Just -- , _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 5ad746e37..c86ee5efd 100644 --- a/src/Dodge/Item/BackgroundEffect.hs +++ b/src/Dodge/Item/BackgroundEffect.hs @@ -36,9 +36,14 @@ rootNotrootEff :: Creature -> World -> World -rootNotrootEff f g it - | it ^? itLocation . ilIsRoot == Just True = f it - | otherwise = g it +rootNotrootEff f g it cr w + | isroot = f it cr w + | otherwise = g it cr w + where + isroot = fromMaybe False $ do + i <- it ^? itLocation . ilInvID + j <- w ^? hud . manObject . hiRootSelectedItem + return $ i == j rootAndAttNotEff :: (Item -> Creature -> World -> World) -> @@ -48,8 +53,7 @@ rootAndAttNotEff :: World -> World rootAndAttNotEff f g it cr w - | it ^? itLocation . ilIsRoot == Just True - && isattached + | isroot && isattached = f it cr w | otherwise = g it cr w where @@ -57,6 +61,10 @@ rootAndAttNotEff f g it cr w i <- it ^? itLocation . ilInvID . unNInt is <- w ^? hud . manObject . hiAttachedItems return $ i `IS.member` is + isroot = fromMaybe False $ do + i <- it ^? itLocation . ilInvID + j <- w ^? hud . manObject . hiRootSelectedItem + return $ i == j createShieldWall :: Item -> Creature -> World -> World createShieldWall it cr w = case it ^? itParams . flatShieldWlMIX . _Just of