Cleanup various equipment/right button code

This commit is contained in:
2025-08-27 00:45:58 +01:00
parent 79a0137d54
commit 7581c86d93
6 changed files with 25 additions and 32 deletions
+15 -22
View File
@@ -6,7 +6,7 @@ module Dodge.Inventory.RBList (
) where
import NewInt
import qualified Data.IntMap.Strict as IM
--import qualified Data.IntMap.Strict as IM
import Dodge.Data.Equipment.Misc
import Dodge.Data.EquipType
--import Control.Applicative
@@ -19,16 +19,16 @@ import Dodge.Data.World
import qualified SDL
updateRBList :: World -> World
updateRBList w = case w ^. rbOptions of
_ | norightclick -> w & rbOptions .~ NoRightButtonOptions
updateRBList w = case w ^. rbState of
_ | norightclick -> w & rbState .~ NoRightButtonState
EquipOptions{} -> w
_ -> fromMaybe (w & rbOptions .~ NoRightButtonOptions) $ do
_ -> fromMaybe (w & rbState .~ NoRightButtonState) $ do
i <- cr ^? crManipulation . manObject . imSelectedItem
itid <- cr ^? crInv . ix i
etype <- w ^? cWorld . lWorld . items . ix itid >>= equipType
return $ w & rbOptions
.~ EquipOptions
(chooseEquipPosition (w ^. cWorld . lWorld . items) cr (eqTypeToSites etype))
itm <- w ^? cWorld . lWorld . items . ix itid
etype <- equipType itm
return $ w & rbState
.~ EquipOptions (chooseEquipPosition itm cr (eqTypeToSites etype))
where
--norightclick = not $ SDL.ButtonRight `M.member` (w ^. input . mouseButtons)
norightclick = null $ w ^. input . mouseButtons . at SDL.ButtonRight
@@ -36,33 +36,26 @@ updateRBList w = case w ^. rbOptions of
-- want to choose the current position if the item is equipped, otherwise try to
-- find a free equipment slot
chooseEquipPosition :: IM.IntMap Item -> Creature -> [EquipSite] -> Int
chooseEquipPosition m cr eps = fromMaybe (chooseFreeSite cr eps) $ do
i <- cr ^? crManipulation . manObject . imSelectedItem
itid <- cr ^? crInv . ix i
ep <- m ^? ix itid . itLocation . ilEquipSite . _Just
chooseEquipPosition :: Item -> Creature -> [EquipSite] -> Int
chooseEquipPosition itm cr eps = fromMaybe (chooseFreeSite cr eps) $ do
ep <- itm ^? itLocation . ilEquipSite . _Just
elemIndex ep eps
chooseFreeSite :: Creature -> [EquipSite] -> Int
chooseFreeSite cr = fromMaybe 0 . findIndex hasnoequipment
where
hasnoequipment ep = isNothing $ cr ^? crEquipment . ix ep
hasnoequipment es = isNothing $ cr ^? crEquipment . ix es
equipmentDesignation :: NewInt InvInt -> World -> EquipmentAllocation
equipmentDesignation invid w = fromMaybe DoNotMoveEquipment $ do
itid <- you w ^? crInv . ix invid
etype <- w ^? cWorld . lWorld . items . ix itid >>= equipType
let mesite = w ^? cWorld . lWorld . items . ix itid . itLocation . ilEquipSite . _Just
i <- w ^? rbOptions . opSel
-- <|> (uncurry elemIndex =<< (mesite <&> (,eqSiteToPositions etype)))
-- <|> Just (chooseFreeSite (you w) (eqSiteToPositions etype))
---- <|> Just (chooseEquipPosition (w ^. cWorld . lWorld . items) (you w) (eqSiteToPositions etype))
i <- w ^? rbState . opSel
es <- eqTypeToSites etype ^? ix i
return $ case mesite of
Just epos
| es == epos -> RemoveEquipment{_allocOldPos = epos}
Just epos
| isJust (you w ^? crEquipment . ix es) ->
Just epos | es == epos -> RemoveEquipment{_allocOldPos = epos}
Just epos | isJust (you w ^? crEquipment . ix es) ->
SwapEquipment
{ _allocOldPos = epos
, _allocNewPos = es