diff options
author | Griffin Smith <root@gws.fyi> | 2019-09-01T20·21-0400 |
---|---|---|
committer | Griffin Smith <root@gws.fyi> | 2019-09-02T14·52-0400 |
commit | adb3b74c0c3a3bffa0d47f52036fde3623f859f7 (patch) | |
tree | 3a2e416ea31f92562ba6eabf0fc4ddf2974b24b7 /src/Xanthous/Game/Draw.hs | |
parent | 2fd3e4c9ad28b77a0d167ceefe879ca80ee1ee04 (diff) |
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
Diffstat (limited to 'src/Xanthous/Game/Draw.hs')
-rw-r--r-- | src/Xanthous/Game/Draw.hs | 18 |
1 files changed, 14 insertions, 4 deletions
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) |