Remove reduntant left click item use code

This commit is contained in:
2024-11-29 20:40:14 +00:00
parent 1b99b73f44
commit de4a955206
9 changed files with 256 additions and 285 deletions
+11 -33
View File
@@ -1,7 +1,6 @@
module Dodge.Creature.Impulse.UseItem (
useRootItem,
useItemLeftClick,
itemUseEffect,
useItemHotkey,
) where
@@ -51,26 +50,6 @@ useRootItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w
-- UseScope{} -> w
-- UseBulletMod{} -> w
itemUseEffect :: Creature -> LabelDoubleTree ComposeLinkType Item -> World -> World
itemUseEffect cr itmtree w = case itmtree ^. ldtValue . itUse of
UseHeld{} ->
heldEffect itmtree cr w
& pointerToItem itm . itUse . heldHammer .~ HammerDown
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
where
itm = itmtree ^. ldtValue
doequipmentchange = fromMaybe w $ do
guard (_crHammerPosition cr == HammerUp)
invid <- itm ^? itLocation . ilInvID
return $ toggleEquipmentAt invid cr w
toggleEquipmentAt :: Int -> Creature -> World -> World
toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
DoNotMoveEquipment -> w
@@ -120,23 +99,22 @@ useItemLeftClick :: Creature -> World -> World
useItemLeftClick cr w = fromMaybe w $ do
guard . not $ _crInvLock cr
invid <- cr ^? crManipulation . manObject . imSelectedItem
itm <- cr ^? crInv . ix invid
ituse <- cr ^? crInv . ix invid . itUse
case ituse of
UseHeld{} -> return w
UseConsume{} -> return $ useItemLeftClick' cr w
UseEquip{} -> return $ useItemLeftClick' cr w
UseHotkey{} -> return $ useItemLeftClick' cr w
UseConsume eff -> return $ useC eff itm cr w
UseEquip{} -> return $ doequipmentchange invid
UseHotkey{} -> return $ doequipmentchange invid
UseAmmoMag{} -> return w
UseAttach{} -> do
itmtree <- invTrees (_crInv cr) ^? ix invid
return $ selectUse itmtree cr w
_ -> Nothing
useItemLeftClick' :: Creature -> World -> World
useItemLeftClick' cr' w = fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix (_crID cr')
itRef <- cr ^? crManipulation . manObject . imSelectedItem
it <- invTrees (_crInv cr) ^? ix itRef
return $
itemUseEffect cr it w
& worldEventFlags . at InventoryChange ?~ ()
where
doequipmentchange invid = fromMaybe w $ do
guard (_crHammerPosition cr == HammerUp)
return $ toggleEquipmentAt invid cr w
-- & f
-- where
+1 -3
View File
@@ -138,6 +138,4 @@ shoulderSH = translateSHz 20
drawEquipment :: Creature -> SPic
{-# INLINE drawEquipment #-}
drawEquipment cr = foldMap
(itemEquipPict cr)
(invLDT $ _crInv cr)
drawEquipment cr = foldMap (itemEquipPict cr) (invLDT $ _crInv cr)
+1 -2
View File
@@ -253,10 +253,9 @@ chainLinkOrientation ::
ItemLink ->
ComposedItem ->
(Point3, Q.Quaternion Float)
chainLinkOrientation mo (par, _, _) (ILink lt f) (child, _, _) =
chainLinkOrientation (p,q) (par, _, _) (ILink lt f) (child, _, _) =
(p + Q.rotate q p1, q * q1)
where
(p, q) = mo
(p1, q1) = f par lt child
updateItemWithOrientation ::
+1 -4
View File
@@ -16,9 +16,7 @@ import Dodge.Data.SoundOrigin
import Geometry.Data
import Sound.Data
data ItCrWdWd
= ItCrWdId
| ItCrWdItemEffect
data ItCrWdWd = ItCrWdItemHeldEffect
--deriving (Eq, Ord, Show, Read) --Generic, Flat)
data WdWd
@@ -32,7 +30,6 @@ data WdWd
| MakeStartCloudAt Point3
| TorqueCr Float Int
| WdWdNegateTrig Int
| WdWdFromItixCrixWdWd Int Int ItCrWdWd
| WdWdFromItCrixWdWd (LabelDoubleTree ComposeLinkType Item) Int ItCrWdWd
| MakeTempLight LSParam Int
--deriving (Eq, Show, Read) --, Generic)
+1 -1
View File
@@ -54,7 +54,7 @@ heldEffectMuzzles t cr w =
-- need to be careful about inventory lock or item ids here
doWeaponRepetitions :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
doWeaponRepetitions itm cr = case itm ^? ldtValue . itUse . heldParams . weaponRepeat of
Just (x : xs) -> cWorld . lWorld . delayedEvents .++~ ((x : xs) <&> (,WdWdFromItCrixWdWd upitm (_crID cr) ItCrWdItemEffect))
Just (x : xs) -> cWorld . lWorld . delayedEvents .++~ ((x : xs) <&> (,WdWdFromItCrixWdWd upitm (_crID cr) ItCrWdItemHeldEffect))
_ -> id
where
upitm =
+26 -14
View File
@@ -72,8 +72,8 @@ itemToBreakLists itm itmf = case (itm ^. itType, itmf) of
, []
)
(_, WeaponTargetingSF) -> (getAmmoLinks itm ++ [(AugmentedHUDSF, AugmentedHUDLink)], [])
(ATTACH BULLETSYNTH, _)
-> ([(AmmoMagSF ElectricalAmmo, AmmoInLink 0 ElectricalAmmo)],[])
(ATTACH BULLETSYNTH, _) ->
([(AmmoMagSF ElectricalAmmo, AmmoInLink 0 ElectricalAmmo)], [])
_ -> ([], [])
getAmmoLinks :: Item -> [(ItemStructuralFunction, ComposeLinkType)]
@@ -186,7 +186,10 @@ invLDT =
-- consider explicitly reseting the inventory ids (but this probably really
-- should be done upstream anyway in the actually creature inventory)
invRootMap :: IM.IntMap Item -> IM.IntMap (Maybe Int, DoubleTree Item)
invRootMap = foldMap (dtToIntMapWithRoot (^?! itLocation . ilInvID) . fmap (^. _1) . ldtToDT) . invLDT
invRootMap =
foldMap
(dtToIntMapWithRoot (^?! itLocation . ilInvID) . fmap (^. _1) . ldtToDT)
. invLDT
-- this assumes the creature inventory is well formed, specifically the
-- location ids
@@ -208,7 +211,8 @@ 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)) . 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") $
@@ -216,10 +220,11 @@ invTrees' = IM.unions . map (ldtToIM getindex . fmap (^. _1)) . map (fmap (\(x,
-- 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
invRootTrees = IM.fromDistinctAscList . reverse . map getid . invLDT
where
getid :: LabelDoubleTree ItemLink ComposedItem
-> (Int, LabelDoubleTree ItemLink ComposedItem)
getid ::
LabelDoubleTree ItemLink ComposedItem ->
(Int, LabelDoubleTree ItemLink ComposedItem)
getid t = (t ^?! ldtValue . _1 . itLocation . ilInvID, t)
-- returns an intmap with indents and locations for all items
@@ -228,10 +233,17 @@ allInvLocs inv = foldMap (f . LocLDT TopLDT) (IM.elems (invRootTrees inv)) mempt
where
f t = cldtPropagateFold h h g 0 t id
h x _ _ _ = x + 1
g :: Int -> LocationLDT ItemLink ComposedItem
-> (IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
-> IM.IntMap (Int, LocationLDT ItemLink ComposedItem))
-> IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
-> IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
g x ldt = (.) (IM.insert (ldt ^?! locLDT . ldtValue . _1 . itLocation . ilInvID)
(x, ldt))
g ::
Int ->
LocationLDT ItemLink ComposedItem ->
( IM.IntMap (Int, LocationLDT ItemLink ComposedItem) ->
IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
) ->
IM.IntMap (Int, LocationLDT ItemLink ComposedItem) ->
IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
g x ldt =
(.)
( IM.insert
(ldt ^?! locLDT . ldtValue . _1 . itLocation . ilInvID)
(x, ldt)
)
+4
View File
@@ -1,5 +1,7 @@
module Dodge.SelectUse (selectUse) where
import Control.Monad
import qualified SDL
import Control.Lens
import Data.Maybe
import Dodge.Data.ComposedItem
@@ -9,6 +11,8 @@ import Dodge.Payload
selectUse :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
selectUse ittree _ 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
thepj <- w ^? cWorld . lWorld . projectiles . ix pjid
+2 -11
View File
@@ -5,13 +5,12 @@ module Dodge.WorldEffect (
lineOutputTerminal,
) where
import Dodge.Item.Grammar
import Dodge.HeldUse
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
import Data.Foldable
import qualified Data.Map.Strict as M
import Data.Maybe
import Dodge.Creature.Impulse.UseItem
import Dodge.Data.World
import Dodge.Default
import Dodge.Inventory.Lock
@@ -35,13 +34,6 @@ doWdWd we = case we of
TorqueCr x cid -> torqueCr x cid
SoundStart so p sid mi -> soundStart so p sid mi
WdWdNegateTrig trid -> cWorld . lWorld . triggers . ix trid %~ not
--WdWdFromItixCrixWdWd itid crid f -> \w -> fromMaybe w $ do
WdWdFromItixCrixWdWd _ crid f -> \w -> fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix crid
--it <- getItem itid w
itRef <- cr ^? crManipulation . manObject . imSelectedItem
it <- invTrees (_crInv cr) ^? ix itRef -- note this probably doesn't always work, invTrees probably only returns rooted trees
return $ doItCrWdWd f it cr w
WdWdFromItCrixWdWd it crid f -> \w -> fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix crid
return $ doItCrWdWd f it cr w
@@ -51,8 +43,7 @@ doWdWd we = case we of
doItCrWdWd :: ItCrWdWd -> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
doItCrWdWd icww = case icww of
ItCrWdId -> \_ _ -> id
ItCrWdItemEffect -> flip itemUseEffect
ItCrWdItemHeldEffect -> heldEffect
accessTerminal :: Maybe Int -> World -> World
accessTerminal mtmid w = fromMaybe w $ do
+209 -217
View File
File diff suppressed because it is too large Load Diff