Remove reduntant left click item use code
This commit is contained in:
@@ -1,7 +1,6 @@
|
|||||||
module Dodge.Creature.Impulse.UseItem (
|
module Dodge.Creature.Impulse.UseItem (
|
||||||
useRootItem,
|
useRootItem,
|
||||||
useItemLeftClick,
|
useItemLeftClick,
|
||||||
itemUseEffect,
|
|
||||||
useItemHotkey,
|
useItemHotkey,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
@@ -51,26 +50,6 @@ useRootItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w
|
|||||||
-- UseScope{} -> w
|
-- UseScope{} -> w
|
||||||
-- UseBulletMod{} -> 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 :: Int -> Creature -> World -> World
|
||||||
toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
|
toggleEquipmentAt invid cr w = case getEquipmentAllocation w of
|
||||||
DoNotMoveEquipment -> w
|
DoNotMoveEquipment -> w
|
||||||
@@ -120,23 +99,22 @@ useItemLeftClick :: Creature -> World -> World
|
|||||||
useItemLeftClick cr w = fromMaybe w $ do
|
useItemLeftClick cr w = fromMaybe w $ do
|
||||||
guard . not $ _crInvLock cr
|
guard . not $ _crInvLock cr
|
||||||
invid <- cr ^? crManipulation . manObject . imSelectedItem
|
invid <- cr ^? crManipulation . manObject . imSelectedItem
|
||||||
|
itm <- cr ^? crInv . ix invid
|
||||||
ituse <- cr ^? crInv . ix invid . itUse
|
ituse <- cr ^? crInv . ix invid . itUse
|
||||||
case ituse of
|
case ituse of
|
||||||
UseHeld{} -> return w
|
UseHeld{} -> return w
|
||||||
UseConsume{} -> return $ useItemLeftClick' cr w
|
UseConsume eff -> return $ useC eff itm cr w
|
||||||
UseEquip{} -> return $ useItemLeftClick' cr w
|
UseEquip{} -> return $ doequipmentchange invid
|
||||||
UseHotkey{} -> return $ useItemLeftClick' cr w
|
UseHotkey{} -> return $ doequipmentchange invid
|
||||||
UseAmmoMag{} -> return w
|
UseAmmoMag{} -> return w
|
||||||
|
UseAttach{} -> do
|
||||||
|
itmtree <- invTrees (_crInv cr) ^? ix invid
|
||||||
|
return $ selectUse itmtree cr w
|
||||||
_ -> Nothing
|
_ -> Nothing
|
||||||
|
where
|
||||||
useItemLeftClick' :: Creature -> World -> World
|
doequipmentchange invid = fromMaybe w $ do
|
||||||
useItemLeftClick' cr' w = fromMaybe w $ do
|
guard (_crHammerPosition cr == HammerUp)
|
||||||
cr <- w ^? cWorld . lWorld . creatures . ix (_crID cr')
|
return $ toggleEquipmentAt invid cr w
|
||||||
itRef <- cr ^? crManipulation . manObject . imSelectedItem
|
|
||||||
it <- invTrees (_crInv cr) ^? ix itRef
|
|
||||||
return $
|
|
||||||
itemUseEffect cr it w
|
|
||||||
& worldEventFlags . at InventoryChange ?~ ()
|
|
||||||
|
|
||||||
-- & f
|
-- & f
|
||||||
-- where
|
-- where
|
||||||
|
|||||||
@@ -138,6 +138,4 @@ shoulderSH = translateSHz 20
|
|||||||
|
|
||||||
drawEquipment :: Creature -> SPic
|
drawEquipment :: Creature -> SPic
|
||||||
{-# INLINE drawEquipment #-}
|
{-# INLINE drawEquipment #-}
|
||||||
drawEquipment cr = foldMap
|
drawEquipment cr = foldMap (itemEquipPict cr) (invLDT $ _crInv cr)
|
||||||
(itemEquipPict cr)
|
|
||||||
(invLDT $ _crInv cr)
|
|
||||||
|
|||||||
@@ -253,10 +253,9 @@ chainLinkOrientation ::
|
|||||||
ItemLink ->
|
ItemLink ->
|
||||||
ComposedItem ->
|
ComposedItem ->
|
||||||
(Point3, Q.Quaternion Float)
|
(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)
|
(p + Q.rotate q p1, q * q1)
|
||||||
where
|
where
|
||||||
(p, q) = mo
|
|
||||||
(p1, q1) = f par lt child
|
(p1, q1) = f par lt child
|
||||||
|
|
||||||
updateItemWithOrientation ::
|
updateItemWithOrientation ::
|
||||||
|
|||||||
@@ -16,9 +16,7 @@ import Dodge.Data.SoundOrigin
|
|||||||
import Geometry.Data
|
import Geometry.Data
|
||||||
import Sound.Data
|
import Sound.Data
|
||||||
|
|
||||||
data ItCrWdWd
|
data ItCrWdWd = ItCrWdItemHeldEffect
|
||||||
= ItCrWdId
|
|
||||||
| ItCrWdItemEffect
|
|
||||||
--deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
--deriving (Eq, Ord, Show, Read) --Generic, Flat)
|
||||||
|
|
||||||
data WdWd
|
data WdWd
|
||||||
@@ -32,7 +30,6 @@ data WdWd
|
|||||||
| MakeStartCloudAt Point3
|
| MakeStartCloudAt Point3
|
||||||
| TorqueCr Float Int
|
| TorqueCr Float Int
|
||||||
| WdWdNegateTrig Int
|
| WdWdNegateTrig Int
|
||||||
| WdWdFromItixCrixWdWd Int Int ItCrWdWd
|
|
||||||
| WdWdFromItCrixWdWd (LabelDoubleTree ComposeLinkType Item) Int ItCrWdWd
|
| WdWdFromItCrixWdWd (LabelDoubleTree ComposeLinkType Item) Int ItCrWdWd
|
||||||
| MakeTempLight LSParam Int
|
| MakeTempLight LSParam Int
|
||||||
--deriving (Eq, Show, Read) --, Generic)
|
--deriving (Eq, Show, Read) --, Generic)
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ heldEffectMuzzles t cr w =
|
|||||||
-- need to be careful about inventory lock or item ids here
|
-- need to be careful about inventory lock or item ids here
|
||||||
doWeaponRepetitions :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
|
doWeaponRepetitions :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
|
||||||
doWeaponRepetitions itm cr = case itm ^? ldtValue . itUse . heldParams . weaponRepeat of
|
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
|
_ -> id
|
||||||
where
|
where
|
||||||
upitm =
|
upitm =
|
||||||
|
|||||||
+26
-14
@@ -72,8 +72,8 @@ itemToBreakLists itm itmf = case (itm ^. itType, itmf) of
|
|||||||
, []
|
, []
|
||||||
)
|
)
|
||||||
(_, WeaponTargetingSF) -> (getAmmoLinks itm ++ [(AugmentedHUDSF, AugmentedHUDLink)], [])
|
(_, WeaponTargetingSF) -> (getAmmoLinks itm ++ [(AugmentedHUDSF, AugmentedHUDLink)], [])
|
||||||
(ATTACH BULLETSYNTH, _)
|
(ATTACH BULLETSYNTH, _) ->
|
||||||
-> ([(AmmoMagSF ElectricalAmmo, AmmoInLink 0 ElectricalAmmo)],[])
|
([(AmmoMagSF ElectricalAmmo, AmmoInLink 0 ElectricalAmmo)], [])
|
||||||
_ -> ([], [])
|
_ -> ([], [])
|
||||||
|
|
||||||
getAmmoLinks :: Item -> [(ItemStructuralFunction, ComposeLinkType)]
|
getAmmoLinks :: Item -> [(ItemStructuralFunction, ComposeLinkType)]
|
||||||
@@ -186,7 +186,10 @@ invLDT =
|
|||||||
-- consider explicitly reseting the inventory ids (but this probably really
|
-- consider explicitly reseting the inventory ids (but this probably really
|
||||||
-- should be done upstream anyway in the actually creature inventory)
|
-- should be done upstream anyway in the actually creature inventory)
|
||||||
invRootMap :: IM.IntMap Item -> IM.IntMap (Maybe Int, DoubleTree Item)
|
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
|
-- this assumes the creature inventory is well formed, specifically the
|
||||||
-- location ids
|
-- location ids
|
||||||
@@ -208,7 +211,8 @@ invTrees = fmap (first _iatType) . invTrees'
|
|||||||
|
|
||||||
-- returns an intmap with trees for all items
|
-- returns an intmap with trees for all items
|
||||||
invTrees' :: IM.IntMap Item -> IM.IntMap (LabelDoubleTree ItemLink Item)
|
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
|
where
|
||||||
getindex i =
|
getindex i =
|
||||||
fromMaybe (error "in invTrees try to get non-inventory item tree") $
|
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
|
-- returns an intmap with trees for (only!) root items, indexed by inventory position
|
||||||
invRootTrees :: IM.IntMap Item -> IM.IntMap (LabelDoubleTree ItemLink ComposedItem)
|
invRootTrees :: IM.IntMap Item -> IM.IntMap (LabelDoubleTree ItemLink ComposedItem)
|
||||||
invRootTrees = IM.fromDistinctAscList . reverse . map (getid) . invLDT
|
invRootTrees = IM.fromDistinctAscList . reverse . map getid . invLDT
|
||||||
where
|
where
|
||||||
getid :: LabelDoubleTree ItemLink ComposedItem
|
getid ::
|
||||||
-> (Int, LabelDoubleTree ItemLink ComposedItem)
|
LabelDoubleTree ItemLink ComposedItem ->
|
||||||
|
(Int, LabelDoubleTree ItemLink ComposedItem)
|
||||||
getid t = (t ^?! ldtValue . _1 . itLocation . ilInvID, t)
|
getid t = (t ^?! ldtValue . _1 . itLocation . ilInvID, t)
|
||||||
|
|
||||||
-- returns an intmap with indents and locations for all items
|
-- 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
|
where
|
||||||
f t = cldtPropagateFold h h g 0 t id
|
f t = cldtPropagateFold h h g 0 t id
|
||||||
h x _ _ _ = x + 1
|
h x _ _ _ = x + 1
|
||||||
g :: Int -> LocationLDT ItemLink ComposedItem
|
g ::
|
||||||
-> (IM.IntMap (Int, LocationLDT ItemLink ComposedItem)
|
Int ->
|
||||||
-> IM.IntMap (Int, LocationLDT ItemLink ComposedItem))
|
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))
|
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)
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
module Dodge.SelectUse (selectUse) where
|
module Dodge.SelectUse (selectUse) where
|
||||||
|
|
||||||
|
import Control.Monad
|
||||||
|
import qualified SDL
|
||||||
import Control.Lens
|
import Control.Lens
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Dodge.Data.ComposedItem
|
import Dodge.Data.ComposedItem
|
||||||
@@ -9,6 +11,8 @@ import Dodge.Payload
|
|||||||
|
|
||||||
selectUse :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
|
selectUse :: LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
|
||||||
selectUse ittree _ w = fromMaybe w $ do
|
selectUse ittree _ w = fromMaybe w $ do
|
||||||
|
lbtime <- w ^? input . mouseButtons . ix SDL.ButtonLeft
|
||||||
|
guard $ lbtime == 0
|
||||||
itid <- ittree ^? ldtValue . itID
|
itid <- ittree ^? ldtValue . itID
|
||||||
pjid <- ittree ^? ldtValue . itUse . uaParams . apLinkedProjectile . _Just
|
pjid <- ittree ^? ldtValue . itUse . uaParams . apLinkedProjectile . _Just
|
||||||
thepj <- w ^? cWorld . lWorld . projectiles . ix pjid
|
thepj <- w ^? cWorld . lWorld . projectiles . ix pjid
|
||||||
|
|||||||
@@ -5,13 +5,12 @@ module Dodge.WorldEffect (
|
|||||||
lineOutputTerminal,
|
lineOutputTerminal,
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import Dodge.Item.Grammar
|
import Dodge.HeldUse
|
||||||
import Dodge.Data.ComposedItem
|
import Dodge.Data.ComposedItem
|
||||||
import Dodge.Data.DoubleTree
|
import Dodge.Data.DoubleTree
|
||||||
import Data.Foldable
|
import Data.Foldable
|
||||||
import qualified Data.Map.Strict as M
|
import qualified Data.Map.Strict as M
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import Dodge.Creature.Impulse.UseItem
|
|
||||||
import Dodge.Data.World
|
import Dodge.Data.World
|
||||||
import Dodge.Default
|
import Dodge.Default
|
||||||
import Dodge.Inventory.Lock
|
import Dodge.Inventory.Lock
|
||||||
@@ -35,13 +34,6 @@ doWdWd we = case we of
|
|||||||
TorqueCr x cid -> torqueCr x cid
|
TorqueCr x cid -> torqueCr x cid
|
||||||
SoundStart so p sid mi -> soundStart so p sid mi
|
SoundStart so p sid mi -> soundStart so p sid mi
|
||||||
WdWdNegateTrig trid -> cWorld . lWorld . triggers . ix trid %~ not
|
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
|
WdWdFromItCrixWdWd it crid f -> \w -> fromMaybe w $ do
|
||||||
cr <- w ^? cWorld . lWorld . creatures . ix crid
|
cr <- w ^? cWorld . lWorld . creatures . ix crid
|
||||||
return $ doItCrWdWd f it cr w
|
return $ doItCrWdWd f it cr w
|
||||||
@@ -51,8 +43,7 @@ doWdWd we = case we of
|
|||||||
|
|
||||||
doItCrWdWd :: ItCrWdWd -> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
|
doItCrWdWd :: ItCrWdWd -> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
|
||||||
doItCrWdWd icww = case icww of
|
doItCrWdWd icww = case icww of
|
||||||
ItCrWdId -> \_ _ -> id
|
ItCrWdItemHeldEffect -> heldEffect
|
||||||
ItCrWdItemEffect -> flip itemUseEffect
|
|
||||||
|
|
||||||
accessTerminal :: Maybe Int -> World -> World
|
accessTerminal :: Maybe Int -> World -> World
|
||||||
accessTerminal mtmid w = fromMaybe w $ do
|
accessTerminal mtmid w = fromMaybe w $ do
|
||||||
|
|||||||
Reference in New Issue
Block a user