Cleanup
This commit is contained in:
+40
-58
@@ -56,41 +56,35 @@ moveCamera w = w
|
||||
|
||||
updateScopeZoom :: World -> World
|
||||
updateScopeZoom w
|
||||
| SDL.ButtonRight `S.member` _mouseButtons w = case w ^? scppoint of
|
||||
| SDL.ButtonRight `S.member` _mouseButtons w
|
||||
= case w ^? creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
. itAttachment . scopeZoomChange of
|
||||
Just x
|
||||
| x > 9 -> zoomInLongGun $ zoomInLongGun
|
||||
$ w & creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
. itAttachment . scopeZoomChange -~ 2
|
||||
| x > 0 -> zoomInLongGun
|
||||
$ w & creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
. itAttachment . scopeZoomChange -~ 1
|
||||
| x < -9 -> zoomOutLongGun $ zoomOutLongGun
|
||||
$ w & creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
. itAttachment . scopeZoomChange +~ 2
|
||||
| x < 0 -> zoomOutLongGun $ zoomOutLongGun
|
||||
$ w & creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
. itAttachment . scopeZoomChange +~ 1
|
||||
| x > 9 -> zoomInLongGun $ zoomInLongGun $ w
|
||||
| x > 0 -> zoomInLongGun $ w
|
||||
| x < -9 -> zoomOutLongGun $ zoomOutLongGun $ w
|
||||
| x < 0 -> zoomOutLongGun $ w
|
||||
| otherwise -> w
|
||||
_ -> w
|
||||
| otherwise = w & creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
. itAttachment %~ updateScope
|
||||
where
|
||||
scppoint = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
. itAttachment . scopeZoomChange
|
||||
updateScope (ItScope _ _ _ bl) = ItScope (V2 0 0) 0 1 bl
|
||||
updateScope otherAtt = otherAtt
|
||||
|
||||
zoomSpeed :: Float
|
||||
zoomSpeed = 39/40
|
||||
|
||||
-- TODO unify zoom in and out, use scroll speed
|
||||
zoomInLongGun :: World -> World
|
||||
zoomInLongGun w
|
||||
| currentZoom < 8 = over (wpPointer . itAttachment . scopePos)
|
||||
(\p -> p +.+ (4-(4*zoomSpeed)) / currentZoom *.* mousep)
|
||||
(\p -> p +.+ (4-(4*zoomSpeed)) / currentZoom *.* mousep)
|
||||
$ over (wpPointer . itAttachment . scopeZoom) (/ zoomSpeed)
|
||||
$ decreaseScopeZoomChange
|
||||
w
|
||||
| otherwise = w
|
||||
| otherwise = decreaseScopeZoomChange w
|
||||
where
|
||||
decreaseScopeZoomChange = wpPointer . itAttachment . scopeZoomChange -~ 1
|
||||
wpPointer = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
wp = _crInv (_creatures w IM.! 0) IM.! _crInvSel (_creatures w IM.! 0)
|
||||
Just currentZoom = wp ^? itAttachment . scopeZoom
|
||||
@@ -98,40 +92,36 @@ zoomInLongGun w
|
||||
|
||||
zoomOutLongGun :: World -> World
|
||||
zoomOutLongGun w
|
||||
| currentZoom > 0.5 = over (wpPointer . itAttachment . scopeZoom) (* zoomSpeed) w
|
||||
| otherwise = w
|
||||
| currentZoom > 0.5 = over (wpPointer . itAttachment . scopeZoom) (* zoomSpeed)
|
||||
$ increaseScopeZoomChange w
|
||||
| otherwise = increaseScopeZoomChange w
|
||||
where
|
||||
increaseScopeZoomChange = wpPointer . itAttachment . scopeZoomChange +~ 1
|
||||
wpPointer = creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
wp = _crInv (_creatures w IM.! 0) IM.! _crInvSel (_creatures w IM.! 0)
|
||||
Just currentZoom = wp ^? itAttachment . scopeZoom
|
||||
|
||||
rotCam :: World -> World
|
||||
rotCam = rotateCameraL
|
||||
. rotateCameraR
|
||||
. zoomCamIn . zoomCamOut
|
||||
. autoZoomCam
|
||||
rotCam = rotateCameraKey . autoZoomCam
|
||||
|
||||
rotateCameraL :: World -> World
|
||||
rotateCameraL w
|
||||
| rotateCameraPlusKey (_keyConfig w) `S.member` _keys w
|
||||
= w & cameraRot +~ 0.015
|
||||
& creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
. itAttachment . scopePos %~ rotateV 0.015
|
||||
rotateCameraBy :: Float -> World -> World
|
||||
rotateCameraBy x w = w
|
||||
& cameraRot +~ x
|
||||
& creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
. itAttachment . scopePos %~ rotateV x
|
||||
|
||||
rotateCameraKey :: World -> World
|
||||
rotateCameraKey w
|
||||
| keyl && keyr = w
|
||||
| keyl = rotateCameraBy 0.015 w
|
||||
| keyr = rotateCameraBy (-0.015) w
|
||||
| otherwise = w
|
||||
rotateCameraR :: World -> World
|
||||
rotateCameraR w | rotateCameraMinusKey (_keyConfig w) `S.member` _keys w
|
||||
= w & cameraRot -~ 0.015
|
||||
& creatures . ix 0 . crInv . ix (_crInvSel (_creatures w IM.! 0))
|
||||
. itAttachment . scopePos %~ rotateV (-0.015)
|
||||
| otherwise = w
|
||||
zoomCamIn :: World -> World
|
||||
zoomCamIn w | zoomInKey (_keyConfig w) `S.member` _keys w
|
||||
= w {_cameraZoom = _cameraZoom w + 0.01}
|
||||
| otherwise = w
|
||||
zoomCamOut :: World -> World
|
||||
zoomCamOut w | zoomOutKey (_keyConfig w) `S.member` _keys w
|
||||
= w {_cameraZoom = max (_cameraZoom w - 0.01) 0.01}
|
||||
| otherwise = w
|
||||
where
|
||||
keyl = rotateCameraPlusKey (_keyConfig w) `S.member` _keys w
|
||||
keyr = rotateCameraMinusKey (_keyConfig w) `S.member` _keys w
|
||||
|
||||
zoomCamBy :: Float -> World -> World
|
||||
zoomCamBy x w = w {_cameraZoom = max (_cameraZoom w + x) 0.01}
|
||||
|
||||
zoomFromItem
|
||||
:: ItZoom
|
||||
@@ -145,7 +135,12 @@ zoomNoItem
|
||||
zoomNoItem = min 20 . max 0.2
|
||||
{- Automatically sets the zoom of the camera according to the surrounding walls. -}
|
||||
autoZoomCam :: World -> World
|
||||
autoZoomCam w = over cameraZoom changeZoom w
|
||||
autoZoomCam w
|
||||
| zoomInKey (_keyConfig w) `S.member` _keys w
|
||||
= zoomCamBy 0.01 w
|
||||
| zoomOutKey (_keyConfig w) `S.member` _keys w
|
||||
= zoomCamBy (-0.01) w
|
||||
| otherwise = w & cameraZoom %~ changeZoom
|
||||
where
|
||||
camPos = _cameraViewFrom w
|
||||
wallZoom = farWallDist camPos w
|
||||
@@ -185,18 +180,5 @@ farWallPoints p w = concatMap _grViewpoints grs ++ linkvps
|
||||
extend :: Point2 -> Point2
|
||||
extend outp = p +.+ maxViewDistance *.* safeNormalizeV (outp -.- p)
|
||||
|
||||
--farWallDist :: Point2 -> World -> Float
|
||||
--farWallDist p w = (winFac /) $ fromMaybe maxViewDistance
|
||||
-- $ L.fold (L.premap (dist p) L.maximum) vdists
|
||||
-- where
|
||||
-- hw = halfWidth w
|
||||
-- hh = halfHeight w
|
||||
-- winFac = min hw hh
|
||||
-- vdists :: [Point2]
|
||||
-- vdists = map (flip (collidePointUpToIndirect p) wos) vps
|
||||
-- vps = concatMap _grViewpoints grs
|
||||
-- grs = filter (pointInOrOnPolygon p . _grBound) (_gameRooms w)
|
||||
-- wos = wallsOnScreen w
|
||||
|
||||
maxViewDistance :: Float
|
||||
maxViewDistance = 800
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{-
|
||||
Functions that affect the world according to what pressed buttons are stored in a Set.
|
||||
{- Functions that affect the world according to what pressed buttons are stored in a Set.
|
||||
-}
|
||||
module Dodge.Update.UsingInput
|
||||
where
|
||||
( updateUsingInput
|
||||
) where
|
||||
import Dodge.Data
|
||||
import Dodge.Item.Data
|
||||
import Dodge.Creature.Impulse.UseItem
|
||||
@@ -13,8 +13,7 @@ import qualified Data.Set as S
|
||||
import Control.Lens
|
||||
|
||||
updateUsingInput :: World -> World
|
||||
updateUsingInput w =
|
||||
if _carteDisplay w
|
||||
updateUsingInput w = if _carteDisplay w
|
||||
then updatePressedButtonsCarte (_mouseButtons w) w
|
||||
else updatePressedButtons (_mouseButtons w) w
|
||||
|
||||
|
||||
Reference in New Issue
Block a user