about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2019-12-23T23·10-0500
committerGriffin Smith <root@gws.fyi>2019-12-23T23·20-0500
commit13516911366a484ee5484166520133e056010515 (patch)
treed7618f2062ad93a3800b0b4e20b45e22ad88faa6
parent32421916e09dc56d91707af10474644276712fc5 (diff)
Don't send the welcome message when loading
Don't re-send the welcome message when loading the game if it's already
been sent. This is done by just tracking whether or not we've sent it as
a boolean in the game state, which may be a bit of a hack but should be fine
-rw-r--r--src/Xanthous/App.hs8
-rw-r--r--src/Xanthous/Game/Arbitrary.hs1
-rw-r--r--src/Xanthous/Game/Lenses.hs1
-rw-r--r--src/Xanthous/Game/State.hs4
4 files changed, 12 insertions, 2 deletions
diff --git a/src/Xanthous/App.hs b/src/Xanthous/App.hs
index 2029be6f108f..2bdf6142f9fd 100644
--- a/src/Xanthous/App.hs
+++ b/src/Xanthous/App.hs
@@ -77,8 +77,12 @@ startEvent = do
     Nothing -> prompt_ @'StringPrompt ["character", "namePrompt"] Uncancellable
       $ \(StringResult s) -> do
         character . characterName ?= s
-        say ["welcome"] =<< use character
-    Just n -> say ["welcome"] $ object [ "characterName" A..= n ]
+        whenM (uses sentWelcome not) $ say ["welcome"] =<< use character
+        sentWelcome .= True
+    Just n ->
+      whenM (uses sentWelcome not) $ do
+        say ["welcome"] $ object [ "characterName" A..= n ]
+        sentWelcome .= True
 
 initLevel :: AppM ()
 initLevel = do
diff --git a/src/Xanthous/Game/Arbitrary.hs b/src/Xanthous/Game/Arbitrary.hs
index f4c83e005146..a4e0255ca8c2 100644
--- a/src/Xanthous/Game/Arbitrary.hs
+++ b/src/Xanthous/Game/Arbitrary.hs
@@ -28,6 +28,7 @@ instance Arbitrary GameState where
     let _promptState = NoPrompt -- TODO
     _activePanel <- arbitrary
     _debugState <- arbitrary
+    _sentWelcome <- arbitrary
     pure $ GameState {..}
 
 
diff --git a/src/Xanthous/Game/Lenses.hs b/src/Xanthous/Game/Lenses.hs
index 1f72e08b7b25..853f758385b1 100644
--- a/src/Xanthous/Game/Lenses.hs
+++ b/src/Xanthous/Game/Lenses.hs
@@ -50,6 +50,7 @@ initialStateFromSeed seed =
       _debugState = DebugState
         { _allRevealed = False
         }
+      _sentWelcome = False
   in GameState {..}
 
 
diff --git a/src/Xanthous/Game/State.hs b/src/Xanthous/Game/State.hs
index d8a0f0b32077..0ba7b2744a80 100644
--- a/src/Xanthous/Game/State.hs
+++ b/src/Xanthous/Game/State.hs
@@ -11,6 +11,7 @@ module Xanthous.Game.State
   , messageHistory
   , randomGen
   , activePanel
+  , sentWelcome
   , promptState
   , characterEntityID
   , GamePromptState(..)
@@ -405,6 +406,7 @@ data GameState = GameState
   , _characterEntityID :: !EntityID
   , _messageHistory    :: !MessageHistory
   , _randomGen         :: !StdGen
+  , _sentWelcome       :: Bool
 
     -- | The active panel displayed in the UI, if any
   , _activePanel       :: !(Maybe Panel)
@@ -425,6 +427,8 @@ instance Eq GameState where
     , gs ^. revealedPositions
     , gs ^. characterEntityID
     , gs ^. messageHistory
+    , gs ^. sentWelcome
+    , gs ^. activePanel
     )
 
 --------------------------------------------------------------------------------