about summary refs log tree commit diff
path: root/src/Xanthous/App.hs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2020-02-17T18·24-0500
committerGriffin Smith <root@gws.fyi>2020-02-17T18·24-0500
commit1265155ae43f59c6bbd4b25f2747515cdf416622 (patch)
treed69e2638c49383308bfdd8641f0562365ab71ed2 /src/Xanthous/App.hs
parent69ccf3a77de7b11ea1c8c11d96ae14595b204589 (diff)
Don't run initEvent when loading the game
Rather than having a single sentWelcome boolean, avoid running the
initEvent entirely when loading an already-initialized game. Among other
things, this stops us from re-generating a level and then merging it
with the existing one when the game is loaded (oops).
Diffstat (limited to 'src/Xanthous/App.hs')
-rw-r--r--src/Xanthous/App.hs24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/Xanthous/App.hs b/src/Xanthous/App.hs
index ab7c8f8e50..24073c5109 100644
--- a/src/Xanthous/App.hs
+++ b/src/Xanthous/App.hs
@@ -2,7 +2,10 @@
 {-# LANGUAGE UndecidableInstances #-}
 {-# LANGUAGE RecordWildCards      #-}
 --------------------------------------------------------------------------------
-module Xanthous.App (makeApp) where
+module Xanthous.App
+  ( makeApp
+  , RunType(..)
+  ) where
 --------------------------------------------------------------------------------
 import           Xanthous.Prelude
 import           Brick hiding (App, halt, continue, raw)
@@ -66,12 +69,17 @@ import qualified Xanthous.Generators.Dungeon as Dungeon
 
 type App = Brick.App GameState () Name
 
-makeApp :: IO App
-makeApp = pure $ Brick.App
+data RunType = NewGame | LoadGame
+  deriving stock (Eq)
+
+makeApp :: RunType -> IO App
+makeApp rt = pure $ Brick.App
   { appDraw = drawGame
   , appChooseCursor = const headMay
   , appHandleEvent = \game event -> runAppM (handleEvent event) game
-  , appStartEvent = runAppM $ startEvent >> get
+  , appStartEvent = case rt of
+      NewGame -> runAppM $ startEvent >> get
+      LoadGame -> pure
   , appAttrMap = const $ attrMap defAttr []
   }
 
@@ -86,12 +94,8 @@ startEvent = do
     Nothing -> prompt_ @'StringPrompt ["character", "namePrompt"] Uncancellable
       $ \(StringResult s) -> do
         character . characterName ?= s
-        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
+        say ["welcome"] =<< use character
+    Just n -> say ["welcome"] $ object [ "characterName" A..= n ]
 
 initLevel :: AppM ()
 initLevel = do