Move UseCondition out of record

This commit is contained in:
2025-06-05 19:41:33 +01:00
parent 16f5c05f19
commit 816ab4222f
15 changed files with 325 additions and 382 deletions
-16
View File
@@ -1,16 +0,0 @@
module Dodge.Cuse where
import Dodge.Inventory
import Control.Lens
import Dodge.Data.World
import Data.Maybe
useC :: Cuse -> Item -> Creature -> World -> World
useC cu itm cr = fromMaybe id $ do
i <- itm ^? itLocation . ilInvID
return $ rmInvItem (_crID cr) i . useC' cu itm cr
useC' :: Cuse -> Item -> Creature -> World -> World
useC' cu = case cu of
CDoNothing -> const $ const id
CHeal x -> const $ \cr -> cWorld . lWorld . creatures . ix (_crID cr) . crHP +~ x
+1 -1
View File
@@ -40,7 +40,7 @@ data Consumables
data Item = Item data Item = Item
{ _itUse :: ItemUse { _itUse :: ItemUse
, _itUseCondition :: UseCondition -- , _itUseCondition :: UseCondition
, _itConsumables :: Consumables , _itConsumables :: Consumables
, _itType :: ItemType , _itType :: ItemType
, _itID :: NewInt ItmInt , _itID :: NewInt ItmInt
-28
View File
@@ -1,28 +0,0 @@
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-}
module Dodge.Data.Item.HeldUse where
--import Dodge.Data.Item.Use.Consumption.Ammo
import Dodge.Data.Magnet
import Data.Aeson
import Data.Aeson.TH
import Control.Lens
data Cuse
= CDoNothing
| CHeal Int
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data Euse
= EDoNothing
| EMagShield MagnetBuBu
| EWristShield
| EHeadLamp
deriving (Eq, Ord, Show, Read) --Generic, Flat)
makeLenses ''Euse
deriveJSON defaultOptions ''Cuse
deriveJSON defaultOptions ''Euse
+3 -66
View File
@@ -5,7 +5,6 @@
module Dodge.Data.Item.Use ( module Dodge.Data.Item.Use (
module Dodge.Data.Item.Use, module Dodge.Data.Item.Use,
module Dodge.Data.Item.HeldUse,
module Dodge.Data.Item.Use.Consumption, module Dodge.Data.Item.Use.Consumption,
module Dodge.Data.Item.Targeting, module Dodge.Data.Item.Targeting,
module Dodge.Data.GenFloat, module Dodge.Data.GenFloat,
@@ -19,8 +18,6 @@ import Data.Aeson.TH
import qualified Data.Set as S import qualified Data.Set as S
import Dodge.Data.GenFloat import Dodge.Data.GenFloat
import Dodge.Data.Item.BulletMod import Dodge.Data.Item.BulletMod
--import Dodge.Data.Item.HeldDelay
import Dodge.Data.Item.HeldUse
import Dodge.Data.Item.Scope import Dodge.Data.Item.Scope
import Dodge.Data.Item.Targeting import Dodge.Data.Item.Targeting
import Dodge.Data.Item.Use.Consumption import Dodge.Data.Item.Use.Consumption
@@ -47,11 +44,6 @@ data UseFocus
| UseFromLocation | UseFromLocation
deriving (Eq, Show, Read) deriving (Eq, Show, Read)
data UseCondition
= UseableWhenAimed
| UseableAnytime
deriving (Eq, Show, Read)
data AttachParams data AttachParams
= APProjectiles {_apProjectiles :: [Int]} = APProjectiles {_apProjectiles :: [Int]}
| APInt {_apInt :: Int} | APInt {_apInt :: Int}
@@ -65,68 +57,13 @@ data AmmoParams
| NoAmmoParams | NoAmmoParams
deriving (Eq, Show, Read) --Generic, Flat) deriving (Eq, Show, Read) --Generic, Flat)
data FlareType
= NoFlare
| BasicFlare
| NoLightFlare
| MiniGunFlare
| HeavySmokeFlare
| LasGunFlare
| TeslaGunFlare
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data MuzzleEffect
= MuzzleShootBullet
| MuzzleLaser
| MuzzleTesla
| MuzzleTractor
| MuzzleRLauncher
| MuzzleGLauncher
| MuzzleNozzle
{ _nzPressure :: GenFloat
, _nzMaxWalkAngle :: Float
, _nzWalkSpeed :: Float
}
| MuzzleShatter
| MuzzleDetector
| MuzzleBlink
| MuzzleUnsafeBlink
| MuzzleRewind
| MuzzleStopper
| MuzzleScroller
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data AmmoPerShot
= UseExactly {_useExactly :: Int}
| UseUpTo {_useUpTo :: Int}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data Muzzle = Muzzle
{ _mzPos :: V2 Float
, _mzRot :: Float
, _mzInaccuracy :: Float
, _mzAmmoSlot :: Int
, _mzFlareType :: FlareType
, _mzEffect :: MuzzleEffect
, _mzAmmoPerShot :: AmmoPerShot
, _mzFrame :: Int
}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
makeLenses ''ItemUse makeLenses ''ItemUse
makeLenses ''Muzzle
makeLenses ''AttachParams makeLenses ''AttachParams
makeLenses ''AmmoParams makeLenses ''AmmoParams
makeLenses ''MuzzleEffect --makeLenses ''UseCondition
makeLenses ''AmmoPerShot
makeLenses ''UseCondition
makeLenses ''UseFocus makeLenses ''UseFocus
deriveJSON defaultOptions ''UseFocus --deriveJSON defaultOptions ''UseFocus
deriveJSON defaultOptions ''UseCondition --deriveJSON defaultOptions ''UseCondition
deriveJSON defaultOptions ''MuzzleEffect
deriveJSON defaultOptions ''FlareType
deriveJSON defaultOptions ''AmmoParams deriveJSON defaultOptions ''AmmoParams
deriveJSON defaultOptions ''AmmoPerShot
deriveJSON defaultOptions ''Muzzle
deriveJSON defaultOptions ''AttachParams deriveJSON defaultOptions ''AttachParams
deriveJSON defaultOptions ''ItemUse deriveJSON defaultOptions ''ItemUse
+59
View File
@@ -0,0 +1,59 @@
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TemplateHaskell #-}
module Dodge.Data.Muzzle where
import Dodge.Data.GenFloat
import Linear
import Control.Lens
data Muzzle = Muzzle
{ _mzPos :: V2 Float
, _mzRot :: Float
, _mzInaccuracy :: Float
, _mzAmmoSlot :: Int
, _mzFlareType :: FlareType
, _mzEffect :: MuzzleEffect
, _mzAmmoPerShot :: AmmoPerShot
, _mzFrame :: Int
}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data FlareType
= NoFlare
| BasicFlare
| NoLightFlare
| MiniGunFlare
| HeavySmokeFlare
| LasGunFlare
| TeslaGunFlare
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data MuzzleEffect
= MuzzleShootBullet
| MuzzleLaser
| MuzzleTesla
| MuzzleTractor
| MuzzleRLauncher
| MuzzleGLauncher
| MuzzleNozzle
{ _nzPressure :: GenFloat
, _nzMaxWalkAngle :: Float
, _nzWalkSpeed :: Float
}
| MuzzleShatter
| MuzzleDetector
| MuzzleBlink
| MuzzleUnsafeBlink
| MuzzleRewind
| MuzzleStopper
| MuzzleScroller
deriving (Eq, Ord, Show, Read) --Generic, Flat)
data AmmoPerShot
= UseExactly {_useExactly :: Int}
| UseUpTo {_useUpTo :: Int}
deriving (Eq, Ord, Show, Read) --Generic, Flat)
makeLenses ''Muzzle
makeLenses ''MuzzleEffect
makeLenses ''AmmoPerShot
+12
View File
@@ -0,0 +1,12 @@
{-# LANGUAGE StrictData #-}
module Dodge.Data.UseCondition
where
data UseCondition
= UseableWhenAimed
| UseableWhenHeld
| UseableAnytime
| NeverUsable
deriving (Eq, Show, Read)
+1 -3
View File
@@ -1,12 +1,10 @@
module Dodge.Default.Item ( module Dodge.Default.Item (
defaultHeldItem, defaultHeldItem,
defaultCraftItem, defaultCraftItem,
module Dodge.Default.Item.Use,
) where ) where
import Control.Lens import Control.Lens
import Dodge.Data.Item import Dodge.Data.Item
import Dodge.Default.Item.Use
defaultHeldItem :: Item defaultHeldItem :: Item
defaultHeldItem = defaultHeldItem =
@@ -19,7 +17,7 @@ defaultHeldItem =
, _itLocation = InVoid , _itLocation = InVoid
, _itUse = UseHeld , _itUse = UseHeld
, _itParams = NoParams , _itParams = NoParams
, _itUseCondition = UseableWhenAimed -- , _itUseCondition = UseableWhenAimed
, _itScroll = NoItemScroll , _itScroll = NoItemScroll
, _itTimeLastUsed = 0 , _itTimeLastUsed = 0
} }
-14
View File
@@ -1,14 +0,0 @@
module Dodge.Default.Item.Use (
module Dodge.Default.Item.Use,
) where
import Dodge.Data.Item.Use
defaultEquipUse :: ItemUse
defaultEquipUse = UseEquip
--defaultHeldUse :: ItemUse
--defaultHeldUse =
-- UseHeld
-- { _heldFrame = 0
-- }
+8 -14
View File
@@ -3,11 +3,11 @@ module Dodge.Equipment (
effectOnEquip, effectOnEquip,
) where ) where
import Dodge.Data.Equipment.Misc
import Control.Lens import Control.Lens
import Data.Maybe import Data.Maybe
import Dodge.Creature.HandPos import Dodge.Creature.HandPos
import Dodge.Creature.Test import Dodge.Creature.Test
import Dodge.Data.Equipment.Misc
import Dodge.Data.World import Dodge.Data.World
import Dodge.Item.Location import Dodge.Item.Location
import Dodge.Wall.Delete import Dodge.Wall.Delete
@@ -18,34 +18,29 @@ import qualified IntMapHelp as IM
effectOnRemove :: Item -> Creature -> World -> World effectOnRemove :: Item -> Creature -> World -> World
effectOnRemove itm = case itm ^. itType of effectOnRemove itm = case itm ^. itType of
EQUIP WRISTARMOUR -> onRemoveWristShield' itm EQUIP WRISTARMOUR -> onRemoveWristShield itm
_ -> \_ -> id _ -> \_ -> id
onRemoveWristShield' :: Item -> Creature -> World -> World onRemoveWristShield :: Item -> Creature -> World -> World
onRemoveWristShield' itm _ = onRemoveWristShield itm _ =
--(pointerToItem itm . itUse . uequipEffect . eeParams .~ NoEquipParams) . mremovewall
(pointerToItem itm . itParams .~ NoParams) . mremovewall (pointerToItem itm . itParams .~ NoParams) . mremovewall
where where
mremovewall = fromMaybe id $ do mremovewall = fromMaybe id $ do
--i <- itm ^? itUse . uequipEffect . eeParams . eparamID
i <- itm ^? itParams . itParamID i <- itm ^? itParams . itParamID
return $ deleteWallID i return $ deleteWallID i
effectOnEquip :: Item -> Creature -> World -> World effectOnEquip :: Item -> Creature -> World -> World
effectOnEquip itm = case itm ^. itType of effectOnEquip itm = case itm ^. itType of
EQUIP WRISTARMOUR -> onEquipWristShield' itm EQUIP WRISTARMOUR -> onEquipWristShield itm
_ -> \_ -> id _ -> \_ -> id
onEquipWristShield' :: Item -> Creature -> World -> World onEquipWristShield :: Item -> Creature -> World -> World
onEquipWristShield' itm cr w = onEquipWristShield itm cr w =
w w
-- & pointerToItem itm . itUse . uequipEffect . eeParams .~ EquipID i
& pointerToItem itm . itParams .~ ItemParamID{_itParamID = i} & pointerToItem itm . itParams .~ ItemParamID{_itParamID = i}
& cWorld . lWorld . walls . at i ?~ forceField{_wlID = i} & cWorld . lWorld . walls . at i ?~ forceField{_wlID = i}
& setWristShieldPos & setWristShieldPos
( itm ( itm & itParams .~ ItemParamID{_itParamID = i}
-- & itUse . uequipEffect . eeParams .~ EquipID i
& itParams .~ ItemParamID{_itParamID = i}
) )
cr cr
where where
@@ -54,7 +49,6 @@ onEquipWristShield' itm cr w =
setWristShieldPos :: Item -> Creature -> World -> World setWristShieldPos :: Item -> Creature -> World -> World
setWristShieldPos itm cr w = w & moveWallIDUnsafe i wlline setWristShieldPos itm cr w = w & moveWallIDUnsafe i wlline
where where
--i = _eparamID $ _eeParams $ _uequipEffect $ _itUse itm
i = _itParamID $ _itParams itm i = _itParamID $ _itParams itm
wlline = (f (V3 (-10) 7 0), f (V3 10 7 0)) wlline = (f (V3 (-10) 7 0), f (V3 10 7 0))
invid = _ilInvID (_itLocation itm) invid = _ilInvID (_itLocation itm)
+1
View File
@@ -10,6 +10,7 @@ module Dodge.HeldUse (
heldEffectMuzzles, heldEffectMuzzles,
) where ) where
import Dodge.Data.Muzzle
import Dodge.Data.UseDelay import Dodge.Data.UseDelay
import Dodge.Item.UseDelay import Dodge.Item.UseDelay
import Dodge.Base import Dodge.Base
+4 -2
View File
@@ -7,6 +7,8 @@ module Dodge.Item.Grammar (
allInvLocs, allInvLocs,
) where ) where
import Dodge.ItemUseCondition
import Dodge.Data.UseCondition
import Dodge.Item.MagAmmoType import Dodge.Item.MagAmmoType
import Dodge.Data.AmmoType import Dodge.Data.AmmoType
import Dodge.Item.AmmoSlots import Dodge.Item.AmmoSlots
@@ -150,8 +152,8 @@ itemToFunction itm = case itm ^. itType of
ITEMSCAN -> ToggleSF ITEMSCAN -> ToggleSF
INTROSCAN {} -> IntroScanSF INTROSCAN {} -> IntroScanSF
HELD LASER -> WeaponTargetingSF HELD LASER -> WeaponTargetingSF
HELD{} -> case itm ^? itUseCondition of HELD{} -> case itUseCondition itm of
Just UseableWhenAimed -> HeldPlatformSF UseableWhenAimed -> HeldPlatformSF
--Just MustBeHeld -> UnloadedWeaponSF --Just MustBeHeld -> UnloadedWeaponSF
_ -> GadgetPlatformSF _ -> GadgetPlatformSF
_ _
+3 -20
View File
@@ -33,30 +33,13 @@ torch =
-- | Sends out pulses that display walls. -- | Sends out pulses that display walls.
detector :: Detector -> Item detector :: Detector -> Item
detector dt = detector dt = defaultHeldItem & itType .~ DETECTOR dt
defaultHeldItem
& itUseCondition .~ UseableAnytime
-- & itUse . heldDelay . rateMax .~ 20
-- & itAmmoSlots .~ singleAmmo ElectricalAmmo
& itType .~ DETECTOR dt
-- & itUse . heldMuzzles . ix 0 . mzEffect .~ MuzzleDetector
-- & itUse . heldMuzzles . ix 0 . mzAmmoPerShot .~ UseExactly 100
blinker :: Item blinker :: Item
blinker = blinker = defaultHeldItem & itType .~ HELD BLINKER
defaultHeldItem
& itUseCondition .~ UseableAnytime
-- & itUse . heldDelay . rateMax .~ 20
-- & itAmmoSlots .~ singleAmmo ElectricalAmmo
-- & itUse . heldMuzzles . ix 0 . mzEffect .~ MuzzleBlink
-- & itUse . heldMuzzles . ix 0 . mzAmmoPerShot .~ UseExactly 10000000
& itType .~ HELD BLINKER
unsafeBlinker :: Item unsafeBlinker :: Item
unsafeBlinker = unsafeBlinker = blinker & itType .~ HELD BLINKERUNSAFE
blinker
-- & itUse . heldMuzzles . ix 0 . mzEffect .~ MuzzleUnsafeBlink
& itType .~ HELD BLINKERUNSAFE
rewinder :: Item rewinder :: Item
rewinder = rewinder =
+11
View File
@@ -0,0 +1,11 @@
module Dodge.ItemUseCondition (itUseCondition) where
import Dodge.Data.Item
import Dodge.Data.UseCondition
itUseCondition :: Item -> UseCondition
itUseCondition itm = case _itType itm of
DETECTOR _ -> UseableAnytime
HELD BLINKER -> UseableAnytime
HELD UNSAFEBLINKER -> UseableAnytime
_ -> UseableWhenAimed
+1
View File
@@ -6,6 +6,7 @@ module Dodge.Projectile.Create (
--import Dodge.Data.ComposedItem --import Dodge.Data.ComposedItem
--import Dodge.Data.DoubleTree --import Dodge.Data.DoubleTree
import Dodge.Data.Muzzle
import Data.Maybe import Data.Maybe
import Dodge.Data.World import Dodge.Data.World
import Dodge.Item.Location import Dodge.Item.Location
+221 -218
View File
File diff suppressed because it is too large Load Diff