Fix scope rotation after torque

This commit is contained in:
2023-05-28 16:22:54 +01:00
parent 24939094c6
commit 9283ae187f
7 changed files with 39 additions and 41 deletions
+10 -16
View File
@@ -2,8 +2,6 @@ module Dodge.Creature.YourControl (
yourControl,
) where
import Dodge.Creature.Impulse.UseItem
import Dodge.Hotkey
import Control.Monad
import Data.Foldable
import qualified Data.Map.Strict as M
@@ -11,8 +9,10 @@ import Data.Maybe
import Dodge.Base.Coordinate
import Dodge.Base.You
import Dodge.Creature.Impulse.Movement
import Dodge.Creature.Impulse.UseItem
import Dodge.Creature.Test
import Dodge.Data.World
import Dodge.Hotkey
import Dodge.InputFocus
import Dodge.WASD
import Geometry
@@ -92,8 +92,9 @@ tryAssignHotkey w sc = fromMaybe w $ do
itid <- cr ^? crManipulation . manObject . inInventory . ispItem
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
{- | Turn key presses into creature movement.
| note the order of operation, setting the posture first--this prevents the twist fire bug
-}
wasdWithAiming ::
World ->
-- | Base speed
@@ -115,16 +116,11 @@ wasdWithAiming w speed cr
addAnyTwist = fromMaybe id $ do
itRef <- cr ^? crManipulation . manObject . inInventory . ispItem
astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
let currenttwistamount = cr ^. crTwist
case (astance, currenttwistamount) of
case (astance, cr ^. crTwist) of
(TwoHandUnder, 0) ->
return $
(crTwist .~ twistamount * pi)
. (crDir -~ twistamount * pi)
return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi)
(TwoHandOver, 0) ->
return $
(crTwist .~ twistamount * pi)
. (crDir -~ twistamount * pi)
return $ (crTwist .~ twistamount * pi) . (crDir -~ twistamount * pi)
_ -> Nothing
theMovement
| movDir == V2 0 0 = id
@@ -154,11 +150,10 @@ aimTurn a cr = creatureTurnTowardDir a (x * 0.2) cr
-- | Set posture according to mouse presses.
mouseActionsCr :: M.Map SDL.MouseButton Int -> Creature -> Creature
mouseActionsCr pkeys cr
| rbPressed && noaction =
| SDL.ButtonRight `M.member` pkeys && noaction =
cr & crStance . posture .~ Aiming
| otherwise = cr & crStance . posture .~ AtEase
where
rbPressed = SDL.ButtonRight `M.member` pkeys
noaction = fromMaybe True $ do
theaction <- cr ^? crManipulation . manObject . inInventory . iselAction
return $ theaction == NoInvSelAction
@@ -167,8 +162,7 @@ pressedMBEffectsTopInventory :: M.Map SDL.MouseButton Int -> World -> World
pressedMBEffectsTopInventory pkeys w
| isDown SDL.ButtonLeft && isDown SDL.ButtonRight && inTopInv = useItemRightClick (you w) w
| isDown SDL.ButtonLeft && inTopInv = useItemLeftClick (you w) w
| isDown SDL.ButtonMiddle =
w & wCam . camRot -~ rotation
| isDown SDL.ButtonMiddle = w & wCam . camRot -~ rotation
| otherwise = w
where
inTopInv = case w ^. hud . hudElement of