Move towards unifying (your) creature manipulation with selection
This commit is contained in:
@@ -39,42 +39,36 @@ getRootItemInvID m i cr = fromMaybe i $ do
|
||||
theroot <- adj ^? ix i
|
||||
theroot ^? _1 . _Just . _1
|
||||
|
||||
updateRootItemID :: IM.IntMap Item -> Creature -> Creature
|
||||
updateRootItemID m cr = fromMaybe cr $ do
|
||||
i <- cr ^? crManipulation . manObject . imSelectedItem . unNInt
|
||||
updateRootItemID :: IM.IntMap Item -> Creature -> World -> World
|
||||
updateRootItemID m cr w = fromMaybe w $ do
|
||||
i <- w^?hud . manObject . imSelectedItem . unNInt
|
||||
let j = getRootItemInvID m i cr
|
||||
return $ cr & crManipulation . manObject . imRootSelectedItem .~ NInt j
|
||||
return $ w & hud . manObject . imRootSelectedItem .~ NInt j
|
||||
|
||||
-- the following assumes that the crManipulation is correct
|
||||
crUpdateItemLocations :: Int -> LWorld -> LWorld
|
||||
crUpdateItemLocations :: Int -> World -> World
|
||||
crUpdateItemLocations crid lw = fromMaybe lw $ do
|
||||
mo <- lw ^? creatures . ix crid . crManipulation . manObject
|
||||
cinv <- lw ^? creatures . ix crid . crInv
|
||||
let crinv = fmap (\k -> lw ^?! items . ix k) cinv
|
||||
mo <- lw ^? hud . manObject
|
||||
cinv <- lw ^? cWorld.lWorld.creatures . ix crid . crInv
|
||||
let crinv = fmap (\k -> lw ^?! cWorld.lWorld.items . ix k) cinv
|
||||
return $ crSetRoots crid $ IM.foldlWithKey' (crUpdateInvidLocations mo crid) lw $ _unNIntMap crinv
|
||||
|
||||
crSetRoots :: Int -> LWorld -> LWorld
|
||||
crSetRoots :: Int -> World -> World
|
||||
crSetRoots cid w = fromMaybe w $ do
|
||||
inv <- w ^? creatures . ix cid . crInv
|
||||
let cinv = invIMDT $ fmap (\i -> w ^?! items . ix i) inv
|
||||
inv <- w ^? cWorld .lWorld. creatures . ix cid . 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' & items . ix i . itLocation . ilIsRoot .~ False
|
||||
f :: LWorld -> DTree OItem -> LWorld
|
||||
g w' i = w' &cWorld.lWorld.items . ix i . itLocation . ilIsRoot .~ False
|
||||
f :: World -> DTree OItem -> World
|
||||
f w' x =
|
||||
w' & items . ix (x ^. dtValue . _1 . itID . unNInt) . itLocation . ilIsRoot .~ True
|
||||
w' &cWorld.lWorld.items . ix (x ^. dtValue . _1 . itID . unNInt) . itLocation . ilIsRoot .~ True
|
||||
|
||||
crUpdateInvidLocations ::
|
||||
ManipulatedObject ->
|
||||
Int ->
|
||||
LWorld ->
|
||||
Int ->
|
||||
Item ->
|
||||
LWorld
|
||||
crUpdateInvidLocations :: ManipulatedObject -> Int -> World -> Int -> Item -> World
|
||||
crUpdateInvidLocations mo crid lw invid itm =
|
||||
lw
|
||||
& creatures . ix crid . crInv . ix (NInt invid) .~ itid
|
||||
& items . ix itid .~ (itm & itLocation .~ newloc)
|
||||
&cWorld.lWorld.creatures . ix crid . crInv . ix (NInt invid) .~ itid
|
||||
&cWorld.lWorld.items . ix itid .~ (itm & itLocation .~ newloc)
|
||||
where
|
||||
itid = itm ^. itID . unNInt
|
||||
newloc =
|
||||
@@ -84,15 +78,16 @@ 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 = lw ^? items . ix itid . itLocation . ilEquipSite . _Just
|
||||
, _ilEquipSite = lw ^? cWorld .lWorld. items . ix itid . itLocation . ilEquipSite . _Just
|
||||
--revise1 , _ilEquipSite = lw ^? items . ix itid . itLocation . ilEquipSite . _Just
|
||||
}
|
||||
|
||||
-- this should be looked at, as it is sometimes used in functions that need not
|
||||
-- concern the player creature
|
||||
-- this might not work if the selpos is in the inventory but too large
|
||||
setInvPosFromSS :: World -> World
|
||||
setInvPosFromSS w = w
|
||||
& cWorld . lWorld . creatures . ix 0 . crManipulation . manObject .~ thesel
|
||||
setInvPosFromSS w = w &hud . manObject .~ thesel
|
||||
--revise1 & cWorld . lWorld . creatures . ix 0 . crManipulation . manObject .~ thesel
|
||||
where
|
||||
thesel = fromMaybe SelNothing $ do
|
||||
--Sel i j _ <- w ^? hud . diSelection . _Just
|
||||
|
||||
Reference in New Issue
Block a user