Refactor event/input

This commit is contained in:
jgk
2021-03-26 14:52:25 +01:00
parent 420cf7fc4b
commit 07d84cc1c6
14 changed files with 91 additions and 63 deletions
+2 -2
View File
@@ -24,7 +24,7 @@ updateAimTime w
| otherwise = w & cameraAimTime %~ \t -> max (t-1) 0
moveCamera :: World -> World
moveCamera w = w & cameraPos .~ idealPos
moveCamera w = w & cameraCenter .~ idealPos
& cameraViewFrom .~ sightFrom
where aimRangeFactor | _cameraZoom w == 0 = 0
| otherwise = (fromMaybe 0 $ yourItem w ^? itAimingRange) / _cameraZoom w
@@ -36,7 +36,7 @@ moveCamera w = w & cameraPos .~ idealPos
currentOffset = currentPos -.- camCenter
idealPos = camCenter +.+ rotateV (_cameraRot w)
(aimRangeFactor * aimingMult *.* _mousePos w)
currentPos = _cameraPos w
currentPos = _cameraCenter w
camCenter = ypos +.+ scope
isCam :: Bool
isCam = fromMaybe False $ yourItem w ^? itAttachment . _Just . scopeIsCamera
+29
View File
@@ -0,0 +1,29 @@
module Dodge.Update.UsingInput
where
import Dodge.Data
import Dodge.CreatureAction.UseItem
import Geometry
import SDL
import qualified Data.Set as S
import Control.Lens
updateUsingInput :: World -> World
updateUsingInput w = updatePressedButtons (_mouseButtons w) w
updatePressedButtons :: S.Set MouseButton -> World -> World
updatePressedButtons keys w
| lbPressed && rbPressed
= useItem (_yourID w) w
| mbPressed
= set clickMousePos (_mousePos w) $ over cameraRot (\r-> r - rotation) w
| otherwise
= w
where lbPressed = ButtonLeft `S.member` keys
rbPressed = ButtonRight `S.member` keys
mbPressed = ButtonMiddle `S.member` keys
rotation = angleBetween (_mousePos w) (_clickMousePos w)