Skip to content

Commit

Permalink
Remove superfluous re-exports
Browse files Browse the repository at this point in the history
Towards #558

This is another no-op refactor to shrink the size of #873
  • Loading branch information
kostmo committed Dec 20, 2022
1 parent aa6b9f2 commit 0fda0f3
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 56 deletions.
24 changes: 1 addition & 23 deletions src/Swarm/TUI/Controller.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions src/Swarm/TUI/Controller/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
33 changes: 0 additions & 33 deletions src/Swarm/TUI/Model.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..),
Expand Down
1 change: 1 addition & 0 deletions src/Swarm/TUI/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Swarm/TUI/View/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions src/Swarm/Web.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 0fda0f3

Please sign in to comment.