2019-10-06 18:50:29 +02:00
|
|
|
--------------------------------------------------------------------------------
|
2019-09-01 22:21:45 +02:00
|
|
|
module Xanthous.Monad
|
|
|
|
( AppT(..)
|
2019-09-28 19:20:57 +02:00
|
|
|
, AppM
|
2019-09-01 22:21:45 +02:00
|
|
|
, runAppT
|
|
|
|
, continue
|
|
|
|
, halt
|
2019-10-06 18:50:29 +02:00
|
|
|
-- * Messages
|
2019-09-01 22:21:45 +02:00
|
|
|
, say
|
2019-09-10 02:54:33 +02:00
|
|
|
, say_
|
2019-10-06 18:50:29 +02:00
|
|
|
, message
|
|
|
|
, message_
|
2019-12-23 16:59:45 +01:00
|
|
|
, writeMessage
|
2019-09-01 22:21:45 +02:00
|
|
|
) where
|
2019-10-06 18:50:29 +02:00
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Xanthous.Prelude
|
|
|
|
import Control.Monad.Random
|
|
|
|
import Control.Monad.State
|
2019-09-01 22:21:45 +02:00
|
|
|
import qualified Brick
|
2019-10-06 18:50:29 +02:00
|
|
|
import Brick (EventM, Next)
|
|
|
|
import Data.Aeson
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
import Xanthous.Game.State
|
|
|
|
import Xanthous.Messages (Message)
|
|
|
|
import qualified Xanthous.Messages as Messages
|
|
|
|
--------------------------------------------------------------------------------
|
2019-09-01 22:21:45 +02:00
|
|
|
|
|
|
|
runAppT :: Monad m => AppT m a -> GameState -> m (a, GameState)
|
|
|
|
runAppT appt initialState = flip runStateT initialState . unAppT $ appt
|
|
|
|
|
|
|
|
halt :: AppT (EventM n) (Next GameState)
|
|
|
|
halt = lift . Brick.halt =<< get
|
|
|
|
|
|
|
|
continue :: AppT (EventM n) (Next GameState)
|
|
|
|
continue = lift . Brick.continue =<< get
|
|
|
|
|
2019-10-06 18:50:29 +02:00
|
|
|
--------------------------------------------------------------------------------
|
2019-09-01 22:21:45 +02:00
|
|
|
|
2019-09-20 18:03:30 +02:00
|
|
|
say :: (MonadRandom m, ToJSON params, MonadState GameState m)
|
|
|
|
=> [Text] -> params -> m ()
|
2019-12-23 16:59:45 +01:00
|
|
|
say msgPath = writeMessage <=< Messages.message msgPath
|
2019-09-10 02:54:33 +02:00
|
|
|
|
2019-09-20 18:03:30 +02:00
|
|
|
say_ :: (MonadRandom m, MonadState GameState m) => [Text] -> m ()
|
|
|
|
say_ msgPath = say msgPath $ object []
|
2019-10-06 18:50:29 +02:00
|
|
|
|
|
|
|
message :: (MonadRandom m, ToJSON params, MonadState GameState m)
|
|
|
|
=> Message -> params -> m ()
|
2019-12-23 16:59:45 +01:00
|
|
|
message msg = writeMessage <=< Messages.render msg
|
2019-10-06 18:50:29 +02:00
|
|
|
|
|
|
|
message_ :: (MonadRandom m, MonadState GameState m)
|
|
|
|
=> Message -> m ()
|
|
|
|
message_ msg = message msg $ object []
|
2019-12-23 16:59:45 +01:00
|
|
|
|
|
|
|
writeMessage :: MonadState GameState m => Text -> m ()
|
|
|
|
writeMessage m = messageHistory %= pushMessage m
|