2020-09-23 23:26:47 +00:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2020-08-30 15:36:32 +00:00
|
|
|
module Main where
|
|
|
|
|
2020-09-23 23:26:47 +00:00
|
|
|
import Affection
|
|
|
|
|
|
|
|
import qualified Data.Text as T
|
|
|
|
|
|
|
|
import qualified SDL
|
|
|
|
|
|
|
|
import Control.Concurrent.STM
|
|
|
|
|
|
|
|
import qualified Data.Map.Strict as M
|
|
|
|
|
|
|
|
import Linear
|
|
|
|
|
|
|
|
-- internal imports
|
|
|
|
|
2020-10-16 23:53:25 +00:00
|
|
|
import StateMachine
|
2020-09-23 23:26:47 +00:00
|
|
|
import Types
|
|
|
|
|
|
|
|
instance Affectionate GameData where
|
2020-10-17 08:35:25 +00:00
|
|
|
preLoop = preLoad
|
2020-10-16 23:53:25 +00:00
|
|
|
handleEvents = handle
|
|
|
|
update = Main.update
|
|
|
|
draw = Main.draw
|
2020-09-23 23:26:47 +00:00
|
|
|
loadState = Main.init
|
|
|
|
cleanUp _ = return ()
|
|
|
|
hasNextStep = liftIO . atomically . readTVar . gameRunning
|
|
|
|
|
2020-08-30 15:36:32 +00:00
|
|
|
main :: IO ()
|
2020-09-23 23:26:47 +00:00
|
|
|
main = do
|
|
|
|
let config = AffectionConfig
|
|
|
|
{ initComponents = All
|
|
|
|
, windowTitle = "Pituicat"
|
|
|
|
, windowConfigs =
|
|
|
|
[ ( 0
|
|
|
|
, SDL.defaultWindow
|
|
|
|
{ SDL.windowInitialSize = V2 800 600
|
|
|
|
, SDL.windowResizable = True
|
|
|
|
, SDL.windowGraphicsContext = SDL.OpenGLContext SDL.defaultOpenGL
|
|
|
|
{ SDL.glProfile = SDL.Core SDL.Normal 3 3
|
|
|
|
}
|
|
|
|
}
|
|
|
|
, SDL.Windowed
|
|
|
|
)
|
|
|
|
]
|
|
|
|
} :: AffectionConfig GameData
|
|
|
|
withAffection config
|
|
|
|
|
2020-10-17 08:35:25 +00:00
|
|
|
preLoad :: GameData -> Affection ()
|
|
|
|
preLoad gd = do
|
|
|
|
liftIO $ atomically $ writeTVar (gameState gd) Loading
|
|
|
|
|
|
|
|
|
2020-10-16 23:53:25 +00:00
|
|
|
handle :: GameData -> [SDL.EventPayload] -> Affection ()
|
|
|
|
handle gd evs = do
|
|
|
|
state <- liftIO (atomically $ readTVar $ gameState gd)
|
|
|
|
smEvent state gd evs
|
|
|
|
|
|
|
|
update :: GameData -> Double -> Affection ()
|
|
|
|
update gd dt = do
|
|
|
|
state <- liftIO (atomically $ readTVar $ gameState gd)
|
2020-10-17 08:35:25 +00:00
|
|
|
progressMeter <- liftIO $ atomically (fst <$> readTMVar (gameStateLoadProgress gd))
|
|
|
|
if progressMeter < 0
|
|
|
|
then do
|
|
|
|
-- liftIO (atomically (putTMVar (gameStateLoadProgress gd) (0, "Ohai!")))
|
|
|
|
smLoad state gd
|
|
|
|
else
|
|
|
|
smUpdate state gd dt
|
2020-10-16 23:53:25 +00:00
|
|
|
|
|
|
|
draw :: GameData -> Affection ()
|
|
|
|
draw gd = do
|
|
|
|
state <- liftIO (atomically $ readTVar $ gameState gd)
|
|
|
|
smDraw state gd
|
|
|
|
|
2020-09-23 23:26:47 +00:00
|
|
|
init :: IO GameData
|
|
|
|
init = GameData
|
|
|
|
<$> newTVarIO Loading
|
2020-10-17 08:35:25 +00:00
|
|
|
<*> newTMVarIO (-1, "Ohai!")
|
|
|
|
<*> newTMVarIO EmptyData
|
2020-09-23 23:26:47 +00:00
|
|
|
<*> (Subsystems
|
|
|
|
<$> (SubWindow <$> newTVarIO [])
|
|
|
|
<*> (SubMouse <$> newTVarIO [])
|
|
|
|
<*> (SubKeyboard <$> newTVarIO [])
|
|
|
|
<*> (SubTranslator <$> newTVarIO [])
|
|
|
|
)
|
|
|
|
<*> newTVarIO (M.fromList [])
|
|
|
|
<*> newTVarIO True
|