Move targeting to dedicated datatype within item

This commit is contained in:
2022-02-22 21:49:10 +00:00
parent 055fcf4cce
commit 8a7d06783d
9 changed files with 48 additions and 29 deletions
+37 -12
View File
@@ -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