Commit before changing ItemUse into single product type

This commit is contained in:
2024-12-20 14:49:18 +00:00
parent e1989eaa1e
commit 3a72bd366f
8 changed files with 32 additions and 27 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -47,7 +47,7 @@ followImpulse cr w imp = case imp of
TurnToward p a -> crup $ creatureTurnToward p a cr TurnToward p a -> crup $ creatureTurnToward p a cr
TurnTo p -> crup $ creatureTurnTo p cr TurnTo p -> crup $ creatureTurnTo p cr
ChangePosture post -> crup $ cr & crStance . posture .~ post ChangePosture post -> crup $ cr & crStance . posture .~ post
UseItem -> (useRootItem $ _crID cr, cr) UseItem -> (useSelectedItem $ _crID cr, cr)
SwitchToItem i -> crup $ cr & crManipulation . manObject .~ SelectedItem i i mempty SwitchToItem i -> crup $ cr & crManipulation . manObject .~ SelectedItem i i mempty
Melee cid' -> Melee cid' ->
( hitCr cid' ( hitCr cid'
+5 -3
View File
@@ -1,5 +1,5 @@
module Dodge.Creature.Impulse.UseItem ( module Dodge.Creature.Impulse.UseItem (
useRootItem, useSelectedItem,
) where ) where
import Control.Lens import Control.Lens
@@ -16,11 +16,13 @@ import Dodge.Item.Grammar
import Dodge.Item.Location import Dodge.Item.Location
import qualified IntMapHelp as IM import qualified IntMapHelp as IM
useRootItem :: Int -> World -> World useSelectedItem :: Int -> World -> World
useRootItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w $ do useSelectedItem crid w = (worldEventFlags . at InventoryChange ?~ ()) . fromMaybe w $ do
cr <- w ^? cWorld . lWorld . creatures . ix crid cr <- w ^? cWorld . lWorld . creatures . ix crid
itRef <- cr ^? crManipulation . manObject . imRootSelectedItem itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
invid <- cr ^? crManipulation . manObject . imSelectedItem
itmtree <- invRootTrees (_crInv cr) ^? ix itRef itmtree <- invRootTrees (_crInv cr) ^? ix itRef
itmloc <- allInvLocs (_crInv cr) ^? ix invid
let itm = itmtree ^. ldtValue . _1 let itm = itmtree ^. ldtValue . _1
case itmtree ^. ldtValue . _2 of case itmtree ^. ldtValue . _2 of
HeldPlatformSF -> HeldPlatformSF ->
+8 -5
View File
@@ -173,18 +173,21 @@ mouseActionsCr pkeys
pressedMBEffectsTopInventory :: M.Map SDL.MouseButton Int -> World -> World pressedMBEffectsTopInventory :: M.Map SDL.MouseButton Int -> World -> World
pressedMBEffectsTopInventory pkeys w pressedMBEffectsTopInventory pkeys w
| isDown SDL.ButtonLeft && isDown SDL.ButtonRight && inTopInv = youhammerdown $ useRootItem 0 w | Just ltime <- pkeys ^? ix SDL.ButtonLeft
-- | isDown SDL.ButtonLeft && inTopInv = youhammerdown $ useItemLeftClick (you w) w , Just rtime <- pkeys ^? ix SDL.ButtonRight
| isDown SDL.ButtonMiddle = w & wCam . camRot -~ rotation , ltime <= rtime && inTopInv
= youhammerdown $ useSelectedItem 0 w
| Just _ <- pkeys ^? ix SDL.ButtonLeft
, Just _ <- pkeys ^? ix SDL.ButtonRight
= w & wCam . camRot -~ rotation
| otherwise = w | otherwise = w
where where
youhammerdown = set (cWorld . lWorld . creatures . ix 0 . crHammerPosition) HammerDown youhammerdown = set (cWorld . lWorld . creatures . ix 0 . crHammerPosition) HammerDown
inTopInv = case w ^. hud . hudElement of inTopInv = case w ^. hud . hudElement of
DisplayInventory{_subInventory = NoSubInventory{}} -> True DisplayInventory{_subInventory = NoSubInventory{}} -> True
_ -> False _ -> False
isDown but = but `M.member` pkeys
rotation = rotation =
maybe maybe
0 0
(angleBetween $ w ^. input . mousePos) (angleBetween $ w ^. input . mousePos)
(w ^. input . heldPos . at SDL.ButtonMiddle) (w ^. input . heldPos . at SDL.ButtonRight)
+8 -7
View File
@@ -41,14 +41,8 @@ data ItemUse
, _heldParams :: HeldParams , _heldParams :: HeldParams
, _heldTriggerType :: TriggerType , _heldTriggerType :: TriggerType
, _useCondition :: UseCondition , _useCondition :: UseCondition
, _useFocus :: UseFocus
} }
-- | UseHotkey
-- { _leftUse :: Luse
-- , _leftDelay :: UseDelay
-- , _leftHammer :: HammerPosition
-- , _uequipEffect :: EquipEffect
-- , _leftConsumption :: LeftConsumption
-- }
| UseConsume { _cUse :: Cuse } | UseConsume { _cUse :: Cuse }
| UseEquip { _uequipEffect :: EquipEffect } | UseEquip { _uequipEffect :: EquipEffect }
| UseAttach {_uaParams :: AttachParams} | UseAttach {_uaParams :: AttachParams}
@@ -57,6 +51,11 @@ data ItemUse
| UseBulletMod { _ubMod :: BulletMod } | UseBulletMod { _ubMod :: BulletMod }
deriving (Eq, Show, Read) deriving (Eq, Show, Read)
data UseFocus
= UseFromRoot
| UseFromLocation
deriving (Eq, Show, Read)
data UseCondition data UseCondition
= MustBeHeld = MustBeHeld
| UseableAnytime | UseableAnytime
@@ -204,6 +203,8 @@ makeLenses ''AmmoParams
makeLenses ''MuzzleEffect makeLenses ''MuzzleEffect
makeLenses ''AmmoPerShot makeLenses ''AmmoPerShot
makeLenses ''UseCondition makeLenses ''UseCondition
makeLenses ''UseFocus
deriveJSON defaultOptions ''UseFocus
deriveJSON defaultOptions ''UseCondition deriveJSON defaultOptions ''UseCondition
deriveJSON defaultOptions ''MuzzleEffect deriveJSON defaultOptions ''MuzzleEffect
deriveJSON defaultOptions ''FlareType deriveJSON defaultOptions ''FlareType
+1
View File
@@ -43,4 +43,5 @@ defaultHeldUse = UseHeld
} }
, _heldTriggerType = HammerTrigger , _heldTriggerType = HammerTrigger
, _useCondition = MustBeHeld , _useCondition = MustBeHeld
, _useFocus = UseFromRoot
} }
+4 -9
View File
@@ -28,7 +28,8 @@ tinMag :: Item
tinMag = tinMag =
defaultHeldItem & itType .~ AMMOMAG TINMAG defaultHeldItem & itType .~ AMMOMAG TINMAG
& itUse .~ UseNothing & itUse .~ UseNothing
& itConsumables .~ AmmoMag & itConsumables
.~ AmmoMag
{ _magParams = BulletParams defaultBullet { _magParams = BulletParams defaultBullet
, _magType = BulletAmmo , _magType = BulletAmmo
, _magLoadStatus = , _magLoadStatus =
@@ -38,13 +39,6 @@ tinMag =
} }
} }
--revolveMag :: Item
--revolveMag =
-- tinMag
-- & itType .~ AMMOMAG REVOLVEMAG
-- & itUse . amagLoadStatus . iaMax .~ 6
-- & itUse . amagLoadStatus . iaLoaded .~ 6
drumMag :: Item drumMag :: Item
drumMag = drumMag =
tinMag & itType . ibtAmmoMag .~ DRUMMAG tinMag & itType . ibtAmmoMag .~ DRUMMAG
@@ -125,5 +119,6 @@ chemFuelPouch =
} }
bulletSynthesizer :: Item bulletSynthesizer :: Item
bulletSynthesizer = makeAttach BULLETSYNTH bulletSynthesizer =
makeAttach BULLETSYNTH
& itUse .~ UseAttach (APInt 0) & itUse .~ UseAttach (APInt 0)
+3
View File
@@ -90,6 +90,9 @@ itemToFunction itm = case itm ^. itType of
HELD{} -> case itm ^? itUse . useCondition of HELD{} -> case itm ^? itUse . useCondition of
Just MustBeHeld -> HeldPlatformSF Just MustBeHeld -> HeldPlatformSF
_ -> GadgetPlatformSF _ -> GadgetPlatformSF
_ | Just amtype <- itm ^? itConsumables . magType
, Just _ <- itm ^? itLocation . ilEquipSite . _Just
-> AmmoMagSF amtype
AMMOMAG{} -> maybe UncomposableIsolateSF AmmoMagSF $ itm ^? itConsumables . magType AMMOMAG{} -> maybe UncomposableIsolateSF AmmoMagSF $ itm ^? itConsumables . magType
ATTACH REMOTESCREEN -> RemoteScreenSF ATTACH REMOTESCREEN -> RemoteScreenSF
ATTACH BULLETSYNTH -> AmmoModifierSF BulletAmmo ATTACH BULLETSYNTH -> AmmoModifierSF BulletAmmo