pituicat/src/Scenes/Test.hs

53 lines
1.1 KiB
Haskell
Raw Normal View History

2020-10-28 10:48:58 +00:00
{-# LANGUAGE OverloadedStrings #-}
module Scenes.Test where
import Affection
import Control.Concurrent.STM
import Control.Monad (void)
-- internal imports
import Types
import Map
import Classes.Scene
data Test = Test
{ testMap :: TMVar LevelMap
, testLoaded :: TVar Bool
}
instance Scene Test where
initScene = Test <$> newEmptyTMVarIO <*> newTVarIO False
loadScene level progress = do
atomically $ do
void $ takeTMVar progress
putTMVar progress (0, "Loading test level...")
loadedMap <- constructMap testLevelDesc 0
atomically $ putTMVar (testMap level) loadedMap
void $ atomically $ do
void $ takeTMVar progress
putTMVar progress (1, "Loaded test level!")
void $ atomically $ swapTVar (testLoaded level) True
return level
isSceneLoaded = liftIO . atomically . readTVar . testLoaded
update _ _ = return ()
onEvents _ _ = return ()
render _ = return ()
testLevelDesc :: LevelDescriptor
testLevelDesc = LevelDescriptor
[ (0, "res/maps/00_test/00_test.bmp")
]
0
"res/tiles/00_test/00_test.png"
(3, 3)