From 10c0af12d646f4cb0c8793052f2173e1fcb518c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ondr=CC=8Cej=20S=CC=8Cebek?= Date: Sun, 8 Sep 2024 18:07:18 +0200 Subject: [PATCH] Renaming and fixups --- app/game/Main.hs | 2 +- src/swarm-engine/Swarm/Game/Step.hs | 10 ++++--- .../Swarm/TUI/Controller/UpdateUI.hs | 4 +-- src/swarm-tui/Swarm/TUI/Model.hs | 6 ++-- src/swarm-tui/Swarm/TUI/Model/StateUpdate.hs | 6 ++-- src/swarm-tui/Swarm/TUI/Model/UI.hs | 28 +++++++++++-------- 6 files changed, 33 insertions(+), 23 deletions(-) diff --git a/app/game/Main.hs b/app/game/Main.hs index 91ffbad8e..cde368d9c 100644 --- a/app/game/Main.hs +++ b/app/game/Main.hs @@ -67,7 +67,7 @@ cliParser = scriptToRun <- run pausedAtStart <- paused autoPlay <- autoplay - showGoal <- not <$> hideGoal + autoShowObjectives <- not <$> hideGoal speed <- speedFactor debugOptions <- debug cheatMode <- cheat diff --git a/src/swarm-engine/Swarm/Game/Step.hs b/src/swarm-engine/Swarm/Game/Step.hs index ab3855643..4636f010d 100644 --- a/src/swarm-engine/Swarm/Game/Step.hs +++ b/src/swarm-engine/Swarm/Game/Step.hs @@ -343,6 +343,7 @@ hypotheticalWinCheck em g ws oc = do queue <- messageInfo . announcementQueue Swarm.Util.<%= (>< Seq.fromList (map ObjectiveCompleted $ completionAnnouncementQueue finalAccumulator)) shouldPause <- use $ temporal . pauseOnCompletion + let willPause = newWinState /= Ongoing || (notNull queue && shouldPause == PauseOnAnyObjective) -- TODO: remove this debug ouput sendIO $ appendFile "log_win.txt" $ @@ -350,11 +351,12 @@ hypotheticalWinCheck em g ws oc = do " \t" [ show $ getTickNumber ts , if newWinState == Ongoing then "ongoing" else "won" - , if (notNull queue) then "queued" else "empty" - , show shouldPause <> "\n" - ] + , if notNull queue then "queued" else "empty" + , show shouldPause + , if willPause then "AutoPause" else "Running" + ] <> "\n" - when (newWinState /= Ongoing || (notNull queue && shouldPause == PauseOnAnyObjective)) $ + when willPause $ temporal . runStatus .= AutoPause mapM_ handleException $ exceptions finalAccumulator diff --git a/src/swarm-tui/Swarm/TUI/Controller/UpdateUI.hs b/src/swarm-tui/Swarm/TUI/Controller/UpdateUI.hs index 399cc9f23..4019ddae3 100644 --- a/src/swarm-tui/Swarm/TUI/Controller/UpdateUI.hs +++ b/src/swarm-tui/Swarm/TUI/Controller/UpdateUI.hs @@ -237,8 +237,8 @@ doGoalUpdates = do -- automatically popped up. gameState . messageInfo . announcementQueue .= mempty - hideObjectives <- use $ uiState . uiGameplay . uiHideObjectives - unless hideObjectives $ openModal GoalModal + showObjectives <- use $ uiState . uiGameplay . uiAutoShowObjectives + when showObjectives $ openModal GoalModal return goalWasUpdated where diff --git a/src/swarm-tui/Swarm/TUI/Model.hs b/src/swarm-tui/Swarm/TUI/Model.hs index 674af407f..ce15747a6 100644 --- a/src/swarm-tui/Swarm/TUI/Model.hs +++ b/src/swarm-tui/Swarm/TUI/Model.hs @@ -255,8 +255,8 @@ data AppOpts = AppOpts -- ^ Pause the game on start by default. , autoPlay :: Bool -- ^ Automatically run the solution defined in the scenario file - , showGoal :: Bool - -- ^ Show goal dialogs. + , autoShowObjectives :: Bool + -- ^ Show objectives dialogs when an objective is achieved/failed. , speed :: Int -- ^ Initial game speed (logarithm) , debugOptions :: Set DebugOption @@ -277,7 +277,7 @@ defaultAppOpts = , userScenario = Nothing , scriptToRun = Nothing , pausedAtStart = False - , showGoal = True + , autoShowObjectives = True , autoPlay = False , speed = defaultInitLgTicksPerSecond , debugOptions = mempty diff --git a/src/swarm-tui/Swarm/TUI/Model/StateUpdate.hs b/src/swarm-tui/Swarm/TUI/Model/StateUpdate.hs index f1e4fb3fe..9fb654625 100644 --- a/src/swarm-tui/Swarm/TUI/Model/StateUpdate.hs +++ b/src/swarm-tui/Swarm/TUI/Model/StateUpdate.hs @@ -131,10 +131,12 @@ initPersistentState opts@(AppOpts {..}) = do initRuntimeState RuntimeOptions { startPaused = pausedAtStart - , pauseOnObjectiveCompletion = showGoal + , pauseOnObjectiveCompletion = autoShowObjectives , loadTestScenarios = Set.member LoadTestingScenarios debugOptions } - ui <- initUIState speed (not (skipMenu opts)) debugOptions + let showMainMenu = not (skipMenu opts) + ui <- initUIState UIInitOptions {..} + -- \$ speed (not (skipMenu opts)) debugOptions ks <- initKeyHandlingState return (rs, ui, ks) let initRS' = addWarnings initRS (F.toList warnings) diff --git a/src/swarm-tui/Swarm/TUI/Model/UI.hs b/src/swarm-tui/Swarm/TUI/Model/UI.hs index 9c5c58542..f82027755 100644 --- a/src/swarm-tui/Swarm/TUI/Model/UI.hs +++ b/src/swarm-tui/Swarm/TUI/Model/UI.hs @@ -32,7 +32,7 @@ module Swarm.TUI.Model.UI ( uiGoal, uiStructure, uiIsAutoPlay, - uiHideObjectives, + uiAutoShowObjectives, uiAchievements, lgTicksPerSecond, lastFrameTime, @@ -57,6 +57,7 @@ module Swarm.TUI.Model.UI ( initFocusRing, defaultInitLgTicksPerSecond, initUIState, + UIInitOptions (..), ) where import Brick (AttrMap) @@ -208,7 +209,7 @@ data UIGameplay = UIGameplay , _uiGoal :: GoalDisplay , _uiStructure :: StructureDisplay , _uiIsAutoPlay :: Bool - , _uiHideObjectives :: Bool + , _uiAutoShowObjectives :: Bool , _uiShowREPL :: Bool , _uiShowDebug :: Bool , _uiHideRobotsUntil :: TimeSpec @@ -258,7 +259,7 @@ uiStructure :: Lens' UIGameplay StructureDisplay uiIsAutoPlay :: Lens' UIGameplay Bool -- | Do not open objectives modals on objective completion. -uiHideObjectives :: Lens' UIGameplay Bool +uiAutoShowObjectives :: Lens' UIGameplay Bool -- | A toggle to expand or collapse the REPL by pressing @Ctrl-k@ uiShowREPL :: Lens' UIGameplay Bool @@ -339,6 +340,14 @@ initFocusRing = focusRing $ map FocusablePanel enumerate defaultInitLgTicksPerSecond :: Int defaultInitLgTicksPerSecond = 4 -- 2^4 = 16 ticks / second +data UIInitOptions = UIInitOptions + { speed :: Int + , showMainMenu :: Bool + , autoShowObjectives :: Bool + , debugOptions :: Set DebugOption + } + deriving (Eq, Show) + -- | 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@ @@ -348,12 +357,9 @@ initUIState :: ( Has (Accum (Seq SystemFailure)) sig m , Has (Lift IO) sig m ) => - Int -> - Bool -> - Set DebugOption -> + UIInitOptions -> m UIState -initUIState speedFactor showMainMenu debug = do - -- TODO: ondra - add ui config for silence +initUIState UIInitOptions {..} = do historyT <- sendIO $ readFileMayT =<< getSwarmHistoryPath False let history = maybe [] (map mkREPLSubmission . T.lines) historyT startTime <- sendIO $ getTime Monotonic @@ -363,7 +369,7 @@ initUIState speedFactor showMainMenu debug = do UIState { _uiMenu = if showMainMenu then MainMenu (mainMenu NewGame) else NoMenu , _uiPlaying = not showMainMenu - , _uiDebugOptions = debug + , _uiDebugOptions = debugOptions , _uiLaunchConfig = launchConfigPanel , _uiAchievements = M.fromList $ map (view achievement &&& id) achievements , _uiAttrMap = swarmAttrMap @@ -387,13 +393,13 @@ initUIState speedFactor showMainMenu debug = do , _uiGoal = emptyGoalDisplay , _uiStructure = emptyStructureDisplay , _uiIsAutoPlay = False - , _uiHideObjectives = True + , _uiAutoShowObjectives = autoShowObjectives , _uiTiming = UITiming { _uiShowFPS = False , _uiTPF = 0 , _uiFPS = 0 - , _lgTicksPerSecond = speedFactor + , _lgTicksPerSecond = speed , _lastFrameTime = startTime , _accumulatedTime = 0 , _lastInfoTime = 0