From 54531b80105742da17a7ffd70e3c650bcebaf85e Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Thu, 9 Jan 2025 11:17:34 -0600 Subject: [PATCH] Warn the user when debugging options are on (#2278) Closes #1270. When any debugging options are enabled, pop up a warning that progress will not be saved. Note, in #1270, we discussed the possibility of saving progress even if `--debug=creative` is on, as long as creative mode is never actually engaged, but I'm not sure it's really worth going to that length. The warning should be enough. --- src/swarm-tui/Swarm/TUI/Model/Dialog/Popup.hs | 1 + src/swarm-tui/Swarm/TUI/Model/StateUpdate.hs | 8 +++++++- src/swarm-tui/Swarm/TUI/View/Popup.hs | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/swarm-tui/Swarm/TUI/Model/Dialog/Popup.hs b/src/swarm-tui/Swarm/TUI/Model/Dialog/Popup.hs index 15ee84d52..ae7e5df66 100644 --- a/src/swarm-tui/Swarm/TUI/Model/Dialog/Popup.hs +++ b/src/swarm-tui/Swarm/TUI/Model/Dialog/Popup.hs @@ -32,6 +32,7 @@ data Popup = AchievementPopup CategorizedAchievement | RecipesPopup | CommandsPopup [Const] + | DebugWarningPopup -- | State to track pending popup queue as well as any -- popup which is currently being displayed. diff --git a/src/swarm-tui/Swarm/TUI/Model/StateUpdate.hs b/src/swarm-tui/Swarm/TUI/Model/StateUpdate.hs index 3dc74ec53..6f4e111ef 100644 --- a/src/swarm-tui/Swarm/TUI/Model/StateUpdate.hs +++ b/src/swarm-tui/Swarm/TUI/Model/StateUpdate.hs @@ -28,7 +28,7 @@ import Control.Effect.Accum import Control.Effect.Lift import Control.Effect.Throw import Control.Lens hiding (from, (<.>)) -import Control.Monad (guard, void) +import Control.Monad (guard, unless, void) import Control.Monad.Except (ExceptT (..)) import Control.Monad.IO.Class (MonadIO (liftIO)) import Control.Monad.State (MonadState, execStateT) @@ -217,6 +217,12 @@ startGameWithSeed siPair@(_scene, si) lp = do -- Beware: currentScenarioPath must be set so that progress/achievements can be saved. -- It has just been cleared in scenarioToAppState. gameState . currentScenarioPath .= Just p + + -- Warn the user that the use of debugging options means progress + -- will not be saved. + debugging <- use $ uiState . uiDebugOptions + unless (null debugging) $ + uiState . uiPopups %= addPopup DebugWarningPopup where prevBest t = case si ^. scenarioStatus of NotStarted -> emptyBest t diff --git a/src/swarm-tui/Swarm/TUI/View/Popup.hs b/src/swarm-tui/Swarm/TUI/View/Popup.hs index dfd1c8e71..a55784b4a 100644 --- a/src/swarm-tui/Swarm/TUI/View/Popup.hs +++ b/src/swarm-tui/Swarm/TUI/View/Popup.hs @@ -56,6 +56,11 @@ drawPopup s = \case ] , txt $ "Hit " <> bindingText s (SE.Main SE.ViewCommandsEvent) <> " to view all available commands." ] + DebugWarningPopup -> + hBox + [ withAttr notifAttr (txt "Warning: ") + , txt "No progress will be saved, since debugging flags are in use." + ] -- | Compute the number of rows of the notification popup we should be -- showing, based on the number of frames the popup has existed.