Skip to content

Commit

Permalink
preserve NoMenu on scenario quit
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed Jan 9, 2025
1 parent 1dbf414 commit 9998458
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
19 changes: 14 additions & 5 deletions src/swarm-tui/Swarm/TUI/Controller/SaveScenario.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 .=)
4 changes: 1 addition & 3 deletions src/swarm-tui/Swarm/TUI/Model/UI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9998458

Please sign in to comment.