Cleanup code for your control
This commit is contained in:
@@ -20,15 +20,14 @@ import qualified SDL
|
||||
|
||||
-- | The AI equivalent for your control.
|
||||
yourControl :: Creature -> World -> World
|
||||
yourControl cr w
|
||||
yourControl _ w
|
||||
| inInputFocus w = w
|
||||
| not intopinv =
|
||||
w & cWorld . lWorld . creatures . ix (_crID cr)
|
||||
%~ wasdWithAiming w (_mvSpeed $ _crMvType cr)
|
||||
w & cWorld . lWorld . creatures . ix 0 %~ wasdWithAiming w
|
||||
| otherwise =
|
||||
w
|
||||
& cWorld . lWorld . creatures . ix (_crID cr)
|
||||
%~ (wasdWithAiming w (_mvSpeed $ _crMvType cr) . mouseActionsCr (_mouseButtons (_input w)))
|
||||
& cWorld . lWorld . creatures . ix 0
|
||||
%~ (wasdWithAiming w . mouseActionsCr (w ^. input . mouseButtons))
|
||||
& pressedMBEffectsTopInventory pkeys
|
||||
& handleHotkeys
|
||||
where
|
||||
@@ -91,88 +90,43 @@ tryAssignHotkey w sc = fromMaybe w $ do
|
||||
itid <- cr ^? crManipulation . manObject . imSelectedItem
|
||||
return $ w & cWorld . lWorld . creatures . ix 0 %~ assignHotkey itid (scancodeToHotkey sc)
|
||||
|
||||
{- | Turn key presses into creature movement.
|
||||
| note the order of operation, setting the posture first--this prevents the twist fire bug
|
||||
{- | The order of these MAY be important, in particular the setting of crMvAim
|
||||
within wasdMovement should probably be done first
|
||||
-}
|
||||
--wasdWithAiming ::
|
||||
-- World ->
|
||||
-- -- | Base speed
|
||||
-- Float ->
|
||||
-- Creature ->
|
||||
-- Creature
|
||||
--wasdWithAiming w speed cr
|
||||
-- | isAiming = addAnyTwist $ aimTurn mouseDir $ theMovement $ setMvAim cr
|
||||
-- | crIsReloading cr && SDL.ButtonRight `M.member` _mouseButtons (_input w) =
|
||||
-- aimTurn mouseDir $ removeTwist $ theMovement $ setMvAim cr
|
||||
-- | otherwise = theMovement $ theTurn $ removeTwist $ setMvAim cr
|
||||
-- where
|
||||
-- setMvAim = maybe id (crMvAim .~) dir
|
||||
-- twistamount = 1.6
|
||||
-- removeTwist cr' =
|
||||
-- cr'
|
||||
-- & crDir +~ _crTwist cr'
|
||||
-- & crTwist .~ 0
|
||||
-- addAnyTwist = fromMaybe id $ do
|
||||
-- itRef <- cr ^? crManipulation . manObject . inInventory . ispItem
|
||||
-- astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
|
||||
-- case (astance, cr ^. crTwist) of
|
||||
-- (TwoHandUnder, 0) ->
|
||||
-- return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi)
|
||||
-- (TwoHandOver, 0) ->
|
||||
-- return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi)
|
||||
-- _ -> Nothing
|
||||
-- theMovement
|
||||
-- | movDir == V2 0 0 = id
|
||||
-- | otherwise = crMvAbsolute (speed *.* movAbs)
|
||||
-- theTurn cr' = creatureTurnTowardDir (_crMvAim cr') 0.2 cr'
|
||||
-- movDir = wasdDir (w ^. input)
|
||||
-- dir = fmap ((w ^. wCam . camRot) +) (safeArgV movDir)
|
||||
-- movAbs = rotateV (w ^. wCam . camRot) $ normalizeV movDir
|
||||
-- isAiming = _posture (_crStance cr) == Aiming
|
||||
-- mouseDir = argV $ mouseWorldPos (w ^. input) (w ^. wCam) - (cr ^. crPos)
|
||||
|
||||
-- | The order of these MAY be important, in particular the setting of crMvAim
|
||||
-- within wasdMovement should probably be done first
|
||||
wasdWithAiming ::
|
||||
World ->
|
||||
-- | Base speed
|
||||
Float ->
|
||||
Creature ->
|
||||
Creature
|
||||
wasdWithAiming w speed = wasdAim inp cam . wasdTwist . wasdMovement inp cam speed
|
||||
wasdWithAiming w cr = wasdAim inp cam . wasdTwist $ wasdMovement inp cam speed cr
|
||||
where
|
||||
speed = _mvSpeed $ _crMvType cr
|
||||
inp = w ^. input
|
||||
cam = w ^. wCam
|
||||
|
||||
wasdAim :: Input -> Camera -> Creature -> Creature
|
||||
wasdAim inp cam cr
|
||||
| SDL.ButtonRight `M.member` _mouseButtons inp = aimTurn mouseDir cr
|
||||
| otherwise = theTurn cr
|
||||
| otherwise = creatureTurnTowardDir (_crMvAim cr) 0.2 cr
|
||||
where
|
||||
theTurn cr' = creatureTurnTowardDir (_crMvAim cr') 0.2 cr'
|
||||
mouseDir = argV $ mouseWorldPos inp cam - (cr ^. crPos)
|
||||
|
||||
-- aim with the root item
|
||||
wasdTwist :: Creature -> Creature
|
||||
wasdTwist cr
|
||||
| _posture (_crStance cr) == Aiming = addAnyTwist cr
|
||||
| otherwise = removeTwist cr
|
||||
where
|
||||
twistamount = 1.6
|
||||
removeTwist cr' =
|
||||
cr'
|
||||
& crDir +~ _crTwist cr'
|
||||
& crTwist .~ 0
|
||||
addAnyTwist = fromMaybe id $ do
|
||||
| _posture (_crStance cr) == Aiming = fromMaybe cr $ do
|
||||
itRef <- cr ^? crManipulation . manObject . imRootItem
|
||||
astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
|
||||
case (astance, cr ^. crTwist) of
|
||||
(TwoHandUnder, 0) ->
|
||||
return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi)
|
||||
return $ cr & crTwist .~ twistamount * pi & crDir -~ twistamount * pi
|
||||
(TwoHandOver, 0) ->
|
||||
return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi)
|
||||
return $ cr & crTwist .~ twistamount * pi & crDir -~ twistamount * pi
|
||||
_ -> Nothing
|
||||
|
||||
| otherwise = cr
|
||||
& crDir +~ _crTwist cr
|
||||
& crTwist .~ 0 --remove twistk
|
||||
where
|
||||
twistamount = 1.6
|
||||
|
||||
wasdMovement :: Input -> Camera -> Float -> Creature -> Creature
|
||||
wasdMovement inp cam speed = theMovement . setMvAim
|
||||
@@ -193,11 +147,14 @@ aimTurn a cr = creatureTurnTowardDir a (x * 0.2) cr
|
||||
itRef <- cr ^? crManipulation . manObject . imRootItem
|
||||
cr ^? crInv . ix itRef . itUse . heldAim . aimTurnSpeed
|
||||
|
||||
-- | Set posture according to mouse presses.
|
||||
{- | Set posture according to mouse presses.
|
||||
(should you be aiming without a selected item?)
|
||||
-}
|
||||
mouseActionsCr :: M.Map SDL.MouseButton Int -> Creature -> Creature
|
||||
mouseActionsCr pkeys cr
|
||||
| SDL.ButtonRight `M.member` pkeys = cr & crStance . posture .~ Aiming
|
||||
| otherwise = cr & crStance . posture .~ AtEase
|
||||
mouseActionsCr pkeys
|
||||
| SDL.ButtonRight `M.member` pkeys = crStance . posture .~ Aiming
|
||||
| otherwise = crStance . posture .~ AtEase
|
||||
|
||||
-- where
|
||||
-- noaction = fromMaybe True $ do
|
||||
-- theaction <- cr ^? crManipulation . manObject . inInventory . iselAction
|
||||
@@ -210,7 +167,7 @@ pressedMBEffectsTopInventory pkeys w
|
||||
| isDown SDL.ButtonMiddle = w & wCam . camRot -~ rotation
|
||||
| otherwise = w
|
||||
where
|
||||
youhammerdown = set (cWorld . lWorld . creatures . ix 0 . crHammerPosition) HammerDown
|
||||
youhammerdown = set (cWorld . lWorld . creatures . ix 0 . crHammerPosition) HammerDown
|
||||
inTopInv = case w ^. hud . hudElement of
|
||||
DisplayInventory{_subInventory = NoSubInventory} -> True
|
||||
_ -> False
|
||||
|
||||
Reference in New Issue
Block a user