Simplify right button options

This commit is contained in:
2023-05-15 11:06:13 +01:00
parent 0735b46266
commit a67e8667bc
4 changed files with 29 additions and 152 deletions
+2 -115
View File
@@ -4,7 +4,6 @@ module Dodge.Inventory (
rmSelectedInvItem,
rmInvItem,
updateCloseObjects,
updateRBList,
closeObjScrollDir,
changeSwapSel,
scrollAugInvSel,
@@ -12,10 +11,11 @@ module Dodge.Inventory (
crInvSize,
selectedCloseObject,
setInvPosFromSS,
module Dodge.Inventory.RBList
) where
import Dodge.Inventory.RBList
import Control.Applicative
import qualified Data.Map.Strict as M
import Data.Maybe
import Dodge.Base
import Dodge.Data.SelectionList
@@ -133,119 +133,6 @@ updateCloseObjects w =
updatebyid (Left flid) = fmap Left $ w ^? cWorld . lWorld . floorItems . ix (_flItID flid)
updatebyid (Right btid) = fmap Right $ w ^? cWorld . lWorld . buttons . ix (_btID btid)
updateRBList :: World -> World
updateRBList w
| w ^? rbOptions . opItemID == mcurrentitemid =
w & setEquipAllocation
| otherwise = fromMaybe (w & rbOptions .~ NoRightButtonOptions) $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
esite <- cr ^? crInv . ix i . itUse . equipEffect . eeSite
itid <- mcurrentitemid
return $
w
& rbOptions
.~ EquipOptions
{ _opEquip = equipSiteToPositions esite
, _opSel = chooseEquipmentPosition cr (equipSiteToPositions esite)
, _opItemID = itid
, _opAllocateEquipment = DoNotMoveEquipment
, _opActivateEquipment = NoChangeActivateEquipment
}
& setEquipAllocation
where
mcurrentitemid = do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
cr ^? crInv . ix i . itID
cr = you w
chooseEquipmentPosition :: Creature -> [EquipPosition] -> Int
chooseEquipmentPosition cr eps = fromMaybe (chooseFreeSite cr eps) $ do
i <- cr ^? crManipulation . manObject . inInventory . ispItem
ep <- cr ^? crInvEquipped . ix i
elemIndex ep eps
chooseFreeSite :: Creature -> [EquipPosition] -> Int
chooseFreeSite cr = fromMaybe 0 . findIndex hasnoequipment
where
hasnoequipment ep = isNothing $ cr ^? crEquipment . ix ep
setEquipAllocation :: World -> World
setEquipAllocation w = fromMaybe w $ do
curpos <- you w ^? crManipulation . manObject . inInventory . ispItem
i <- w ^? rbOptions . opSel
es <- w ^? rbOptions . opEquip . ix i
return $
w & rbOptions . opAllocateEquipment .~ case you w ^? crInvEquipped . ix curpos of
Just epos
| es == epos -> RemoveEquipment{_allocOldPos = epos}
Just epos
| isJust (you w ^? crEquipment . ix es) ->
SwapEquipment
{ _allocOldPos = epos
, _allocNewPos = es
, _allocSwapID = _crEquipment (you w) M.! es
}
Just epos ->
MoveEquipment
{ _allocOldPos = epos
, _allocNewPos = es
}
Nothing
| isJust (you w ^? crEquipment . ix es) ->
ReplaceEquipment
{ _allocNewPos = es
, _allocRemoveID = _crEquipment (you w) M.! es
}
Nothing -> PutOnEquipment{_allocNewPos = es}
--setEquipActivation :: World -> World
--setEquipActivation w = case w ^? rbOptions . opAllocateEquipment of
-- Just DoNotMoveEquipment -> w
-- Just RemoveEquipment{} ->
-- case you w ^. crLeftInvSel . lisMPos of
-- Just i
-- | Just i == minvsel ->
-- w & rbOptions . opActivateEquipment
-- .~ DeactivateEquipment
-- { _deactivateEquipment = i
-- }
-- _ -> w & rbOptions . opActivateEquipment .~ NoChangeActivateEquipment
-- Just rbos ->
-- case you w ^. crLeftInvSel . lisMPos of
-- Just i | Just i == minvsel -> w & rbOptions . opActivateEquipment .~ NoChangeActivateEquipment
-- Just i
-- | invselcanactivate ->
-- w & rbOptions . opActivateEquipment
-- .~ ActivateDeactivateEquipment
-- { _activateEquipment = fromJust minvsel
-- , _deactivateEquipment = i
-- }
-- Just i
-- | Just i == rbos ^? allocRemoveID ->
-- w & rbOptions . opActivateEquipment .~ DeactivateEquipment i
-- Just _ -> w & rbOptions . opActivateEquipment .~ NoChangeActivateEquipment
-- Nothing
-- | invselcanactivate ->
-- w & rbOptions . opActivateEquipment
-- .~ ActivateEquipment
-- { _activateEquipment = fromJust minvsel
-- }
-- Nothing -> w & rbOptions . opActivateEquipment .~ NoChangeActivateEquipment
-- Nothing -> w & rbOptions . opActivateEquipment .~ NoChangeActivateEquipment
-- where
-- minvsel = cr ^? crManipulation . manObject . inInventory . ispItem
-- cr = you w
-- invselcanactivate = isJust $ do
-- i <- minvsel
-- return $ cr ^? crInv . ix i . itUse . leftUse
equipSiteToPositions :: EquipSite -> [EquipPosition]
equipSiteToPositions es = case es of
GoesOnHead -> [OnHead]
GoesOnChest -> [OnChest]
GoesOnBack -> [OnBack]
GoesOnWrist -> [OnLeftWrist, OnRightWrist]
GoesOnLegs -> [OnLegs]
closeObjScrollDir :: Float -> World -> World
closeObjScrollDir x