Remove invTrees function

This commit is contained in:
2024-11-29 20:47:16 +00:00
parent de4a955206
commit 59c65b059a
3 changed files with 5 additions and 33 deletions
+1 -12
View File
@@ -40,16 +40,6 @@ useRootItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w
where
fst3 (x,_,_) = x
-- where
-- UseHotkey{} -> doequipmentchange
-- UseEquip{} -> doequipmentchange
-- (UseConsume eff) -> useC eff (_ldtValue itmtree) cr w
-- UseCraft{} -> w
-- UseAttach{} -> selectUse itmtree cr w
-- UseAmmoMag{} -> w
-- UseScope{} -> w
-- UseBulletMod{} -> w
toggleEquipmentAt :: Int -> Creature -> World -> World
toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
DoNotMoveEquipment -> w
@@ -108,8 +98,7 @@ useItemLeftClick cr w = fromMaybe w $ do
UseHotkey{} -> return $ doequipmentchange invid
UseAmmoMag{} -> return w
UseAttach{} -> do
itmtree <- invTrees (_crInv cr) ^? ix invid
return $ selectUse itmtree cr w
return $ selectUse itm cr w
_ -> Nothing
where
doequipmentchange invid = fromMaybe w $ do
-15
View File
@@ -1,6 +1,5 @@
module Dodge.Item.Grammar (
invLDT,
invTrees,
invAdj,
invRootMap,
invRootTrees,
@@ -9,7 +8,6 @@ module Dodge.Item.Grammar (
) where
import Control.Applicative
import Data.Bifunctor
import qualified Data.IntMap.Strict as IM
import Data.Maybe
import Dodge.Data.ComposedItem
@@ -205,19 +203,6 @@ invAdj = IM.unions . map g . invLDT
(error ("invAdj item " ++ show (_itID itm) ++ " location: " ++ show (itm ^? itLocation)))
$ itm ^? itLocation . ilInvID
-- returns an intmap with trees for all items
invTrees :: IM.IntMap Item -> IM.IntMap (LabelDoubleTree ComposeLinkType Item)
invTrees = fmap (first _iatType) . invTrees'
-- returns an intmap with trees for all items
invTrees' :: IM.IntMap Item -> IM.IntMap (LabelDoubleTree ItemLink Item)
--invTrees' = IM.unions . map (ldtToIM getindex . fmap (^. _1)) . map (fmap (\(x, y, _) -> (x, y))) . invLDT
invTrees' = IM.unions . map (ldtToIM getindex . fmap (^. _1)) . invLDT
where
getindex i =
fromMaybe (error "in invTrees try to get non-inventory item tree") $
i ^? itLocation . ilInvID
-- returns an intmap with trees for (only!) root items, indexed by inventory position
invRootTrees :: IM.IntMap Item -> IM.IntMap (LabelDoubleTree ItemLink ComposedItem)
invRootTrees = IM.fromDistinctAscList . reverse . map getid . invLDT
+4 -6
View File
@@ -4,17 +4,15 @@ import Control.Monad
import qualified SDL
import Control.Lens
import Data.Maybe
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
import Dodge.Data.World
import Dodge.Payload
selectUse :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
selectUse ittree _ w = fromMaybe w $ do
selectUse :: Item -> Creature -> World -> World
selectUse itm _ w = fromMaybe w $ do
lbtime <- w ^? input . mouseButtons . ix SDL.ButtonLeft
guard $ lbtime == 0
itid <- ittree ^? ldtValue . itID
pjid <- ittree ^? ldtValue . itUse . uaParams . apLinkedProjectile . _Just
itid <- itm ^? itID
pjid <- itm ^? itUse . uaParams . apLinkedProjectile . _Just
thepj <- w ^? cWorld . lWorld . projectiles . ix pjid
return $
w