Separate out input datatype

This commit is contained in:
2022-10-29 11:36:57 +01:00
parent 82e2a5a234
commit af6cdff063
19 changed files with 160 additions and 112 deletions
+8 -8
View File
@@ -53,13 +53,13 @@ moveZoomCamera cfig w =
vfoffset = do
iscam <- yourItem w ^? _Just . itScope . scopeIsCamera
guard iscam
guard (SDL.ButtonRight `M.member` _mouseButtons w)
guard (SDL.ButtonRight `M.member` _mouseButtons (_input w))
yourItem w ^? _Just . itScope . scopePos
mscopeoffset = do
guard (SDL.ButtonRight `M.member` _mouseButtons w)
guard (SDL.ButtonRight `M.member` _mouseButtons (_input w))
yourItem w ^? _Just . itScope . scopePos
newcen = cpos +.+ fromMaybe (V2 0 0) mscopeoffset +.+ offset
offset = rotateV (w ^. cWorld . lWorld . camPos . camRot) $ ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos w
offset = rotateV (w ^. cWorld . lWorld . camPos . camRot) $ ((newzoom - newDefaultZoom) / (newDefaultZoom * newzoom)) *.* _mousePos (_input w)
newzoom = case yourItem w ^? _Just . itScope of
Just zs@ZoomScope{} -> _scopeZoom zs
_ -> newDefaultZoom * newItemZoom
@@ -88,7 +88,7 @@ moveZoomCamera cfig w =
updateScopeZoom :: World -> World
updateScopeZoom w
| SDL.ButtonRight `M.member` _mouseButtons w =
| SDL.ButtonRight `M.member` _mouseButtons (_input w) =
case w
^? cWorld . lWorld . creatures . ix 0 . crInv . ix (crSel (w ^?! cWorld . lWorld . creatures . ix 0))
. itScope
@@ -129,7 +129,7 @@ zoomInLongGun w
ycr = you w
Just currentZoom = wp ^? itScope . scopeZoom
newzoom = (wp ^?! itScope . scopeZoom) / zoomSpeed
mousep = rotateV (w ^. cWorld . lWorld . camPos . camRot) $ _mousePos w
mousep = rotateV (w ^. cWorld . lWorld . camPos . camRot) $ _mousePos (_input w)
zoomOutLongGun :: World -> World
zoomOutLongGun w
@@ -150,7 +150,7 @@ zoomOutLongGun w
ifConfigWallRotate :: Configuration -> World -> World
ifConfigWallRotate cfig w
| _gameplay_rotate_to_wall cfig && not (SDL.ButtonRight `M.member` _mouseButtons w) =
| _gameplay_rotate_to_wall cfig && not (SDL.ButtonRight `M.member` _mouseButtons (_input w)) =
rotateToOverlappingWall w
| otherwise = w
@@ -193,8 +193,8 @@ rotateCamera cfig w
| keyr = over (cWorld . lWorld) (rotateCameraBy (-0.025)) w
| otherwise = ifConfigWallRotate cfig w
where
keyl = SDL.ScancodeQ `Set.member` _keys w && notAtTerminal w
keyr = SDL.ScancodeE `Set.member` _keys w && notAtTerminal w
keyl = SDL.ScancodeQ `Set.member` _keys (_input w) && notAtTerminal w
keyr = SDL.ScancodeE `Set.member` _keys (_input w) && notAtTerminal w
-- TODO check where/how this is used
notAtTerminal :: World -> Bool
+3 -3
View File
@@ -72,9 +72,9 @@ updateWheelEvent yi w = case w ^. cWorld . lWorld . hud . hudElement of
numcombs = length $ combineItemListYou w
y = fromIntegral yi
numLocs = (fst . IM.findMax $ (w ^. cWorld . lWorld . seenLocations)) + 1
rbDown = ButtonRight `M.member` _mouseButtons w
lbDown = ButtonLeft `M.member` _mouseButtons w
invKeyDown = ScancodeCapsLock `S.member` _keys w
rbDown = ButtonRight `M.member` _mouseButtons (_input w)
lbDown = ButtonLeft `M.member` _mouseButtons (_input w)
invKeyDown = ScancodeCapsLock `S.member` _keys (_input w)
scrollRBOption :: Float -> World -> World
scrollRBOption y w
+20 -20
View File
@@ -20,49 +20,49 @@ import SDL
updateUsingInput :: World -> World
updateUsingInput w = case w ^. cWorld . lWorld . hud . hudElement of
DisplayInventory subinv ->
pressedMBEffects subinv (_mouseButtons w) w
pressedMBEffects subinv (_mouseButtons (_input w)) w
DisplayCarte ->
updatePressedButtonsCarte (_mouseButtons w) w
updatePressedButtonsCarte (_mouseButtons (_input w)) w
pressedMBEffects :: SubInventory -> M.Map MouseButton Bool -> World -> World
pressedMBEffects subinv pkeys w = case subinv of
NoSubInventory
| ButtonLeft `M.member` pkeys && w ^?! hammers . ix SubInvHam /= HammerUp ->
w & hammers . ix SubInvHam .~ HammerDown
| ButtonLeft `M.member` pkeys && w ^?! input . hammers . ix SubInvHam /= HammerUp ->
w & input . hammers . ix SubInvHam .~ HammerDown
| otherwise -> pressedMBEffectsNoInventory pkeys w
CombineInventory mi
| pkeys ^? ix ButtonLeft == Just False ->
maybeexitcombine (maybe id doCombine mi w) & hammers . ix SubInvHam .~ HammerDown
maybeexitcombine (maybe id doCombine mi w) & input . hammers . ix SubInvHam .~ HammerDown
DisplayTerminal tmid
| pkeys ^? ix ButtonLeft == Just False && inTermFocus w ->
doTerminalEffectLB (w ^?! cWorld . lWorld . terminals . ix tmid) w
& hammers . ix SubInvHam .~ HammerDown
& input . hammers . ix SubInvHam .~ HammerDown
| pkeys ^? ix ButtonLeft == Just False ->
w & cWorld . lWorld . terminals . ix tmid . tmInput . tiFocus %~ const True
& hammers . ix SubInvHam .~ HammerDown
& input . hammers . ix SubInvHam .~ HammerDown
_
| ButtonLeft `M.member` pkeys ->
w & hammers . ix SubInvHam .~ HammerDown
w & input . hammers . ix SubInvHam .~ HammerDown
_ -> w
where
maybeexitcombine
| ButtonRight `M.member` _mouseButtons w = id
| ButtonRight `M.member` _mouseButtons (_input w) = id
| otherwise = cWorld . lWorld . hud . hudElement .~ DisplayInventory NoSubInventory
pressedMBEffectsNoInventory :: M.Map MouseButton Bool -> World -> World
pressedMBEffectsNoInventory pkeys w
| isDown ButtonLeft && isDown ButtonRight && inTopInv =
useItem (you w) w & hammers . ix DoubleMouseHam .~ HammerDown
useItem (you w) w & input . hammers . ix DoubleMouseHam .~ HammerDown
| justPressedDown ButtonLeft && inTopInv
&& w ^?! hammers . ix DoubleMouseHam == HammerUp =
&& w ^?! input . hammers . ix DoubleMouseHam == HammerUp =
useLeftItem 0 w
| isDown ButtonLeft && inTopInv =
w & hammers . ix DoubleMouseHam .~ HammerDown
w & input . hammers . ix DoubleMouseHam .~ HammerDown
| isDown ButtonRight && inTopInv = w
| isDown ButtonMiddle =
w & cWorld . lWorld . camPos . camRot -~ rotation
& clickMousePos .~ _mousePos w
| isDown ButtonLeft = w & hammers . ix DoubleMouseHam .~ HammerDown
& input . clickMousePos .~ _mousePos (_input w)
| isDown ButtonLeft = w & input . hammers . ix DoubleMouseHam .~ HammerDown
| otherwise = w
where
inTopInv = case w ^. cWorld . lWorld . hud . hudElement of
@@ -70,7 +70,7 @@ pressedMBEffectsNoInventory pkeys w
_ -> False
justPressedDown but = (pkeys ^. at but) == Just False
isDown but = but `M.member` pkeys
rotation = angleBetween (_mousePos w) (_clickMousePos w)
rotation = angleBetween (_mousePos (_input w)) (_clickMousePos (_input w))
-- note "sort" on the inventory indices; otherwise
-- lower items may be shifted up and items below these removed instead
@@ -90,16 +90,16 @@ updatePressedButtonsCarte :: M.Map MouseButton Bool -> World -> World
updatePressedButtonsCarte pkeys w
| isDown ButtonRight =
w
& clickMousePos .~ _mousePos w
& input . clickMousePos .~ _mousePos (_input w)
& cWorld . lWorld . hud . carteCenter %~ (-.- trans)
| isDown ButtonLeft =
w
& clickMousePos .~ _mousePos w
& input . clickMousePos .~ _mousePos (_input w)
& cWorld . lWorld . hud . carteRot -~ rot
& cWorld . lWorld . hud . carteZoom *~ czoom
| otherwise = w
where
isDown but = but `M.member` pkeys
rot = angleBetween (_mousePos w) (_clickMousePos w)
czoom = magV (_mousePos w) / magV (_clickMousePos w)
trans = rotateV (w ^. cWorld . lWorld . hud . carteRot) $ 1 / (w ^. cWorld . lWorld . hud . carteZoom) *.* (_mousePos w -.- _clickMousePos w)
rot = angleBetween (_mousePos (_input w)) (_clickMousePos (_input w))
czoom = magV (_mousePos (_input w)) / magV (_clickMousePos (_input w))
trans = rotateV (w ^. cWorld . lWorld . hud . carteRot) $ 1 / (w ^. cWorld . lWorld . hud . carteZoom) *.* (_mousePos (_input w) -.- _clickMousePos (_input w))