Implement floating camera

This commit is contained in:
2023-03-26 16:44:19 +01:00
parent 082ce9c9a1
commit 73e742e1a2
12 changed files with 86 additions and 38 deletions
+15 -10
View File
@@ -105,11 +105,13 @@ gotoTerminal w = case _uvScreenLayers w of
_ -> w & uvScreenLayers .:~ InputScreen mempty "Enter command"
updateUniverseLast :: Universe -> Universe
updateUniverseLast =
over uvWorld (input . mouseButtons . each .~ True) -- to determine if the mouse button is held
. over uvWorld (input . pressedKeys . each %~ f)
. over uvWorld (input . mouseMoving .~ False)
updateUniverseLast u = u
& uvWorld . input . pressedKeys . each %~ f
& uvWorld . input . mouseMoving .~ False
& uvWorld . input . mouseButtons . each +~ 1
& uvWorld . input . heldPos %~ M.union (fmap (const mp) (u ^. uvWorld . input . mouseButtons))
where
mp = u ^. uvWorld . input . mousePos
f LongPress = LongPress
f _ = ShortPress
@@ -131,25 +133,28 @@ updateUniverseMid u = case _uvScreenLayers u of
timeFlowUpdate :: Universe -> Universe
timeFlowUpdate u = case u ^. uvWorld . timeFlow of
_ | debugcamera -> u
NormalTimeFlow -> functionalUpdate u
ScrollTimeFlow smoothing _ _ _ -> over uvWorld (doTimeScroll smoothing) u
RewindLeftClick 0 _ -> u & uvWorld . timeFlow .~ NormalTimeFlow
RewindLeftClick _ _ -> over uvWorld scrollTimeBack u -- & uvWorld . cWorld . timeFlow .~ NormalTimeFlow
DeathTime{} -> u
PausedTimeFlow _ itmloc -> over uvWorld (pauseTime itmloc) u
where
debugcamera = CamInGame /= (u ^. uvWorld . cWorld . cwCam . camControl)
pauseTime :: Int -> World -> World
pauseTime itmloc w
| justPressedButtonLeft || outofcharge = w & timeFlow .~ NormalTimeFlow
| otherwise = w & pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix itmloc) . itUse . leftConsumption . wpCharge -~ 1
where
justPressedButtonLeft = w ^? input . mouseButtons . ix ButtonLeft == Just False
justPressedButtonLeft = w ^? input . mouseButtons . ix ButtonLeft == Just 1
outofcharge = maybe True (== 0) charge
charge = w ^? pointerToItemLocation (w ^?! cWorld . lWorld . itemLocations . ix itmloc) . itUse . leftConsumption . wpCharge
doTimeScroll :: Int -> World -> World
doTimeScroll smoothing w = case w ^? input . mouseButtons . ix ButtonLeft of
Just False -> w & timeFlow .~ NormalTimeFlow
Just 1 -> w & timeFlow .~ NormalTimeFlow
_ -> doTimeScroll' smoothing w
doTimeScroll' :: Int -> World -> World
@@ -286,16 +291,16 @@ updateWorldSelect' w = over input (updateWorldSelect (w ^. cWorld . cwCam)) w
updateWorldSelect :: Camera -> Input -> Input
updateWorldSelect cam inp = f . g $ case (inp ^? mouseButtons . ix ButtonLeft, inp ^? mouseButtons . ix ButtonRight) of
(Just False, Nothing) ->
(Just 1, Nothing) ->
inp & lLine . _1 .~ mwp
& lrLine . _1 .~ mwp
(Just True, Nothing) ->
(Just _, Nothing) ->
inp & lLine . _2 .~ mwp
& lrLine . _1 .~ mwp
(Nothing, Just False) ->
(Nothing, Just 1) ->
inp & rLine . _1 .~ mwp
& lrLine . _2 .~ mwp
(Nothing, Just True) ->
(Nothing, Just _) ->
inp & rLine . _2 .~ mwp
& lrLine . _2 .~ mwp
_ -> inp