store all the messages from the game and print them at the end.

This commit is contained in:
Jesse D. McDonald 2014-07-26 17:00:53 -05:00
parent 7f7e39213e
commit 4331512a3e
1 changed files with 4 additions and 2 deletions

View File

@ -95,7 +95,7 @@ drawState :: IORef DisplayState -> IO ()
drawState ref = do
ds <- readIORef ref
printWaterdeep (ds ^. gameState)
forM_ (ds ^. gameMessages) putStrLn
mapM_ putStrLn $ take 4 $ ds ^. gameMessages
unless (null (ds ^. gameMessages)) $ putStrLn ""
menuPrompt :: IORef DisplayState -> IO () -> WaterdeepPrompt a -> IO a
@ -103,7 +103,7 @@ menuPrompt ref redraw (NotifyState w) = do
modifyIORef ref (gameState .~ w)
redraw
menuPrompt ref redraw (Broadcast s) = do
modifyIORef ref (gameMessages %~ ((s:) . take 4))
modifyIORef ref (gameMessages %~ (s:))
redraw
menuPrompt ref redraw prm@(SolicitChoice p t cs) = do
let menuSize = length cs
@ -149,4 +149,6 @@ main = do
let w0 = newGame players defaultQuestDeck defaultIntrigueDeck defaultBuildingDeck rndgen
ref <- newIORef (DisplayState { _gameState = w0, _gameMessages = [] })
runWaterdeepM (menuPrompt ref (drawState ref)) waterdeepGame w0
putStrLn "--- GAME LOG ---"
mapM_ putStrLn . reverse . view gameMessages =<< readIORef ref
return ()