Move targeting to dedicated datatype within item
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
+1
-2
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user