about summary refs log tree commit diff
path: root/src/Xanthous/App.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/App.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/App.hs')
-rw-r--r--src/Xanthous/App.hs29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/Xanthous/App.hs b/src/Xanthous/App.hs
index b8cda3b777..df76eadc3b 100644
--- a/src/Xanthous/App.hs
+++ b/src/Xanthous/App.hs
@@ -44,7 +44,8 @@ import           Xanthous.Entities.Item (Item)
 import qualified Xanthous.Entities.Item as Item
 import           Xanthous.Entities.Creature (Creature)
 import qualified Xanthous.Entities.Creature as Creature
-import           Xanthous.Entities.Environment (Door, open, locked)
+import           Xanthous.Entities.Environment
+                 (Door, open, locked, GroundMessage(..))
 import           Xanthous.Entities.RawTypes (edible, eatMessage, hitpointsHealed)
 import           Xanthous.Generators
 import qualified Xanthous.Generators.CaveAutomata as CaveAutomata
@@ -84,6 +85,7 @@ initLevel = do
   entities <>= (SomeEntity <$> level ^. levelWalls)
   entities <>= (SomeEntity <$> level ^. levelItems)
   entities <>= (SomeEntity <$> level ^. levelCreatures)
+  entities <>= (SomeEntity <$> level ^. levelTutorialMessage)
 
   characterPosition .= level ^. levelCharacterPosition
 
@@ -206,6 +208,29 @@ handleCommand Eat = do
   stepGame -- TODO
   continue
 
+handleCommand Read = do
+  -- TODO allow reading things in the inventory (combo direction+menu prompt?)
+  prompt_ @'DirectionPrompt ["read", "prompt"] Cancellable
+    $ \(DirectionResult dir) -> do
+      pos <- uses characterPosition $ move dir
+      uses entities
+        (fmap snd . entitiesAtPositionWithType @GroundMessage pos) >>= \case
+          Empty -> say_ ["read", "nothing"]
+          GroundMessage msg :< Empty ->
+            say ["read", "result"] $ object ["message" A..= msg]
+          msgs ->
+            let readAndContinue Empty = pure ()
+                readAndContinue (msg :< msgs') =
+                  prompt @'Continue
+                    ["read", "result"]
+                    (object ["message" A..= msg])
+                    Cancellable
+                  . const
+                  $ readAndContinue msgs'
+                readAndContinue _ = error "this is total"
+            in readAndContinue msgs
+  continue
+
 handleCommand Save = do
   -- TODO default save locations / config file?
   prompt_ @'StringPrompt ["save", "location"] Cancellable
@@ -413,3 +438,5 @@ entityMenu_ = mkMenuItems @[_] . map entityMenuItem
 
 -- entityMenu :: Entity entity => [entity] -> Map Char (MenuOption entity)
 -- entityMenu = map (map runIdentity) . entityMenu_ . fmap Identity
+
+--------------------------------------------------------------------------------