Flatten values in creature manipulation data types

This commit is contained in:
2024-09-24 21:50:21 +01:00
parent fe00af0e73
commit 25cec10313
24 changed files with 69 additions and 86 deletions
+9 -9
View File
@@ -38,9 +38,9 @@ tryGetRootItemInvID i cr = do
updateRootItemID :: Creature -> Creature
updateRootItemID cr = fromMaybe cr $ do
i <- cr ^? crManipulation . manObject . inInventory . imSelectedItem
i <- cr ^? crManipulation . manObject . imSelectedItem
j <- tryGetRootItemInvID i cr
return $ cr & crManipulation . manObject . inInventory . imRootItem .~ j
return $ cr & crManipulation . manObject . imRootItem .~ j
-- the following assumes that the crManipulation is correct
crUpdateItemLocations :: Int -> LWorld -> LWorld
@@ -58,9 +58,9 @@ crUpdateInvidLocations mo crid lw invid itm = lw
newloc = InInv
{ _ilCrID = crid
, _ilInvID = invid
, _ilIsRoot = Just invid == mo ^? inInventory . imSelectedItem
, _ilIsSelected = Just invid == mo ^? inInventory . imRootItem
, _ilIsAttached = invid `IS.member` (mo ^. inInventory . imAttachedItems)
, _ilIsRoot = Just invid == mo ^? imSelectedItem
, _ilIsSelected = Just invid == mo ^? imRootItem
, _ilIsAttached = invid `IS.member` (mo ^. imAttachedItems)
}
-- this should be looked at, as it is sometimes used in functions that need not
@@ -75,15 +75,15 @@ setInvPosFromSS w =
sss <- w ^? hud . hudElement . diSections
(i, j) <- sss ^? sssExtra . sssSelPos . _Just
case i of
(-1) -> Just $ InInventory SortInventory
(-1) -> Just SortInventory
0 -> do
(rootid,aset) <- tryGetRootAttachedFromInvID j (you w ^. crInv)
return $ InInventory $ SelectedItem
return SelectedItem
{ _imSelectedItem = j
, _imRootItem = rootid
, _imAttachedItems = aset
}
1 -> Just SelNothing
2 -> Just $ InNearby SortNearby
3 -> Just $ InNearby $ SelCloseObject j
2 -> Just SortNearby
3 -> Just $ SelCloseObject j
_ -> error "selection out of bounds"
+3 -3
View File
@@ -20,7 +20,7 @@ updateRBList w
| otherwise = case w ^. rbOptions of
EquipOptions{} -> w
_ -> fromMaybe (w & rbOptions .~ NoRightButtonOptions) $ do
i <- cr ^? crManipulation . manObject . inInventory . imSelectedItem
i <- cr ^? crManipulation . manObject . imSelectedItem
esite <- cr ^? crInv . ix i . itUse . equipEffect . eeSite
return $
w
@@ -35,7 +35,7 @@ updateRBList w
-- find a free equipment slot
chooseEquipmentPosition :: Creature -> [EquipPosition] -> Int
chooseEquipmentPosition cr eps = fromMaybe (chooseFreeSite cr eps) $ do
i <- cr ^? crManipulation . manObject . inInventory . imSelectedItem
i <- cr ^? crManipulation . manObject . imSelectedItem
ep <- cr ^? crInvEquipped . ix i
elemIndex ep eps
@@ -46,7 +46,7 @@ chooseFreeSite cr = fromMaybe 0 . findIndex hasnoequipment
getEquipmentAllocation :: World -> EquipmentAllocation
getEquipmentAllocation w = fromMaybe DoNotMoveEquipment $ do
curpos <- you w ^? crManipulation . manObject . inInventory . imSelectedItem
curpos <- you w ^? crManipulation . manObject . imSelectedItem
esite <- you w ^? crInv . ix curpos . itUse . equipEffect . eeSite
i <- w ^? rbOptions . opSel
<|> Just (chooseEquipmentPosition (you w) (equipSiteToPositions esite))