Add clicker items that use other items with a one frame delay

This commit is contained in:
2025-01-03 14:50:09 +00:00
parent 386d6f47b0
commit 3b452b9002
10 changed files with 41 additions and 0 deletions
+3
View File
@@ -9,6 +9,8 @@ import Control.Lens
import qualified Data.Map.Strict as M
import Geometry.Data
import SDL (MouseButton, Scancode)
import Data.Aeson
import Data.Aeson.TH
data PressType
= InitialPress
@@ -69,3 +71,4 @@ data TermSignal
makeLenses ''Input
makeLenses ''MouseContext
deriveJSON defaultOptions ''PressType
+1
View File
@@ -24,6 +24,7 @@ data ItemType
| ITEMSCAN
| MAPPER
| DROPPER InventoryPathing
| CLICKER InventoryPathing
| INTROSCAN {_ibtIntroScanType :: IntroScanType}
| DETECTOR {_ibtDetector :: Detector}
| ARHUD
+2
View File
@@ -5,6 +5,7 @@
module Dodge.Data.WorldEffect where
import Dodge.Data.Input
import Dodge.Data.LightSource
import Dodge.Data.ComposedItem
import Dodge.Data.DoubleTree
@@ -32,6 +33,7 @@ data WdWd
| WdWdNegateTrig Int
| WdWdFromItCrixWdWd (LabelDoubleTree ComposeLinkType Item) Int ItCrWdWd
| MakeTempLight LSParam Int
| UseInvItem Int PressType
--deriving (Eq, Show, Read) --, Generic)
--h--deriving (Eq, Show, Read) --Generic, Flat)
+22
View File
@@ -48,6 +48,9 @@ gadgetEffect pt loc
| DROPPER x <- loc ^. locLDT . ldtValue . _1 . itType
, Just i <- loc ^? locLDT . ldtValue . _1 . itUse . uInt
, pt == InitialPress = dropInventoryPath i x loc
| CLICKER x <- loc ^. locLDT . ldtValue . _1 . itType
, Just i <- loc ^? locLDT . ldtValue . _1 . itUse . uInt
= useInventoryPath pt i x loc
| otherwise = const id
heldEffect ::
@@ -793,6 +796,25 @@ dropInventoryPath i ip loc cr w = case ip of
guard $ (i + j) `IM.member` (cr ^. crInv)
return $ dropItem cr (i + j) w
useInventoryPath :: PressType ->
Int -> InventoryPathing -> LocationLDT ItemLink ComposedItem
-> Creature
-> World -> World
useInventoryPath pt i ip loc cr w = case ip of
ABSOLUTE -> fromMaybe w $ do
guard $ i `IM.member` (cr ^. crInv)
return $ w & cWorld . lWorld . delayedEvents .:~ (1,UseInvItem i pt)
RELCURS -> fromMaybe w $ do
j <- cr ^? crManipulation . manObject . imSelectedItem
guard $ (i + j) `IM.member` (cr ^. crInv)
return $ w
& cWorld . lWorld . delayedEvents .:~ (1,UseInvItem (i+j) pt)
RELITEM -> fromMaybe w $ do
j <- loc ^? locLDT . ldtValue . _1 . itLocation . ilInvID
guard $ (i + j) `IM.member` (cr ^. crInv)
return $ w
& cWorld . lWorld . delayedEvents .:~ (1,UseInvItem (i+j) pt)
--useRewindGun _ _ w = case w ^. cwTime . rewindWorlds of
-- [w'] -> w & cwTime . maybeWorld .~ Just' w'
-- (w' : ws) -> w
+1
View File
@@ -31,6 +31,7 @@ itemFromBase = \case
DETECTOR d -> detector d
ARHUD -> arHUD
DROPPER x -> dropper x
CLICKER x -> clicker x
itemFromAmmoMag :: AmmoMagType -> Item
itemFromAmmoMag at = case at of
+1
View File
@@ -72,6 +72,7 @@ itemBaseName = \case
DETECTOR t -> show t
ARHUD -> "AR-HUD"
DROPPER x -> "DROPPER-" ++ showInventoryPathing x
CLICKER x -> "CLICKER-" ++ showInventoryPathing x
showInventoryPathing :: InventoryPathing -> String
showInventoryPathing = \case
+1
View File
@@ -47,6 +47,7 @@ itemSPic it = case it ^. itType of
INTROSCAN {} -> defSPic
DETECTOR dt -> noPic (colorSH (detectorColor dt) $ upperPrismPolySU 3 $ rectWH 2 2)
DROPPER{} -> defSPic
CLICKER{} -> defSPic
craftItemSPic :: CraftType -> Shape
craftItemSPic = \case
+1
View File
@@ -167,6 +167,7 @@ itemToFunction itm = case itm ^. itType of
EQUIP{} -> EquipmentPlatformSF
ATTACH SHELLPAYLOAD{} -> AmmoPayloadSF LauncherAmmo
DROPPER{} -> GadgetPlatformSF
CLICKER{} -> GadgetPlatformSF
_ -> NoSF
structureToPotentialFunction ::
+7
View File
@@ -18,6 +18,7 @@ module Dodge.Item.Scope (
introScan,
mapper,
dropper,
clicker,
) where
import Dodge.Item.Attach
@@ -74,6 +75,12 @@ dropper x =
& itType .~ DROPPER x
& itUse .~ UseInt 0
clicker :: InventoryPathing -> Item
clicker x =
defaultHeldItem
& itType .~ CLICKER x
& itUse .~ UseInt 0
bulletModule :: BulletMod -> Item
bulletModule bm =
defaultHeldItem
+2
View File
@@ -5,6 +5,7 @@ module Dodge.WorldEffect (
lineOutputTerminal,
) where
import Dodge.Creature.Impulse.UseItem
import Dodge.BlBl
import Dodge.Data.Input
import Dodge.HeldUse
@@ -42,6 +43,7 @@ doWdWd we = case we of
MakeTempLight _ 0 -> id
MakeTempLight x t -> (cWorld . lWorld . lights .:~ x)
. (cWorld . lWorld . worldEvents .:~ MakeTempLight x (t-1))
UseInvItem invid pt -> \w -> fromMaybe w (useItem invid pt w)
doItCrWdWd :: ItCrWdWd -> LabelDoubleTree ComposeLinkType Item -> Creature -> World -> World
doItCrWdWd icww = case icww of