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
This commit is contained in:
parent
2fd3e4c9ad
commit
adb3b74c0c
9 changed files with 155 additions and 39 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue