From 56eea8608c7f1b93e90a56187aea6a2108b8efa8 Mon Sep 17 00:00:00 2001 From: Karl Ostmo Date: Tue, 20 Dec 2022 11:35:22 -0800 Subject: [PATCH] Remove superfluous re-exports (#930) Towards #558 Also, move the following functions to `Util` module: * `setFocus` * `openModal` * `isRunningModal` This is another no-op refactor to shrink the size of #873. --- src/Swarm/TUI/Controller.hs | 24 +---------------------- src/Swarm/TUI/Controller/Util.hs | 29 ++++++++++++++++++++++++++++ src/Swarm/TUI/Model.hs | 33 -------------------------------- src/Swarm/TUI/View.hs | 1 + src/Swarm/TUI/View/Util.hs | 1 + src/Swarm/Web.hs | 1 + 6 files changed, 33 insertions(+), 56 deletions(-) diff --git a/src/Swarm/TUI/Controller.hs b/src/Swarm/TUI/Controller.hs index 64d0dca5c..adb58afa3 100644 --- a/src/Swarm/TUI/Controller.hs +++ b/src/Swarm/TUI/Controller.hs @@ -90,7 +90,7 @@ import Swarm.TUI.Model.Achievement.Definitions import Swarm.TUI.Model.Achievement.Persistence import Swarm.TUI.Model.Repl import Swarm.TUI.Model.StateUpdate -import Swarm.TUI.Model.UI (uiAchievements) +import Swarm.TUI.Model.UI import Swarm.TUI.View (generateModal) import Swarm.Util hiding ((<<.=)) import Swarm.Util.Location @@ -355,9 +355,6 @@ mouseLocToWorldCoords (Brick.Location mouseLoc) = do my = fst mouseLoc' + snd regionStart in pure . Just $ W.Coords (mx, my) -setFocus :: FocusablePanel -> EventM Name AppState () -setFocus name = uiState . uiFocusRing %= focusSetCurrent (FocusablePanel name) - -- | Set the game to Running if it was (auto) paused otherwise to paused. -- -- Also resets the last frame time to now. If we are pausing, it @@ -386,25 +383,6 @@ toggleModal mt = do Nothing -> openModal mt Just _ -> uiState . uiModal .= Nothing >> safeAutoUnpause -openModal :: ModalType -> EventM Name AppState () -openModal mt = do - newModal <- gets $ flip generateModal mt - ensurePause - uiState . uiModal ?= newModal - where - -- Set the game to AutoPause if needed - ensurePause = do - pause <- use $ gameState . paused - unless (pause || isRunningModal mt) $ do - gameState . runStatus .= AutoPause - --- | The running modals do not autopause the game. -isRunningModal :: ModalType -> Bool -isRunningModal = \case - RobotsModal -> True - MessagesModal -> True - _ -> False - handleModalEvent :: V.Event -> EventM Name AppState () handleModalEvent = \case V.EvKey V.KEnter [] -> do diff --git a/src/Swarm/TUI/Controller/Util.hs b/src/Swarm/TUI/Controller/Util.hs index 3ffa3e9d6..4c93a7e3a 100644 --- a/src/Swarm/TUI/Controller/Util.hs +++ b/src/Swarm/TUI/Controller/Util.hs @@ -3,7 +3,14 @@ module Swarm.TUI.Controller.Util where import Brick hiding (Direction) +import Brick.Focus +import Control.Lens +import Control.Monad (unless) import Graphics.Vty qualified as V +import Swarm.Game.State +import Swarm.TUI.Model +import Swarm.TUI.Model.UI +import Swarm.TUI.View.Util (generateModal) -- | Pattern synonyms to simplify brick event handler pattern Key :: V.Key -> BrickEvent n e @@ -22,3 +29,25 @@ pattern EscapeKey = VtyEvent (V.EvKey V.KEsc []) pattern FKey :: Int -> BrickEvent n e pattern FKey c = VtyEvent (V.EvKey (V.KFun c) []) + +openModal :: ModalType -> EventM Name AppState () +openModal mt = do + newModal <- gets $ flip generateModal mt + ensurePause + uiState . uiModal ?= newModal + where + -- Set the game to AutoPause if needed + ensurePause = do + pause <- use $ gameState . paused + unless (pause || isRunningModal mt) $ do + gameState . runStatus .= AutoPause + +-- | The running modals do not autopause the game. +isRunningModal :: ModalType -> Bool +isRunningModal = \case + RobotsModal -> True + MessagesModal -> True + _ -> False + +setFocus :: FocusablePanel -> EventM Name AppState () +setFocus name = uiState . uiFocusRing %= focusSetCurrent (FocusablePanel name) diff --git a/src/Swarm/TUI/Model.hs b/src/Swarm/TUI/Model.hs index e0411120d..2f02d1614 100644 --- a/src/Swarm/TUI/Model.hs +++ b/src/Swarm/TUI/Model.hs @@ -62,39 +62,6 @@ module Swarm.TUI.Model ( _InventoryEntry, _InstalledEntry, - -- ** UI Model - UIState, - uiMenu, - uiPlaying, - uiCheatMode, - uiFocusRing, - uiWorldCursor, - uiREPL, - uiInventory, - uiInventorySort, - uiMoreInfoTop, - uiMoreInfoBot, - uiScrollToEnd, - uiError, - uiModal, - uiGoal, - lgTicksPerSecond, - lastFrameTime, - accumulatedTime, - tickCount, - frameCount, - frameTickCount, - lastInfoTime, - uiShowFPS, - uiShowZero, - uiShowRobots, - uiHideRobotsUntil, - uiInventoryShouldUpdate, - uiTPF, - uiFPS, - scenarioRef, - appData, - -- *** REPL Panel Model REPLState, ReplControlMode (..), diff --git a/src/Swarm/TUI/View.hs b/src/Swarm/TUI/View.hs index 8f9ad4dd6..f80a1a31d 100644 --- a/src/Swarm/TUI/View.hs +++ b/src/Swarm/TUI/View.hs @@ -98,6 +98,7 @@ import Swarm.TUI.Border import Swarm.TUI.Inventory.Sorting (renderSortMethod) import Swarm.TUI.Model import Swarm.TUI.Model.Repl +import Swarm.TUI.Model.UI import Swarm.TUI.Panel import Swarm.TUI.View.Achievement import Swarm.TUI.View.Util diff --git a/src/Swarm/TUI/View/Util.hs b/src/Swarm/TUI/View/Util.hs index ffd35dee7..aca53e7fc 100644 --- a/src/Swarm/TUI/View/Util.hs +++ b/src/Swarm/TUI/View/Util.hs @@ -18,6 +18,7 @@ import Swarm.Language.Pretty (prettyText) import Swarm.Language.Types (Polytype) import Swarm.TUI.Attr import Swarm.TUI.Model +import Swarm.TUI.Model.UI import Witch (from, into) -- | Generate a fresh modal window of the requested type. diff --git a/src/Swarm/Web.hs b/src/Swarm/Web.hs index 2c6a9077b..6c1875134 100644 --- a/src/Swarm/Web.hs +++ b/src/Swarm/Web.hs @@ -36,6 +36,7 @@ import Servant import Swarm.Game.Robot import Swarm.Game.State import Swarm.TUI.Model +import Swarm.TUI.Model.UI import System.Timeout (timeout) type SwarmApi =