about summary refs log tree commit diff
path: root/src/Xanthous/Messages.hs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-12-01T00·55-0500
committerGriffin Smith <root@gws.fyi>2019-12-01T00·55-0500
commit71b628c604556bc2d829f12980db99c9a526ec84 (patch)
tree2bd0b27810139c2fcf19813c0cf3f31100d5008f /src/Xanthous/Messages.hs
parent4431d453f61e88383aba40c8db3c4afb3c828b2e (diff)
Add messages on the ground
Add support for a "GroundMessage" entity type, support for a Read
command to read them, and randomly place an initial, tone-setting
tutorial message on the ground near the character at the beginning of
the game.
Diffstat (limited to 'src/Xanthous/Messages.hs')
-rw-r--r--src/Xanthous/Messages.hs29
1 files changed, 18 insertions, 11 deletions
diff --git a/src/Xanthous/Messages.hs b/src/Xanthous/Messages.hs
index b0dc0e4ae9d2..2b1b3da1e8c1 100644
--- a/src/Xanthous/Messages.hs
+++ b/src/Xanthous/Messages.hs
@@ -11,23 +11,25 @@ module Xanthous.Messages
   , render
   , lookup
   , message
+  , message_
   ) where
 --------------------------------------------------------------------------------
 import Xanthous.Prelude hiding (lookup)
 --------------------------------------------------------------------------------
-import Control.Monad.Random.Class (MonadRandom)
-import Data.Aeson (FromJSON, ToJSON, toJSON)
-import Data.Aeson.Generic.DerivingVia
-import Data.FileEmbed
-import Data.List.NonEmpty
-import Test.QuickCheck hiding (choose)
-import Test.QuickCheck.Arbitrary.Generic
-import Test.QuickCheck.Instances.UnorderedContainers ()
-import Text.Mustache
+import           Control.Monad.Random.Class (MonadRandom)
+import           Data.Aeson (FromJSON, ToJSON, toJSON)
+import qualified Data.Aeson as JSON
+import           Data.Aeson.Generic.DerivingVia
+import           Data.FileEmbed
+import           Data.List.NonEmpty
+import           Test.QuickCheck hiding (choose)
+import           Test.QuickCheck.Arbitrary.Generic
+import           Test.QuickCheck.Instances.UnorderedContainers ()
+import           Text.Mustache
 import qualified Data.Yaml as Yaml
 --------------------------------------------------------------------------------
-import Xanthous.Random
-import Xanthous.Orphans ()
+import           Xanthous.Random
+import           Xanthous.Orphans ()
 --------------------------------------------------------------------------------
 
 data Message = Single Template | Choice (NonEmpty Template)
@@ -98,3 +100,8 @@ message :: (MonadRandom m, ToJSON params) => [Text] -> params -> m Text
 message path params = maybe notFound (`render` params) $ messages ^? ix path
   where
     notFound = pure "Message not found"
+
+message_ :: (MonadRandom m) => [Text] -> m Text
+message_ path = maybe notFound (`render` JSON.object []) $ messages ^? ix path
+  where
+    notFound = pure "Message not found"