Cleanup
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user