wizard-wipeout/src-client/Client/Game.hs
2024-01-23 11:13:52 +01:00

44 lines
856 B
Haskell

module Client.Game where
import Control.Concurrent
import qualified Control.Concurrent.STM as STM
import Control.Monad
import Control.Monad.Loops
import Control.Monad.RWS
import Graphics.Vty
-- internal imports
import Client.Communication
import Client.Graphics
import Client.Types
import Library.Types
runGame :: Game ()
runGame = do
sock <- asks rcSocket
queue <- asks rcQueue
clientId <- asks rcClientUUID
recvThread <- liftIO $ forkIO $ forever $ receiveMessage sock queue
liftIO $ sendMessage (ClientMessage clientId ClientReady) sock
whileM_
(not . clientStop <$> (liftIO . STM.atomically . STM.readTMVar =<< gets scClientState))
(do
handleMessages
-- draw
)
liftIO $ killThread recvThread
handleEvent
:: Maybe Event
-> Game ()
handleEvent Nothing =
pure ()
handleEvent (Just event) =
pure ()