module Game.LambdaHack.Client.UI.StartupFrontendClient
( srtFrontend
) where
import Control.Concurrent.Async
import qualified Control.Concurrent.STM as STM
import Control.Exception.Assert.Sugar
import Game.LambdaHack.Client.State
import Game.LambdaHack.Client.UI.Config
import Game.LambdaHack.Client.UI.Content.KeyKind
import Game.LambdaHack.Client.UI.Frontend
import Game.LambdaHack.Client.UI.KeyBindings
import Game.LambdaHack.Client.UI.MonadClientUI
import Game.LambdaHack.Common.ClientOptions
import Game.LambdaHack.Common.Faction
import qualified Game.LambdaHack.Common.Kind as Kind
import Game.LambdaHack.Common.Msg
import Game.LambdaHack.Common.State
srtFrontend :: (DebugModeCli -> SessionUI -> State -> StateClient
-> chanServerUI
-> IO ())
-> (DebugModeCli -> SessionUI -> State -> StateClient
-> chanServerAI
-> IO ())
-> KeyKind -> Kind.COps -> DebugModeCli
-> ((FactionId -> chanServerUI -> IO ())
-> (FactionId -> chanServerAI -> IO ())
-> IO ())
-> IO ()
srtFrontend executorUI executorAI
copsClient cops sdebugCli exeServer = do
sconfig <- mkConfig cops
let !sbinding = stdBinding copsClient sconfig
sdebugMode = applyConfigToDebug sconfig sdebugCli cops
defaultHist <- defaultHistory
let cli = defStateClient defaultHist emptyReport
s = updateCOps (const cops) emptyState
exeClientAI fid =
let noSession = assert `failure` "AI client needs no UI session"
`twith` fid
in executorAI sdebugMode noSession s (cli fid True)
exeClientUI sescMVar loopFrontend fid chanServerUI = do
responseF <- STM.newTQueueIO
requestF <- STM.newTQueueIO
let schanF = ChanFrontend{..}
a <- async $ loopFrontend schanF
link a
executorUI sdebugMode SessionUI{..} s (cli fid False) chanServerUI
STM.atomically $ STM.writeTQueue requestF FrontFinish
wait a
startupF sdebugMode $ \sescMVar loopFrontend ->
exeServer (exeClientUI sescMVar loopFrontend) exeClientAI