Add a previous message command

Add a "previous message" command, triggered via ctrl+p.

I attempted here to get the message area to still take up a row of space
post-hiding the message, but failed - should revisit that at some point
This commit is contained in:
Griffin Smith 2019-09-02 10:36:15 -04:00
parent adb3b74c0c
commit 18551cdf30
5 changed files with 31 additions and 6 deletions

View file

@ -14,6 +14,8 @@ module Xanthous.Game
, MessageHistory(..)
, pushMessage
, popMessage
, hideMessage
) where
import Data.List.NonEmpty ( NonEmpty((:|)))
@ -43,6 +45,16 @@ pushMessage :: Text -> MessageHistory -> MessageHistory
pushMessage msg NoMessageHistory = MessageHistory (msg :| []) True
pushMessage msg (MessageHistory msgs _) = MessageHistory (NonEmpty.cons msg msgs) True
popMessage :: MessageHistory -> MessageHistory
popMessage NoMessageHistory = NoMessageHistory
popMessage (MessageHistory msgs False) = MessageHistory msgs True
popMessage (MessageHistory msgs@(_ :| []) _) = MessageHistory msgs True
popMessage (MessageHistory (_ :| (msg : msgs)) True) = MessageHistory (msg :| msgs) True
hideMessage :: MessageHistory -> MessageHistory
hideMessage NoMessageHistory = NoMessageHistory
hideMessage (MessageHistory msgs _) = MessageHistory msgs False
data GameState = GameState
{ _entities :: EntityMap SomeEntity
, _characterEntityID :: EntityID