From adb3b74c0c3a3bffa0d47f52036fde3623f859f7 Mon Sep 17 00:00:00 2001 From: Griffin Smith Date: Sun, 1 Sep 2019 16:21:45 -0400 Subject: Link up messages to the overall game Add a "say" function for saying messages within an app monad to the user, and link everything up to display them and track their history --- src/Xanthous/Game/Draw.hs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/Xanthous/Game/Draw.hs') diff --git a/src/Xanthous/Game/Draw.hs b/src/Xanthous/Game/Draw.hs index 79089029ea8d..5a2f773c1b18 100644 --- a/src/Xanthous/Game/Draw.hs +++ b/src/Xanthous/Game/Draw.hs @@ -8,15 +8,25 @@ import Xanthous.Prelude import Brick hiding (loc) import Brick.Widgets.Border import Brick.Widgets.Border.Style +import Data.List.NonEmpty(NonEmpty((:|))) import Xanthous.Data (Position(Position), x, y, loc) import Xanthous.Data.EntityMap import Xanthous.Entities -import Xanthous.Game (GameState(..), entities, characterPosition) +import Xanthous.Game + ( GameState(..) + , entities + , characterPosition + , MessageHistory(..) + , messageHistory + ) import Xanthous.Resource (Name(..)) +import Xanthous.Orphans () -drawMessages :: GameState -> Widget Name -drawMessages _ = str "Welcome to Xanthous! It's dangerous out there, why not stay inside?" +drawMessages :: MessageHistory -> Widget Name +drawMessages NoMessageHistory = emptyWidget +drawMessages (MessageHistory _ False) = emptyWidget +drawMessages (MessageHistory (lastMessage :| _) True) = str $ unpack lastMessage drawEntities :: (Draw a, Show a) => EntityMap a -> Widget Name drawEntities em@(fromNullable . positions -> Just entityPositions) @@ -41,5 +51,5 @@ drawGame :: GameState -> [Widget Name] drawGame game = pure . withBorderStyle unicode - $ drawMessages game + $ drawMessages (game ^. messageHistory) <=> border (drawMap game) -- cgit 1.4.1