40 lines
963 B
Haskell
40 lines
963 B
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
module State.MainGame.Load where
|
|
|
|
import Affection
|
|
|
|
import Control.Concurrent (forkIO)
|
|
import Control.Concurrent.STM
|
|
|
|
import Control.Monad (void)
|
|
|
|
-- internal imports
|
|
|
|
import Types
|
|
import Map
|
|
|
|
mainGameLoad
|
|
:: GameData
|
|
-> Affection ()
|
|
mainGameLoad gd = do
|
|
liftIO $ atomically $ do
|
|
_ <- takeTMVar (gameStateLoadProgress gd)
|
|
putTMVar (gameStateLoadProgress gd) (0, "Ohai!")
|
|
liftIO $ logIO Verbose "Entering main Game"
|
|
liftIO $ void $ forkIO $ loadFork (gameStateData gd) (gameStateLoadProgress gd)
|
|
|
|
loadFork
|
|
:: TMVar StateData
|
|
-> TMVar Progress
|
|
-> IO ()
|
|
loadFork dataContainer progress = do
|
|
atomically $ do
|
|
_ <- takeTMVar progress
|
|
putTMVar progress (0, "Loading test level...")
|
|
testData <- TestData <$> constructMap testLevelDesc 0
|
|
atomically $ do
|
|
_ <- takeTMVar dataContainer
|
|
putTMVar dataContainer testData
|
|
_ <- takeTMVar progress
|
|
putTMVar progress (1, "Loaded test level!")
|