Cleanup
This commit is contained in:
@@ -9,14 +9,6 @@ import Control.Lens
|
||||
import qualified Data.Map.Strict as M
|
||||
import Geometry.Data
|
||||
import SDL (MouseButton, Scancode)
|
||||
import Data.Aeson
|
||||
import Data.Aeson.TH
|
||||
|
||||
--data PressType
|
||||
-- = InitialPress Int
|
||||
-- | ShortPress Int
|
||||
-- | LongPress Int
|
||||
-- deriving (Eq, Show)
|
||||
|
||||
data MouseContext
|
||||
= NoMouseContext
|
||||
@@ -72,4 +64,3 @@ data TermSignal
|
||||
|
||||
makeLenses ''Input
|
||||
makeLenses ''MouseContext
|
||||
--deriveJSON defaultOptions ''PressType
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
|
||||
module Dodge.Data.WorldEffect where
|
||||
|
||||
import Dodge.Data.Input
|
||||
import Dodge.Data.LightSource
|
||||
import Data.Aeson
|
||||
import Data.Aeson.TH
|
||||
|
||||
+10
-17
@@ -23,13 +23,8 @@ handleKeyboardEvent :: KeyboardEventData -> Input -> Input
|
||||
handleKeyboardEvent kev = case keyboardEventKeyMotion kev of
|
||||
Released -> pressedKeys . at scode .~ Nothing
|
||||
Pressed | keyboardEventRepeat kev -> addTermSignal scode
|
||||
Pressed | not (keyboardEventRepeat kev) ->
|
||||
(pressedKeys . at scode ?~ 0)
|
||||
. addTermSignal scode
|
||||
Pressed -> (pressedKeys . at scode ?~ 0) . addTermSignal scode
|
||||
where
|
||||
-- val
|
||||
-- | keyboardEventRepeat kev = LongPress 0
|
||||
-- | otherwise = InitialPress 0
|
||||
scode = (keysymScancode . keyboardEventKeysym) kev
|
||||
|
||||
addTermSignal :: Scancode -> Input -> Input
|
||||
@@ -46,9 +41,7 @@ addTermSignal sc = case sc of
|
||||
_ -> id
|
||||
|
||||
handleMouseMotionEvent :: MouseMotionEventData -> Configuration -> Input -> Input
|
||||
handleMouseMotionEvent mmev cfig =
|
||||
set mousePos themousepos
|
||||
. set mouseMoving True
|
||||
handleMouseMotionEvent mmev cfig = set mousePos themousepos . set mouseMoving True
|
||||
where
|
||||
P (V2 x y) = mouseMotionEventPos mmev
|
||||
themousepos =
|
||||
@@ -62,13 +55,13 @@ handleMouseWheelEvent mwev = scrollAmount +~ fromIntegral y
|
||||
V2 _ y = mouseWheelEventPos mwev
|
||||
|
||||
handleMouseButtonEvent :: MouseButtonEventData -> Input -> Input
|
||||
handleMouseButtonEvent mbev theinput = case mouseButtonEventMotion mbev of
|
||||
Released -> theinput & mouseButtons . at thebutton .~ Nothing
|
||||
& mouseButtonsReleased . at thebutton ?~ 0
|
||||
Pressed -> theinput
|
||||
& mouseButtons . at thebutton ?~ 0
|
||||
& mouseButtonsReleased . at thebutton .~ Nothing
|
||||
& clickPos . at thebutton ?~ (theinput ^. mousePos)
|
||||
handleMouseButtonEvent mbev inp = case mouseButtonEventMotion mbev of
|
||||
Released -> inp & mouseButtons . at but .~ Nothing
|
||||
& mouseButtonsReleased . at but ?~ 0
|
||||
Pressed -> inp
|
||||
& mouseButtons . at but ?~ 0
|
||||
& mouseButtonsReleased . at but .~ Nothing
|
||||
& clickPos . at but ?~ (inp ^. mousePos)
|
||||
-- note that mouse button down events are NOT repeating
|
||||
where
|
||||
thebutton = mouseButtonEventButton mbev
|
||||
but = mouseButtonEventButton mbev
|
||||
|
||||
+8
-4
@@ -465,15 +465,19 @@ updatePulseLasers w = f w & cWorld . lWorld . pulseLasers .~ pzs
|
||||
updatePulseBall :: PulseBall -> World -> World
|
||||
updatePulseBall pb w
|
||||
| Just (_, ecrwl) <- thit =
|
||||
w & cWorld . lWorld . pulseBalls . at (pb ^. pbID) .~ Nothing
|
||||
w & cWorld . lWorld . pulseBalls . at (pb ^. pbID) .~ Nothing
|
||||
& cWorld . lWorld %~ dodam ecrwl
|
||||
| pb ^. pbTimer <= 0 =
|
||||
w & cWorld . lWorld . pulseBalls . at (pb ^. pbID) .~ Nothing
|
||||
w & cWorld . lWorld . pulseBalls . at (pb ^. pbID) .~ Nothing
|
||||
| otherwise =
|
||||
w
|
||||
& cWorld . lWorld . pulseBalls . ix (pb ^. pbID) . pbTimer -~ 1
|
||||
w & cWorld . lWorld . pulseBalls . ix (pb ^. pbID) . pbTimer -~ 1
|
||||
& cWorld . lWorld . pulseBalls . ix (pb ^. pbID) . pbPos .~ ep
|
||||
& pbFlicker pb
|
||||
where
|
||||
dodam = \case
|
||||
Left cr -> creatures . ix (_crID cr) . crDamage .:~ thedam
|
||||
Right wl -> wallDamages . at (_wlID wl) . non mempty .:~ thedam
|
||||
thedam = Lasering 100 ep (pb ^. pbVel)
|
||||
sp = pb ^. pbPos
|
||||
ep = sp + pb ^. pbVel
|
||||
thit = thingHit sp ep w
|
||||
|
||||
Reference in New Issue
Block a user