This commit is contained in:
2025-05-31 08:17:26 +01:00
parent cdf300b824
commit ceb7a4f04c
6 changed files with 99 additions and 133 deletions
+33 -63
View File
@@ -2,9 +2,7 @@ module Dodge.Creature.YourControl (
yourControl,
) where
import Dodge.SelectedClose
import Control.Monad
import Data.Foldable
import qualified Data.Map.Strict as M
import Data.Maybe
import Dodge.Base.Coordinate
@@ -14,6 +12,7 @@ import Dodge.Data.World
import Dodge.Hotkey
import Dodge.InputFocus
import Dodge.Inventory
import Dodge.SelectedClose
import Dodge.WASD
import Geometry
import LensHelp
@@ -27,9 +26,7 @@ yourControl _ w
| Just x <- w ^? hud . hudElement . subInventory
, f x =
w
& cWorld . lWorld . creatures . ix 0
-- %~ (wasdWithAiming w . setCrPosture pkeys)
%~ wasdWithAiming w
& cWorld . lWorld . creatures . ix 0 %~ wasdWithAiming w
& tryClickUse pkeys
& handleHotkeys
| otherwise =
@@ -42,17 +39,17 @@ yourControl _ w
handleHotkeys :: World -> World
handleHotkeys w
| SDL.ScancodeLShift `M.member` _pressedKeys (_input w)
|| SDL.ScancodeRShift `M.member` _pressedKeys (_input w)
, hks <- mapMaybe scancodeToHotkey $ M.keys $ w ^. input . pressedKeys
| ispressed SDL.ScancodeLShift || ispressed SDL.ScancodeRShift
, Just hk <- listToMaybe . mapMaybe scancodeToHotkey . M.keys $ w ^. input . pressedKeys
, Just invid <- lw ^? creatures . ix 0 . crManipulation . manObject . imSelectedItem
, Just itid <- lw ^? creatures . ix 0 . crInv . ix invid . itID =
w & cWorld . lWorld %~ \lw' -> foldl' (flip $ assignHotkey itid) lw' hks
| SDL.ScancodeLCtrl `M.member` _pressedKeys (_input w)
|| SDL.ScancodeRCtrl `M.member` _pressedKeys (_input w)
, Just hk <- listToMaybe . mapMaybe scancodeToHotkey . M.keys $ w ^. input . pressedKeys
, Just itid <- w ^? cWorld . lWorld . hotkeys . ix hk . unNInt
, Just invid <- w ^? cWorld . lWorld . itemLocations . ix itid . ilInvID =
w & cWorld . lWorld %~ assignHotkey itid hk
| ispressed SDL.ScancodeLCtrl || ispressed SDL.ScancodeRCtrl
, Just hk <-
listToMaybe . mapMaybe scancodeToHotkey . M.keys $
w ^. input . pressedKeys
, Just itid <- lw ^? hotkeys . ix hk . unNInt
, Just invid <- lw ^? itemLocations . ix itid . ilInvID =
w & augInvDirectSelect (0, invid, mempty)
| otherwise =
M.foldl'
@@ -60,6 +57,7 @@ handleHotkeys w
w
(M.intersectionWith (,) thehotkeys (w ^. input . pressedKeys))
where
ispressed k = k `M.member` _pressedKeys (_input w)
thehotkeys = M.mapKeys hotkeyToScancode $ w ^. cWorld . lWorld . hotkeys
lw = w ^. cWorld . lWorld
@@ -112,11 +110,7 @@ scancodeToHotkey x = case x of
{- | The order of these MAY be important, in particular the setting of crMvAim
within wasdMovement should probably be done first
-}
wasdWithAiming ::
World ->
Creature ->
Creature
--wasdWithAiming w cr = wasdAim inp cam . wasdTwist $ wasdMovement inp cam speed cr
wasdWithAiming :: World -> Creature -> Creature
wasdWithAiming w cr = wasdAim inp cam $ wasdMovement inp cam speed cr
where
speed = _mvSpeed $ _crMvType cr
@@ -125,57 +119,32 @@ wasdWithAiming w cr = wasdAim inp cam $ wasdMovement inp cam speed cr
wasdAim :: Input -> Camera -> Creature -> Creature
wasdAim inp cam cr
| Just 0 <- inp ^? mouseButtons . ix SDL.ButtonRight
= setAimPosture cr
| Just 0 <- inp ^? mouseButtonsReleased . ix SDL.ButtonRight
= removeAimPosture cr
| Just 0 <- inp ^? mouseButtons . ix SDL.ButtonRight =
setAimPosture cr
| Just 0 <- inp ^? mouseButtonsReleased . ix SDL.ButtonRight =
removeAimPosture cr
| SDL.ButtonRight `M.member` _mouseButtons inp = aimTurn mouseDir cr
| otherwise = creatureTurnTowardDir (_crMvAim cr) 0.2 cr
where
mouseDir = argV $ mouseWorldPos inp cam - (cr ^. crPos)
---- aim with the root item
---- when initiating aim with a two handed weapon, change the creature direction
---- to be closer to where the two handed weapon was pointing
--wasdTwist :: Creature -> Creature
--wasdTwist cr
---- | _posture (_crStance cr) == Aiming
-- | Aiming {} <- cr ^. crStance . posture = fromMaybe cr $ do
-- itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
-- astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
-- case (astance, cr ^. crTwist) of
-- (TwoHandUnder, 0) ->
-- return $ cr & crTwist .~ twistamount * pi & crDir -~ twistamount * pi
-- (TwoHandOver, 0) ->
-- return $ cr & crTwist .~ twistamount * pi & crDir -~ twistamount * pi
-- _ -> Nothing
-- | otherwise =
-- cr
-- & crDir +~ _crTwist cr
-- & crTwist .~ 0 --remove twistk
-- where
-- twistamount = 1.6
setAimPosture :: Creature -> Creature
setAimPosture cr = fromMaybe cr $ do
setAimPosture = (crStance . posture .~ Aiming) . doAimTwist (- twoHandTwistAmount)
doAimTwist :: Float -> Creature -> Creature
doAimTwist x cr = fromMaybe cr $ do
itRef <- cr ^? crManipulation . manObject . imRootSelectedItem
astance <- cr ^? crInv . ix itRef . itUse . heldAim . aimStance
case astance of
TwoHandUnder ->
return $ cr & crStance . posture .~ Aiming
& crDir -~ twoHandTwistAmount
TwoHandOver ->
return $ cr & crStance . posture .~ Aiming
& crDir -~ twoHandTwistAmount
_ -> return $ cr & crStance . posture .~ Aiming
return $ case astance of
TwoHandUnder -> cr & crDir +~ x
TwoHandOver -> cr & crDir +~ x
_ -> cr
removeAimPosture :: Creature -> Creature
removeAimPosture = (crStance . posture .~ AtEase) . doAimTwist twoHandTwistAmount
twoHandTwistAmount :: Float
twoHandTwistAmount = 1.6 * pi
removeAimPosture :: Creature -> Creature
removeAimPosture cr = cr
& crDir +~ twoHandTwistAmount
& crStance . posture .~ AtEase
wasdMovement :: Input -> Camera -> Float -> Creature -> Creature
wasdMovement inp cam speed = theMovement . setMvAim
@@ -201,10 +170,11 @@ tryClickUse pkeys w = fromMaybe w $ do
ltime <- pkeys ^? ix SDL.ButtonLeft
rtime <- pkeys ^? ix SDL.ButtonRight
guard $ ltime <= rtime
case w ^? cWorld . lWorld . creatures . ix 0
. crManipulation
. manObject
. imSelectedItem of
case w
^? cWorld . lWorld . creatures . ix 0
. crManipulation
. manObject
. imSelectedItem of
Just invid -> useItem invid (f ltime) w
Nothing -> interactWithCloseObj <$> getSelectedCloseObj w ?? w
where