From ffc274d310b14eb663d018a00a64b78ba45d0fc5 Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Wed, 8 Feb 2023 07:16:43 +0000 Subject: Use NoFieldSelectors --- src/Game.hs | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) (limited to 'src/Game.hs') diff --git a/src/Game.hs b/src/Game.hs index 48a8e21..463ef27 100644 --- a/src/Game.hs +++ b/src/Game.hs @@ -31,15 +31,15 @@ version :: String version = "0.1.0" data Env = Env - { _window :: SDL.Window, - _renderer :: SDL.Renderer, - _canvas :: SDL.Texture, - _fullscreen :: IORef Bool, - _renderRect :: IORef (SDL.Rectangle CInt), - _controls :: IORef C.Controls, - _map :: M.Map, - _sprites :: S.SpriteSheet, - _entities :: IORef E.Entities + { window :: SDL.Window, + renderer :: SDL.Renderer, + canvas :: SDL.Texture, + fullscreen :: IORef Bool, + renderRect :: IORef (SDL.Rectangle CInt), + controls :: IORef C.Controls, + map :: M.Map, + sprites :: S.SpriteSheet, + entities :: IORef E.Entities } defaultRenderRect :: SDL.Rectangle CInt @@ -72,17 +72,29 @@ main = do entities <- newIORef $ E.mkEntities sprites player <- E.mkPlayer sprites 32 104 controls (M.isBlocked map') entities $~ E.append player - runReaderT gameLoop (Env window renderer canvas fullscreen renderRect controls map' sprites entities) + runReaderT + gameLoop + Env + { window = window, + renderer = renderer, + canvas = canvas, + fullscreen = fullscreen, + renderRect = renderRect, + controls = controls, + map = map', + sprites = sprites, + entities = entities + } SDL.destroyWindow window SDL.quit toggleFullscreen :: ReaderT Env IO () toggleFullscreen = do env <- ask - let fullscreen = env._fullscreen - renderRect = env._renderRect - renderer = env._renderer - window = env._window + let fullscreen = env.fullscreen + renderRect = env.renderRect + renderer = env.renderer + window = env.window fullscreen $~ not fs <- SDL.get fullscreen let mode = if fs then SDL.FullscreenDesktop else SDL.Windowed @@ -104,12 +116,12 @@ toggleFullscreen = do gameLoop :: ReaderT Env IO () gameLoop = do env <- ask - let renderer = env._renderer - canvas = env._canvas - renderRect = env._renderRect - controls = env._controls - map' = env._map - entities = env._entities + let renderer = env.renderer + canvas = env.canvas + renderRect = env.renderRect + controls = env.controls + map' = env.map + entities = env.entities events <- map SDL.eventPayload <$> SDL.pollEvents -- cgit v1.2.3