From 9998458077f1ed5c90635d2875131ee8442717cb Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Thu, 9 Jan 2025 10:42:04 -0600 Subject: [PATCH] preserve `NoMenu` on scenario quit --- .../Swarm/TUI/Controller/SaveScenario.hs | 19 ++++++++++++++----- src/swarm-tui/Swarm/TUI/Model/UI.hs | 4 +--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/src/swarm-tui/Swarm/TUI/Controller/SaveScenario.hs b/src/swarm-tui/Swarm/TUI/Controller/SaveScenario.hs index e9ff1a28f..28c23a0a5 100644 --- a/src/swarm-tui/Swarm/TUI/Controller/SaveScenario.hs +++ b/src/swarm-tui/Swarm/TUI/Controller/SaveScenario.hs @@ -28,7 +28,6 @@ import Swarm.TUI.Model.Repl import Swarm.TUI.Model.UI import Swarm.TUI.Model.UI.Gameplay import System.FilePath (splitDirectories) -import Prelude hiding (Applicative (..)) getNormalizedCurrentScenarioPath :: (MonadIO m, MonadState AppState m) => m (Maybe FilePath) getNormalizedCurrentScenarioPath = @@ -117,7 +116,17 @@ saveScenarioInfoOnQuit = -- previous scenario ended (via quit vs. via win), it might be the same as -- currentScenarioPath or it might be different. curPath <- preuse $ uiState . uiMenu . _NewGameMenu . ix 0 . BL.listSelectedElementL . _SISingle . _2 . scenarioPath - -- Now rebuild the NewGameMenu so it gets the updated ScenarioInfo, - -- being sure to preserve the same focused scenario. - sc <- use $ runtimeState . scenarios - forM_ (mkNewGameMenu sc (fromMaybe p curPath)) (uiState . uiMenu .=) + + menu <- use $ uiState . uiMenu + case menu of + -- If the menu is NoMenu, it means we skipped showing the + -- menu at startup, so leave it alone; we simply want to + -- exit the entire app. + NoMenu -> pure () + + -- Otherwise, rebuild the NewGameMenu so it gets the updated + -- ScenarioInfo, being sure to preserve the same focused + -- scenario. + _ -> do + sc <- use $ runtimeState . scenarios + forM_ (mkNewGameMenu sc (fromMaybe p curPath)) (uiState . uiMenu .=) diff --git a/src/swarm-tui/Swarm/TUI/Model/UI.hs b/src/swarm-tui/Swarm/TUI/Model/UI.hs index bb3eb2742..a76d6ff06 100644 --- a/src/swarm-tui/Swarm/TUI/Model/UI.hs +++ b/src/swarm-tui/Swarm/TUI/Model/UI.hs @@ -127,9 +127,7 @@ data UIInitOptions = UIInitOptions -- | Initialize the UI state. This needs to be in the IO monad since -- it involves reading a REPL history file, getting the current --- time, and loading text files from the data directory. The @Bool@ --- parameter indicates whether we should start off by showing the --- main menu. +-- time, and loading text files from the data directory. initUIState :: ( Has (Accum (Seq SystemFailure)) sig m , Has (Lift IO) sig m