{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DeriveGeneric #-}
module Terminal.Game.Layer.Object.Interface where
import Terminal.Game.Plane
import qualified Control.Concurrent as CC
import qualified Data.Serialize as S
import qualified GHC.Generics as G
import qualified Test.QuickCheck as Q
type MonadGameIO m = (MonadInput m, MonadTimer m,
MonadException m, MonadLogic m,
MonadDisplay m)
type FPS = Integer
data Event = Tick
| KeyPress Char
deriving (Show, Eq, G.Generic)
instance S.Serialize Event where
instance Q.Arbitrary Event where
arbitrary = Q.oneof [ pure Tick,
KeyPress <$> Q.arbitrary ]
data InputHandle = InputHandle
{ ihKeyMVar :: CC.MVar [Event],
ihOpenThreds :: [CC.ThreadId] }
class Monad m => MonadInput m where
startEvents :: FPS -> m InputHandle
pollEvents :: CC.MVar [Event] -> m [Event]
stopEvents :: [CC.ThreadId] -> m ()
class Monad m => MonadTimer m where
getTime :: m Integer
sleepABit :: FPS -> m ()
class Monad m => MonadException m where
cleanUpErr :: m a -> m b -> m a
class Monad m => MonadLogic m where
checkQuit :: (s -> Bool) -> s -> m Bool
class Monad m => MonadDisplay m where
setupDisplay :: m ()
clearDisplay :: m ()
displaySize :: m (Integer, Integer)
blitPlane :: Width -> Height -> Maybe Plane -> Plane -> m ()
shutdownDisplay :: m ()