From 8a7d06783d5dec71cef79c71a817943ef1faa24d Mon Sep 17 00:00:00 2001 From: justin Date: Tue, 22 Feb 2022 21:49:10 +0000 Subject: [PATCH] Move targeting to dedicated datatype within item --- src/Dodge/Combine/Combinations.hs | 8 ++-- src/Dodge/Creature/Picture.hs | 2 +- src/Dodge/Data.hs | 3 +- src/Dodge/Default.hs | 2 - src/Dodge/Default/Weapon.hs | 2 - src/Dodge/Item/Weapon/Bezier.hs | 3 +- src/Dodge/Item/Weapon/BulletGun/Stick.hs | 2 - src/Dodge/Item/Weapon/ExtraEffect.hs | 49 ++++++++++++++++++------ src/Dodge/Item/Weapon/Targeting.hs | 6 +-- 9 files changed, 48 insertions(+), 29 deletions(-) diff --git a/src/Dodge/Combine/Combinations.hs b/src/Dodge/Combine/Combinations.hs index 068f89175..82f6b3b1a 100644 --- a/src/Dodge/Combine/Combinations.hs +++ b/src/Dodge/Combine/Combinations.hs @@ -119,7 +119,9 @@ moduleCombinations = ) ] where - makeDirectedTele it = it & itEffect .~ rbSetTarget + makeDirectedTele it = it + -- & itEffect .~ rbSetTarget + & itTargeting' .~ targetRBPress & itUse . useMods .:~ withPosDirWallCheck directedTelPos -- for the camera: the simplest option is to remove all zoom/offset & itUse . useAim . aimZoom . itZoomFac .~ 1 @@ -128,9 +130,7 @@ moduleCombinations = -- position directedTelPos it cr w = (p,a) where - p = fromMaybe (_crPos cr) $ do - (g,_) <- _itTargeting it - g w + p = fromMaybe (_crPos cr) $ it ^? itTargeting' . tgPos . _Just a = argV (mouseWorldPos w -.- p) f ameff = itConsumption . aoType . amBulEff .~ ameff amod cts str func = (cts,ItemModule [str] 1 func) diff --git a/src/Dodge/Creature/Picture.hs b/src/Dodge/Creature/Picture.hs index 7f3b92cd8..fb6a3250b 100644 --- a/src/Dodge/Creature/Picture.hs +++ b/src/Dodge/Creature/Picture.hs @@ -42,7 +42,7 @@ basicCrPict col cr cfig w = ) where targetingPic = IM.elems $ IM.mapMaybeWithKey f $ _crInv cr - f invid it = fmap ((\g -> g invid it cr w) . snd) (it ^? itTargeting . _Just) + f invid it = fmap (\g -> g invid it cr w) (it ^? itTargeting' . tgDraw) drawCrEquipment :: Creature -> SPic drawCrEquipment cr = uncurryV translateSPf (_crPos cr) (rotateSP (_crDir cr) $ drawEquipment cr) diff --git a/src/Dodge/Data.hs b/src/Dodge/Data.hs index 03d7b9458..a83dd2427 100644 --- a/src/Dodge/Data.hs +++ b/src/Dodge/Data.hs @@ -369,7 +369,6 @@ data Item = Item , _itInvSize :: Float , _itInvDisplay :: Item -> [String] , _itInvColor :: Color - , _itTargeting :: Maybe (World -> Maybe Point2, Int -> Item -> Creature -> World -> Picture) , _itTargeting' :: Targeting , _itDimension :: ItemDimension , _itCurseStatus :: CurseStatus @@ -383,7 +382,7 @@ data Targeting | TargetingOnHeld { _tgPos :: Maybe Point2 , _tgHeldUpdate :: Item -> Creature -> World -> Targeting -> Targeting - , _tgDraw :: Item -> Creature -> World -> Picture + , _tgDraw :: Int -> Item -> Creature -> World -> Picture } data ModuleSlot = ModBullet diff --git a/src/Dodge/Default.hs b/src/Dodge/Default.hs index 090f01f9b..8a0487fa4 100644 --- a/src/Dodge/Default.hs +++ b/src/Dodge/Default.hs @@ -154,7 +154,6 @@ defaultEquipment = Item , _itAttachment = NoItAttachment , _itParams = NoParams , _itTweaks = NoTweaks - , _itTargeting = Nothing , _itModules = M.empty , _itScope = NoScope , _itTargeting' = NoTargeting @@ -177,7 +176,6 @@ defaultConsumable = Item , _itScroll = \_ _ -> id , _itAttachment = NoItAttachment , _itType = NoCombineType - , _itTargeting = Nothing , _itParams = NoParams , _itDimension = defItDimCol blue , _itTweaks = NoTweaks diff --git a/src/Dodge/Default/Weapon.hs b/src/Dodge/Default/Weapon.hs index 3151f8854..c178c4db3 100644 --- a/src/Dodge/Default/Weapon.hs +++ b/src/Dodge/Default/Weapon.hs @@ -97,7 +97,6 @@ defaultGun = Item , _itInvDisplay = basicItemDisplay , _itInvColor = white , _itInvSize = 1 - , _itTargeting = Nothing , _itParams = NoParams , _itTweaks = NoTweaks , _itModules = M.fromList [(ModBullet , DefaultModule) @@ -121,7 +120,6 @@ defaultCraftable = Item , _itInvDisplay = basicItemDisplay , _itInvColor = green , _itInvSize = 1 - , _itTargeting = Nothing , _itParams = NoParams , _itDimension = defItDimCol green , _itTweaks = NoTweaks diff --git a/src/Dodge/Item/Weapon/Bezier.hs b/src/Dodge/Item/Weapon/Bezier.hs index 0017dc506..06c0a29bd 100644 --- a/src/Dodge/Item/Weapon/Bezier.hs +++ b/src/Dodge/Item/Weapon/Bezier.hs @@ -40,11 +40,12 @@ bezierGun = defaultGun -- , _itFloorPict = bezierGunSPic , _itAttachment = NoItAttachment , _itScroll = \_ _ -> removeItTarget - , _itEffect = rbSetTarget +-- , _itEffect = rbSetTarget -- , _itZoom = defaultItZoom , _itConsumption = defaultAmmo { _ammoBaseMax = 15 } + , _itTargeting' = targetRBPress } shootBezier :: Point2 -> Creature -> World -> World shootBezier targetp cr w = w & particles .:~ aCurveBulAt diff --git a/src/Dodge/Item/Weapon/BulletGun/Stick.hs b/src/Dodge/Item/Weapon/BulletGun/Stick.hs index 162b7635e..326665800 100644 --- a/src/Dodge/Item/Weapon/BulletGun/Stick.hs +++ b/src/Dodge/Item/Weapon/BulletGun/Stick.hs @@ -65,7 +65,6 @@ bangStick i = defaultGun ] , _itID = Nothing , _itInvColor = white - , _itTargeting = Nothing , _itParams = BulletShooter { _muzVel = 0.8 , _rifling = 0.8 @@ -185,7 +184,6 @@ pistol = (bangStick 1) -- , _itEquipPict = pictureWeaponAim pistolPic , _itID = Nothing , _itInvColor = white - , _itTargeting = Nothing , _itParams = BulletShooter { _muzVel = 0.8 , _rifling = 0.8 diff --git a/src/Dodge/Item/Weapon/ExtraEffect.hs b/src/Dodge/Item/Weapon/ExtraEffect.hs index 859d049a1..cf9202db1 100644 --- a/src/Dodge/Item/Weapon/ExtraEffect.hs +++ b/src/Dodge/Item/Weapon/ExtraEffect.hs @@ -7,7 +7,8 @@ module Dodge.Item.Weapon.ExtraEffect itemLaserScopeEffect , autoSonarEffect , autoRadarEffect - , rbSetTarget + , targetRBPress +-- , rbSetTarget ) where import Dodge.Data import Dodge.Base @@ -81,19 +82,43 @@ autoSonarEffect = ItInvEffect {_itInvEffect = f 50 ,_itEffectCounter = 0 } f t _ cr i w = w & creatures . ix (_crID cr) . crInv . ix i . itEffect . itInvEffect .~ f (t-1) -rbSetTarget :: ItEffect -rbSetTarget = ItInvEffect - {_itInvEffect = setTarg - ,_itEffectCounter = 0 +targetRBPress :: Targeting +targetRBPress = TargetingOnHeld + { _tgPos = Nothing + , _tgHeldUpdate = targetRBPressUpdate + , _tgDraw = targetRBPressDraw } +targetRBPressDraw :: Int -> Item -> Creature -> World -> Picture +targetRBPressDraw _ it _ w' = fromMaybe mempty $ do + mwp <- it ^? itTargeting' . tgPos . _Just + return $ setLayer 1 $ color red $ onLayer InvLayer $ uncurryV translate mwp + $ rotate (_cameraRot w') + $ pictures + [line [V2 x x, V2 (-x) (-x)] + ,line [V2 (-x) x, V2 x (-x)] + ] where - setTarg :: ItEffect -> Creature -> Int -> World -> World - setTarg _ cr invid w - | _crInvSel cr /= invid = w - | SDL.ButtonRight `S.member` _mouseButtons w = w - & creatures . ix (_crID cr) . crInv . ix invid . itTargeting - %~ maybe (Just $ targetRBMousePos w) Just - | otherwise = w & creatures . ix (_crID cr) . crInv . ix invid . itTargeting .~ Nothing + x = 5 / _cameraZoom w' + +targetRBPressUpdate :: Item -> Creature -> World -> Targeting -> Targeting +targetRBPressUpdate _ _ w t + | SDL.ButtonRight `S.member` _mouseButtons w = t + & tgPos %~ maybe (Just $ mouseWorldPos w) Just + | otherwise = t & tgPos %~ const Nothing + +--rbSetTarget :: ItEffect +--rbSetTarget = ItInvEffect +-- {_itInvEffect = setTarg +-- ,_itEffectCounter = 0 +-- } +-- where +-- setTarg :: ItEffect -> Creature -> Int -> World -> World +-- setTarg _ cr invid w +-- | _crInvSel cr /= invid = w +-- | SDL.ButtonRight `S.member` _mouseButtons w = w +-- & creatures . ix (_crID cr) . crInv . ix invid . itTargeting +-- %~ maybe (Just $ targetRBMousePos w) Just +-- | otherwise = w & creatures . ix (_crID cr) . crInv . ix invid . itTargeting .~ Nothing targetRBMousePos :: World diff --git a/src/Dodge/Item/Weapon/Targeting.hs b/src/Dodge/Item/Weapon/Targeting.hs index 603889fee..0379ddb07 100644 --- a/src/Dodge/Item/Weapon/Targeting.hs +++ b/src/Dodge/Item/Weapon/Targeting.hs @@ -10,9 +10,9 @@ useTargetPos -> Creature -> World -> World -useTargetPos f cr w = case cr ^? crInv . ix (_crInvSel cr) . itTargeting . _Just of +useTargetPos f cr w = case cr ^? crInv . ix (_crInvSel cr) . itTargeting' . tgPos of Nothing -> w - Just (g,_) -> f (g w) cr w + Just p -> f p cr w removeItTarget :: Item -> Item -removeItTarget = itTargeting .~ Nothing +removeItTarget = itTargeting' . tgPos .~ Nothing