{-# LANGUAGE OverloadedStrings #-}

-- |
-- SPDX-License-Identifier: BSD-3-Clause
--
-- Here is the main player configurable key event handler while playing the game.
module Swarm.TUI.Controller.EventHandlers.Main (
  mainEventHandlers,
  isRunning,
  whenRunningAppState,
  whenRunningPlayState,
  runSingleTick,
  adjustTPS,
  toggleREPLVisibility,
  showCESKDebug,
  hideRobots,
  toggleDiscoveryNotificationModal,
  viewGoal,
  toggleMessagesModal,
) where

import Brick
import Brick.Keybindings
import Control.Lens as Lens
import Control.Monad (unless, void, when)
import Control.Monad.IO.Class (liftIO)
import Swarm.Game.Scenario.Topography.Structure.Recognition.Type (originalStructureDefinitions)
import Swarm.Game.State
import Swarm.Game.State.Landscape
import Swarm.Game.State.Robot
import Swarm.Game.State.Substate
import Swarm.Game.Step (finishGameTick)
import Swarm.TUI.Controller.EventHandlers.Frame (runGameTickUI)
import Swarm.TUI.Controller.UpdateUI (updateUI)
import Swarm.TUI.Controller.Util
import Swarm.TUI.Editor.Model (isWorldEditorEnabled, worldOverdraw)
import Swarm.TUI.Model
import Swarm.TUI.Model.DebugOption (DebugOption (ToggleCreative, ToggleWorldEditor))
import Swarm.TUI.Model.Dialog.Goal
import Swarm.TUI.Model.Event (MainEvent (..), SwarmEvent (..))
import Swarm.TUI.Model.Menu
import Swarm.TUI.Model.UI
import Swarm.TUI.Model.UI.Gameplay
import System.Clock (Clock (..), TimeSpec (..), getTime)

-- | Main keybindings event handler while running the game itself.
--
-- See 'Swarm.TUI.Controller.handleMainEvent'.
mainEventHandlers :: [KeyEventHandler SwarmEvent (EventM Name AppState)]
mainEventHandlers :: [KeyEventHandler SwarmEvent (EventM Name AppState)]
mainEventHandlers = (MainEvent -> SwarmEvent)
-> (MainEvent -> (Text, EventM Name AppState ()))
-> [KeyEventHandler SwarmEvent (EventM Name AppState)]
forall e2 e1 s.
(Ord e2, Enum e1, Bounded e1) =>
(e1 -> e2)
-> (e1 -> (Text, EventM Name s ()))
-> [KeyEventHandler e2 (EventM Name s)]
allHandlers MainEvent -> SwarmEvent
Main ((MainEvent -> (Text, EventM Name AppState ()))
 -> [KeyEventHandler SwarmEvent (EventM Name AppState)])
-> (MainEvent -> (Text, EventM Name AppState ()))
-> [KeyEventHandler SwarmEvent (EventM Name AppState)]
forall a b. (a -> b) -> a -> b
$ \case
  MainEvent
QuitEvent -> (Text
"Open quit game dialog", EventM Name AppState ()
toggleQuitGameDialog)
  MainEvent
ViewHelpEvent ->
    ( Text
"View Help screen"
    , LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) (EventM Name ScenarioState () -> EventM Name AppState ())
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ MidScenarioModalType -> EventM Name ScenarioState ()
toggleMidScenarioModal MidScenarioModalType
HelpModal
    )
  MainEvent
ViewRobotsEvent ->
    ( Text
"View Robots screen"
    , LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) (EventM Name ScenarioState () -> EventM Name AppState ())
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ MidScenarioModalType -> EventM Name ScenarioState ()
toggleMidScenarioModal MidScenarioModalType
RobotsModal
    )
  MainEvent
ViewRecipesEvent ->
    ( Text
"View Recipes screen"
    , LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) (EventM Name ScenarioState () -> EventM Name AppState ())
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ MidScenarioModalType
-> Lens' Discovery (Notifications (Recipe Entity))
-> EventM Name ScenarioState ()
forall a.
MidScenarioModalType
-> Lens' Discovery (Notifications a)
-> EventM Name ScenarioState ()
toggleDiscoveryNotificationModal MidScenarioModalType
RecipesModal (Notifications (Recipe Entity)
 -> f (Notifications (Recipe Entity)))
-> Discovery -> f Discovery
Lens' Discovery (Notifications (Recipe Entity))
availableRecipes
    )
  MainEvent
ViewCommandsEvent ->
    ( Text
"View Commands screen"
    , LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) (EventM Name ScenarioState () -> EventM Name AppState ())
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ MidScenarioModalType
-> Lens' Discovery (Notifications Const)
-> EventM Name ScenarioState ()
forall a.
MidScenarioModalType
-> Lens' Discovery (Notifications a)
-> EventM Name ScenarioState ()
toggleDiscoveryNotificationModal MidScenarioModalType
CommandsModal (Notifications Const -> f (Notifications Const))
-> Discovery -> f Discovery
Lens' Discovery (Notifications Const)
availableCommands
    )
  MainEvent
ViewMessagesEvent ->
    ( Text
"View Messages screen"
    , LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) EventM Name ScenarioState ()
toggleMessagesModal
    )
  MainEvent
ViewStructuresEvent ->
    ( Text
"View Structures screen"
    , LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) (EventM Name ScenarioState () -> EventM Name AppState ())
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$
        Lens'
  Landscape
  (Map
     StructureName (StructureInfo RecognizableStructureContent Entity))
-> EventM Name ScenarioState ()
forall (t :: * -> *) a.
Foldable t =>
Lens' Landscape (t a) -> EventM Name ScenarioState ()
toggleStructuresModal ((RecognizerAutomatons RecognizableStructureContent Entity
 -> f (RecognizerAutomatons RecognizableStructureContent Entity))
-> Landscape -> f Landscape
Lens'
  Landscape
  (RecognizerAutomatons RecognizableStructureContent Entity)
recognizerAutomatons ((RecognizerAutomatons RecognizableStructureContent Entity
  -> f (RecognizerAutomatons RecognizableStructureContent Entity))
 -> Landscape -> f Landscape)
-> ((Map
       StructureName (StructureInfo RecognizableStructureContent Entity)
     -> f (Map
             StructureName (StructureInfo RecognizableStructureContent Entity)))
    -> RecognizerAutomatons RecognizableStructureContent Entity
    -> f (RecognizerAutomatons RecognizableStructureContent Entity))
-> (Map
      StructureName (StructureInfo RecognizableStructureContent Entity)
    -> f (Map
            StructureName (StructureInfo RecognizableStructureContent Entity)))
-> Landscape
-> f Landscape
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map
   StructureName (StructureInfo RecognizableStructureContent Entity)
 -> f (Map
         StructureName (StructureInfo RecognizableStructureContent Entity)))
-> RecognizerAutomatons RecognizableStructureContent Entity
-> f (RecognizerAutomatons RecognizableStructureContent Entity)
forall b a (f :: * -> *).
Functor f =>
(Map StructureName (StructureInfo b a)
 -> f (Map StructureName (StructureInfo b a)))
-> RecognizerAutomatons b a -> f (RecognizerAutomatons b a)
originalStructureDefinitions)
    )
  MainEvent
ViewGoalEvent ->
    ( Text
"View scenario goal description"
    , LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) EventM Name ScenarioState ()
viewGoal
    )
  MainEvent
HideRobotsEvent -> (Text
"Hide robots for a few ticks", LensLike' (Zoomed (EventM Name UIGameplay) ()) AppState UIGameplay
-> EventM Name UIGameplay () -> EventM Name AppState ()
forall c.
LensLike' (Zoomed (EventM Name UIGameplay) c) AppState UIGameplay
-> EventM Name UIGameplay c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((UIGameplay
     -> Focusing (StateT (EventState Name) IO) () UIGameplay)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (UIGameplay
    -> Focusing (StateT (EventState Name) IO) () UIGameplay)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState ((ScenarioState
  -> Focusing (StateT (EventState Name) IO) () ScenarioState)
 -> PlayState
 -> Focusing (StateT (EventState Name) IO) () PlayState)
-> ((UIGameplay
     -> Focusing (StateT (EventState Name) IO) () UIGameplay)
    -> ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> (UIGameplay
    -> Focusing (StateT (EventState Name) IO) () UIGameplay)
-> PlayState
-> Focusing (StateT (EventState Name) IO) () PlayState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay
 -> Focusing (StateT (EventState Name) IO) () UIGameplay)
-> ScenarioState
-> Focusing (StateT (EventState Name) IO) () ScenarioState
Lens' ScenarioState UIGameplay
uiGameplay) EventM Name UIGameplay ()
hideRobots)
  MainEvent
ShowCESKDebugEvent -> (Text
"Show active robot CESK machine debugging line", EventM Name AppState ()
showCESKDebug)
  MainEvent
PauseEvent -> (Text
"Pause or unpause the game", LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) (EventM Name ScenarioState () -> EventM Name AppState ())
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ EventM Name ScenarioState () -> EventM Name ScenarioState ()
whenRunningPlayState EventM Name ScenarioState ()
safeTogglePause)
  MainEvent
RunSingleTickEvent -> (Text
"Run game for a single tick", EventM Name AppState () -> EventM Name AppState ()
whenRunningAppState EventM Name AppState ()
runSingleTick)
  MainEvent
IncreaseTpsEvent -> (Text
"Double game speed", LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) (EventM Name ScenarioState () -> EventM Name AppState ())
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ EventM Name ScenarioState () -> EventM Name ScenarioState ()
whenRunningPlayState (EventM Name ScenarioState () -> EventM Name ScenarioState ())
-> ((ScenarioState -> ScenarioState)
    -> EventM Name ScenarioState ())
-> (ScenarioState -> ScenarioState)
-> EventM Name ScenarioState ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState -> ScenarioState) -> EventM Name ScenarioState ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((ScenarioState -> ScenarioState) -> EventM Name ScenarioState ())
-> (ScenarioState -> ScenarioState) -> EventM Name ScenarioState ()
forall a b. (a -> b) -> a -> b
$ (Int -> Int -> Int) -> ScenarioState -> ScenarioState
adjustTPS Int -> Int -> Int
forall a. Num a => a -> a -> a
(+))
  MainEvent
DecreaseTpsEvent -> (Text
"Halve game speed", LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) (EventM Name ScenarioState () -> EventM Name AppState ())
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ EventM Name ScenarioState () -> EventM Name ScenarioState ()
whenRunningPlayState (EventM Name ScenarioState () -> EventM Name ScenarioState ())
-> ((ScenarioState -> ScenarioState)
    -> EventM Name ScenarioState ())
-> (ScenarioState -> ScenarioState)
-> EventM Name ScenarioState ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState -> ScenarioState) -> EventM Name ScenarioState ()
forall s (m :: * -> *). MonadState s m => (s -> s) -> m ()
modify ((ScenarioState -> ScenarioState) -> EventM Name ScenarioState ())
-> (ScenarioState -> ScenarioState) -> EventM Name ScenarioState ()
forall a b. (a -> b) -> a -> b
$ (Int -> Int -> Int) -> ScenarioState -> ScenarioState
adjustTPS (-))
  MainEvent
FocusWorldEvent -> (Text
"Set focus on the World panel", LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) (EventM Name ScenarioState () -> EventM Name AppState ())
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ FocusablePanel -> EventM Name ScenarioState ()
setFocus FocusablePanel
WorldPanel)
  MainEvent
FocusRobotEvent -> (Text
"Set focus on the Robot panel", LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) (EventM Name ScenarioState () -> EventM Name AppState ())
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ FocusablePanel -> EventM Name ScenarioState ()
setFocus FocusablePanel
RobotPanel)
  MainEvent
FocusREPLEvent -> (Text
"Set focus on the REPL panel", LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) (EventM Name ScenarioState () -> EventM Name AppState ())
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ FocusablePanel -> EventM Name ScenarioState ()
setFocus FocusablePanel
REPLPanel)
  MainEvent
FocusInfoEvent -> (Text
"Set focus on the Info panel", LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) (EventM Name ScenarioState () -> EventM Name AppState ())
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ FocusablePanel -> EventM Name ScenarioState ()
setFocus FocusablePanel
InfoPanel)
  MainEvent
ToggleCreativeModeEvent -> (Text
"Toggle creative mode", DebugOption -> EventM Name AppState () -> EventM Name AppState ()
whenDebug DebugOption
ToggleCreative (EventM Name AppState () -> EventM Name AppState ())
-> EventM Name AppState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) EventM Name ScenarioState ()
toggleCreativeMode)
  MainEvent
ToggleWorldEditorEvent -> (Text
"Toggle world editor mode", DebugOption -> EventM Name AppState () -> EventM Name AppState ()
whenDebug DebugOption
ToggleWorldEditor (EventM Name AppState () -> EventM Name AppState ())
-> EventM Name AppState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) EventM Name ScenarioState ()
toggleWorldEditor)
  MainEvent
ToggleREPLVisibilityEvent -> (Text
"Collapse/Expand REPL panel", LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) EventM Name ScenarioState ()
toggleREPLVisibility)
  MainEvent
ViewBaseEvent -> (Text
"View the base robot", LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) EventM Name ScenarioState ()
viewBase)
  MainEvent
ToggleFPSEvent -> (Text
"Toggle the FPS display", LensLike'
  (Zoomed (EventM Name ScenarioState) ()) AppState ScenarioState
-> EventM Name ScenarioState () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
Lens' AppState PlayState
playState ((PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
 -> AppState -> Focusing (StateT (EventState Name) IO) () AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) () ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) () PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) () AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) () ScenarioState)
-> PlayState -> Focusing (StateT (EventState Name) IO) () PlayState
Lens' PlayState ScenarioState
scenarioState) EventM Name ScenarioState ()
toggleFPS)

toggleQuitGameDialog :: EventM Name AppState ()
toggleQuitGameDialog :: EventM Name AppState ()
toggleQuitGameDialog = do
  AppState
s <- EventM Name AppState AppState
forall s (m :: * -> *). MonadState s m => m s
get
  let whichModal :: EndScenarioModalType
whichModal = case AppState
s AppState
-> Getting WinCondition AppState WinCondition -> WinCondition
forall s a. s -> Getting a s a -> a
^. (PlayState -> Const WinCondition PlayState)
-> AppState -> Const WinCondition AppState
Lens' AppState PlayState
playState ((PlayState -> Const WinCondition PlayState)
 -> AppState -> Const WinCondition AppState)
-> ((WinCondition -> Const WinCondition WinCondition)
    -> PlayState -> Const WinCondition PlayState)
-> Getting WinCondition AppState WinCondition
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState -> Const WinCondition ScenarioState)
-> PlayState -> Const WinCondition PlayState
Lens' PlayState ScenarioState
scenarioState ((ScenarioState -> Const WinCondition ScenarioState)
 -> PlayState -> Const WinCondition PlayState)
-> ((WinCondition -> Const WinCondition WinCondition)
    -> ScenarioState -> Const WinCondition ScenarioState)
-> (WinCondition -> Const WinCondition WinCondition)
-> PlayState
-> Const WinCondition PlayState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GameState -> Const WinCondition GameState)
-> ScenarioState -> Const WinCondition ScenarioState
Lens' ScenarioState GameState
gameState ((GameState -> Const WinCondition GameState)
 -> ScenarioState -> Const WinCondition ScenarioState)
-> ((WinCondition -> Const WinCondition WinCondition)
    -> GameState -> Const WinCondition GameState)
-> (WinCondition -> Const WinCondition WinCondition)
-> ScenarioState
-> Const WinCondition ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WinCondition -> Const WinCondition WinCondition)
-> GameState -> Const WinCondition GameState
Lens' GameState WinCondition
winCondition of
        WinConditions (Won Bool
_ TickNumber
_) ObjectiveCompletion
_ -> ScenarioOutcome -> EndScenarioModalType
ScenarioFinishModal ScenarioOutcome
WinModal
        WinConditions (Unwinnable Bool
_) ObjectiveCompletion
_ -> ScenarioOutcome -> EndScenarioModalType
ScenarioFinishModal ScenarioOutcome
LoseModal
        WinCondition
_ -> EndScenarioModalType
QuitModal
  LensLike' (Zoomed (EventM Name PlayState) ()) AppState PlayState
-> EventM Name PlayState () -> EventM Name AppState ()
forall c.
LensLike' (Zoomed (EventM Name PlayState) c) AppState PlayState
-> EventM Name PlayState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom (PlayState -> Focusing (StateT (EventState Name) IO) () PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) () AppState
LensLike' (Zoomed (EventM Name PlayState) ()) AppState PlayState
Lens' AppState PlayState
playState (EventM Name PlayState () -> EventM Name AppState ())
-> EventM Name PlayState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ EndScenarioModalType -> Menu -> EventM Name PlayState ()
toggleEndScenarioModal EndScenarioModalType
whichModal (Menu -> EventM Name PlayState ())
-> Menu -> EventM Name PlayState ()
forall a b. (a -> b) -> a -> b
$ AppState
s AppState -> Getting Menu AppState Menu -> Menu
forall s a. s -> Getting a s a -> a
^. (UIState -> Const Menu UIState) -> AppState -> Const Menu AppState
Lens' AppState UIState
uiState ((UIState -> Const Menu UIState)
 -> AppState -> Const Menu AppState)
-> ((Menu -> Const Menu Menu) -> UIState -> Const Menu UIState)
-> Getting Menu AppState Menu
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Menu -> Const Menu Menu) -> UIState -> Const Menu UIState
Lens' UIState Menu
uiMenu

toggleGameModal ::
  Foldable t =>
  MidScenarioModalType ->
  Getter GameState (t a) ->
  EventM Name ScenarioState Bool
toggleGameModal :: forall (t :: * -> *) a.
Foldable t =>
MidScenarioModalType
-> Getter GameState (t a) -> EventM Name ScenarioState Bool
toggleGameModal MidScenarioModalType
m Getter GameState (t a)
l = do
  ScenarioState
s <- EventM Name ScenarioState ScenarioState
forall s (m :: * -> *). MonadState s m => m s
get
  let nothingToShow :: Bool
nothingToShow = t a -> Bool
forall a. t a -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (t a -> Bool) -> t a -> Bool
forall a b. (a -> b) -> a -> b
$ ScenarioState
s ScenarioState -> Getting (t a) ScenarioState (t a) -> t a
forall s a. s -> Getting a s a -> a
^. (GameState -> Const (t a) GameState)
-> ScenarioState -> Const (t a) ScenarioState
Lens' ScenarioState GameState
gameState ((GameState -> Const (t a) GameState)
 -> ScenarioState -> Const (t a) ScenarioState)
-> ((t a -> Const (t a) (t a))
    -> GameState -> Const (t a) GameState)
-> Getting (t a) ScenarioState (t a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t a -> Const (t a) (t a)) -> GameState -> Const (t a) GameState
Getter GameState (t a)
l

  Bool
-> EventM Name ScenarioState () -> EventM Name ScenarioState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
nothingToShow (EventM Name ScenarioState () -> EventM Name ScenarioState ())
-> EventM Name ScenarioState () -> EventM Name ScenarioState ()
forall a b. (a -> b) -> a -> b
$
    MidScenarioModalType -> EventM Name ScenarioState ()
toggleMidScenarioModal MidScenarioModalType
m
  Bool -> EventM Name ScenarioState Bool
forall a. a -> EventM Name ScenarioState a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
nothingToShow

toggleStructuresModal ::
  Foldable t =>
  Lens' Landscape (t a) ->
  EventM Name ScenarioState ()
toggleStructuresModal :: forall (t :: * -> *) a.
Foldable t =>
Lens' Landscape (t a) -> EventM Name ScenarioState ()
toggleStructuresModal Lens' Landscape (t a)
l = EventM Name ScenarioState Bool -> EventM Name ScenarioState ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (EventM Name ScenarioState Bool -> EventM Name ScenarioState ())
-> EventM Name ScenarioState Bool -> EventM Name ScenarioState ()
forall a b. (a -> b) -> a -> b
$ MidScenarioModalType
-> Getter GameState (t a) -> EventM Name ScenarioState Bool
forall (t :: * -> *) a.
Foldable t =>
MidScenarioModalType
-> Getter GameState (t a) -> EventM Name ScenarioState Bool
toggleGameModal MidScenarioModalType
StructuresModal ((Landscape -> f Landscape) -> GameState -> f GameState
Lens' GameState Landscape
landscape ((Landscape -> f Landscape) -> GameState -> f GameState)
-> ((t a -> f (t a)) -> Landscape -> f Landscape)
-> (t a -> f (t a))
-> GameState
-> f GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (t a -> f (t a)) -> Landscape -> f Landscape
Lens' Landscape (t a)
l)

toggleDiscoveryNotificationModal ::
  MidScenarioModalType ->
  Lens' Discovery (Notifications a) ->
  EventM Name ScenarioState ()
toggleDiscoveryNotificationModal :: forall a.
MidScenarioModalType
-> Lens' Discovery (Notifications a)
-> EventM Name ScenarioState ()
toggleDiscoveryNotificationModal MidScenarioModalType
mt Lens' Discovery (Notifications a)
l = do
  Bool
nothingToShow <- MidScenarioModalType
-> Getter GameState [a] -> EventM Name ScenarioState Bool
forall (t :: * -> *) a.
Foldable t =>
MidScenarioModalType
-> Getter GameState (t a) -> EventM Name ScenarioState Bool
toggleGameModal MidScenarioModalType
mt (Getter GameState [a] -> EventM Name ScenarioState Bool)
-> Getter GameState [a] -> EventM Name ScenarioState Bool
forall a b. (a -> b) -> a -> b
$ (Discovery -> f Discovery) -> GameState -> f GameState
Lens' GameState Discovery
discovery ((Discovery -> f Discovery) -> GameState -> f GameState)
-> (([a] -> f [a]) -> Discovery -> f Discovery)
-> ([a] -> f [a])
-> GameState
-> f GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Notifications a -> f (Notifications a))
-> Discovery -> f Discovery
Lens' Discovery (Notifications a)
l ((Notifications a -> f (Notifications a))
 -> Discovery -> f Discovery)
-> (([a] -> f [a]) -> Notifications a -> f (Notifications a))
-> ([a] -> f [a])
-> Discovery
-> f Discovery
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([a] -> f [a]) -> Notifications a -> f (Notifications a)
forall a1 a2 (f :: * -> *).
Functor f =>
([a1] -> f [a2]) -> Notifications a1 -> f (Notifications a2)
notificationsContent
  Bool
-> EventM Name ScenarioState () -> EventM Name ScenarioState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
nothingToShow (EventM Name ScenarioState () -> EventM Name ScenarioState ())
-> EventM Name ScenarioState () -> EventM Name ScenarioState ()
forall a b. (a -> b) -> a -> b
$ (GameState -> Identity GameState)
-> ScenarioState -> Identity ScenarioState
Lens' ScenarioState GameState
gameState ((GameState -> Identity GameState)
 -> ScenarioState -> Identity ScenarioState)
-> ((Int -> Identity Int) -> GameState -> Identity GameState)
-> (Int -> Identity Int)
-> ScenarioState
-> Identity ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Discovery -> Identity Discovery)
-> GameState -> Identity GameState
Lens' GameState Discovery
discovery ((Discovery -> Identity Discovery)
 -> GameState -> Identity GameState)
-> ((Int -> Identity Int) -> Discovery -> Identity Discovery)
-> (Int -> Identity Int)
-> GameState
-> Identity GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Notifications a -> Identity (Notifications a))
-> Discovery -> Identity Discovery
Lens' Discovery (Notifications a)
l ((Notifications a -> Identity (Notifications a))
 -> Discovery -> Identity Discovery)
-> ((Int -> Identity Int)
    -> Notifications a -> Identity (Notifications a))
-> (Int -> Identity Int)
-> Discovery
-> Identity Discovery
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Identity Int)
-> Notifications a -> Identity (Notifications a)
forall a (f :: * -> *).
Functor f =>
(Int -> f Int) -> Notifications a -> f (Notifications a)
notificationsCount ((Int -> Identity Int) -> ScenarioState -> Identity ScenarioState)
-> Int -> EventM Name ScenarioState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int
0

toggleMessagesModal :: EventM Name ScenarioState ()
toggleMessagesModal :: EventM Name ScenarioState ()
toggleMessagesModal = do
  ScenarioState
s <- EventM Name ScenarioState ScenarioState
forall s (m :: * -> *). MonadState s m => m s
get
  Bool
nothingToShow <- MidScenarioModalType
-> Getter GameState [LogEntry] -> EventM Name ScenarioState Bool
forall (t :: * -> *) a.
Foldable t =>
MidScenarioModalType
-> Getter GameState (t a) -> EventM Name ScenarioState Bool
toggleGameModal MidScenarioModalType
MessagesModal (Getter GameState [LogEntry] -> EventM Name ScenarioState Bool)
-> Getter GameState [LogEntry] -> EventM Name ScenarioState Bool
forall a b. (a -> b) -> a -> b
$ (Notifications LogEntry -> f (Notifications LogEntry))
-> GameState -> f GameState
Getter GameState (Notifications LogEntry)
messageNotifications ((Notifications LogEntry -> f (Notifications LogEntry))
 -> GameState -> f GameState)
-> (([LogEntry] -> f [LogEntry])
    -> Notifications LogEntry -> f (Notifications LogEntry))
-> ([LogEntry] -> f [LogEntry])
-> GameState
-> f GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([LogEntry] -> f [LogEntry])
-> Notifications LogEntry -> f (Notifications LogEntry)
forall a1 a2 (f :: * -> *).
Functor f =>
([a1] -> f [a2]) -> Notifications a1 -> f (Notifications a2)
notificationsContent
  Bool
-> EventM Name ScenarioState () -> EventM Name ScenarioState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless Bool
nothingToShow (EventM Name ScenarioState () -> EventM Name ScenarioState ())
-> EventM Name ScenarioState () -> EventM Name ScenarioState ()
forall a b. (a -> b) -> a -> b
$ (GameState -> Identity GameState)
-> ScenarioState -> Identity ScenarioState
Lens' ScenarioState GameState
gameState ((GameState -> Identity GameState)
 -> ScenarioState -> Identity ScenarioState)
-> ((TickNumber -> Identity TickNumber)
    -> GameState -> Identity GameState)
-> (TickNumber -> Identity TickNumber)
-> ScenarioState
-> Identity ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Messages -> Identity Messages) -> GameState -> Identity GameState
Lens' GameState Messages
messageInfo ((Messages -> Identity Messages)
 -> GameState -> Identity GameState)
-> ((TickNumber -> Identity TickNumber)
    -> Messages -> Identity Messages)
-> (TickNumber -> Identity TickNumber)
-> GameState
-> Identity GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TickNumber -> Identity TickNumber)
-> Messages -> Identity Messages
Lens' Messages TickNumber
lastSeenMessageTime ((TickNumber -> Identity TickNumber)
 -> ScenarioState -> Identity ScenarioState)
-> TickNumber -> EventM Name ScenarioState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= ScenarioState
s ScenarioState
-> Getting TickNumber ScenarioState TickNumber -> TickNumber
forall s a. s -> Getting a s a -> a
^. (GameState -> Const TickNumber GameState)
-> ScenarioState -> Const TickNumber ScenarioState
Lens' ScenarioState GameState
gameState ((GameState -> Const TickNumber GameState)
 -> ScenarioState -> Const TickNumber ScenarioState)
-> ((TickNumber -> Const TickNumber TickNumber)
    -> GameState -> Const TickNumber GameState)
-> Getting TickNumber ScenarioState TickNumber
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TemporalState -> Const TickNumber TemporalState)
-> GameState -> Const TickNumber GameState
Lens' GameState TemporalState
temporal ((TemporalState -> Const TickNumber TemporalState)
 -> GameState -> Const TickNumber GameState)
-> ((TickNumber -> Const TickNumber TickNumber)
    -> TemporalState -> Const TickNumber TemporalState)
-> (TickNumber -> Const TickNumber TickNumber)
-> GameState
-> Const TickNumber GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TickNumber -> Const TickNumber TickNumber)
-> TemporalState -> Const TickNumber TemporalState
Lens' TemporalState TickNumber
ticks

viewGoal :: EventM Name ScenarioState ()
viewGoal :: EventM Name ScenarioState ()
viewGoal = do
  ScenarioState
s <- EventM Name ScenarioState ScenarioState
forall s (m :: * -> *). MonadState s m => m s
get
  if GoalTracking -> Bool
hasAnythingToShow (GoalTracking -> Bool) -> GoalTracking -> Bool
forall a b. (a -> b) -> a -> b
$ ScenarioState
s ScenarioState
-> Getting GoalTracking ScenarioState GoalTracking -> GoalTracking
forall s a. s -> Getting a s a -> a
^. (UIGameplay -> Const GoalTracking UIGameplay)
-> ScenarioState -> Const GoalTracking ScenarioState
Lens' ScenarioState UIGameplay
uiGameplay ((UIGameplay -> Const GoalTracking UIGameplay)
 -> ScenarioState -> Const GoalTracking ScenarioState)
-> ((GoalTracking -> Const GoalTracking GoalTracking)
    -> UIGameplay -> Const GoalTracking UIGameplay)
-> Getting GoalTracking ScenarioState GoalTracking
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIDialogs -> Const GoalTracking UIDialogs)
-> UIGameplay -> Const GoalTracking UIGameplay
Lens' UIGameplay UIDialogs
uiDialogs ((UIDialogs -> Const GoalTracking UIDialogs)
 -> UIGameplay -> Const GoalTracking UIGameplay)
-> ((GoalTracking -> Const GoalTracking GoalTracking)
    -> UIDialogs -> Const GoalTracking UIDialogs)
-> (GoalTracking -> Const GoalTracking GoalTracking)
-> UIGameplay
-> Const GoalTracking UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GoalDisplay -> Const GoalTracking GoalDisplay)
-> UIDialogs -> Const GoalTracking UIDialogs
Lens' UIDialogs GoalDisplay
uiGoal ((GoalDisplay -> Const GoalTracking GoalDisplay)
 -> UIDialogs -> Const GoalTracking UIDialogs)
-> ((GoalTracking -> Const GoalTracking GoalTracking)
    -> GoalDisplay -> Const GoalTracking GoalDisplay)
-> (GoalTracking -> Const GoalTracking GoalTracking)
-> UIDialogs
-> Const GoalTracking UIDialogs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GoalTracking -> Const GoalTracking GoalTracking)
-> GoalDisplay -> Const GoalTracking GoalDisplay
Lens' GoalDisplay GoalTracking
goalsContent
    then MidScenarioModalType -> EventM Name ScenarioState ()
toggleMidScenarioModal MidScenarioModalType
GoalModal
    else EventM Name ScenarioState ()
forall n s. EventM n s ()
continueWithoutRedraw

hideRobots :: EventM Name UIGameplay ()
hideRobots :: EventM Name UIGameplay ()
hideRobots = do
  TimeSpec
t <- IO TimeSpec -> EventM Name UIGameplay TimeSpec
forall a. IO a -> EventM Name UIGameplay a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO TimeSpec -> EventM Name UIGameplay TimeSpec)
-> IO TimeSpec -> EventM Name UIGameplay TimeSpec
forall a b. (a -> b) -> a -> b
$ Clock -> IO TimeSpec
getTime Clock
Monotonic
  TimeSpec
h <- Getting TimeSpec UIGameplay TimeSpec
-> EventM Name UIGameplay TimeSpec
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use Getting TimeSpec UIGameplay TimeSpec
Lens' UIGameplay TimeSpec
uiHideRobotsUntil
  case TimeSpec
h TimeSpec -> TimeSpec -> Bool
forall a. Ord a => a -> a -> Bool
>= TimeSpec
t of
    -- ignore repeated keypresses
    Bool
True -> EventM Name UIGameplay ()
forall n s. EventM n s ()
continueWithoutRedraw
    -- hide for two seconds
    Bool
False -> do
      (TimeSpec -> Identity TimeSpec)
-> UIGameplay -> Identity UIGameplay
Lens' UIGameplay TimeSpec
uiHideRobotsUntil ((TimeSpec -> Identity TimeSpec)
 -> UIGameplay -> Identity UIGameplay)
-> TimeSpec -> EventM Name UIGameplay ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= TimeSpec
t TimeSpec -> TimeSpec -> TimeSpec
forall a. Num a => a -> a -> a
+ Int64 -> Int64 -> TimeSpec
TimeSpec Int64
2 Int64
0
      Name -> EventM Name UIGameplay ()
forall n s. Ord n => n -> EventM n s ()
invalidateCacheEntry Name
WorldCache

showCESKDebug :: EventM Name AppState ()
showCESKDebug :: EventM Name AppState ()
showCESKDebug = do
  AppState
s <- EventM Name AppState AppState
forall s (m :: * -> *). MonadState s m => m s
get
  let isPaused :: Bool
isPaused = AppState
s AppState -> Getting Bool AppState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (PlayState -> Const Bool PlayState)
-> AppState -> Const Bool AppState
Lens' AppState PlayState
playState ((PlayState -> Const Bool PlayState)
 -> AppState -> Const Bool AppState)
-> ((Bool -> Const Bool Bool) -> PlayState -> Const Bool PlayState)
-> Getting Bool AppState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState -> Const Bool ScenarioState)
-> PlayState -> Const Bool PlayState
Lens' PlayState ScenarioState
scenarioState ((ScenarioState -> Const Bool ScenarioState)
 -> PlayState -> Const Bool PlayState)
-> ((Bool -> Const Bool Bool)
    -> ScenarioState -> Const Bool ScenarioState)
-> (Bool -> Const Bool Bool)
-> PlayState
-> Const Bool PlayState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GameState -> Const Bool GameState)
-> ScenarioState -> Const Bool ScenarioState
Lens' ScenarioState GameState
gameState ((GameState -> Const Bool GameState)
 -> ScenarioState -> Const Bool ScenarioState)
-> ((Bool -> Const Bool Bool) -> GameState -> Const Bool GameState)
-> (Bool -> Const Bool Bool)
-> ScenarioState
-> Const Bool ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TemporalState -> Const Bool TemporalState)
-> GameState -> Const Bool GameState
Lens' GameState TemporalState
temporal ((TemporalState -> Const Bool TemporalState)
 -> GameState -> Const Bool GameState)
-> ((Bool -> Const Bool Bool)
    -> TemporalState -> Const Bool TemporalState)
-> (Bool -> Const Bool Bool)
-> GameState
-> Const Bool GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> TemporalState -> Const Bool TemporalState
Getter TemporalState Bool
paused
  let isCreative :: Bool
isCreative = AppState
s AppState -> Getting Bool AppState Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (PlayState -> Const Bool PlayState)
-> AppState -> Const Bool AppState
Lens' AppState PlayState
playState ((PlayState -> Const Bool PlayState)
 -> AppState -> Const Bool AppState)
-> ((Bool -> Const Bool Bool) -> PlayState -> Const Bool PlayState)
-> Getting Bool AppState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState -> Const Bool ScenarioState)
-> PlayState -> Const Bool PlayState
Lens' PlayState ScenarioState
scenarioState ((ScenarioState -> Const Bool ScenarioState)
 -> PlayState -> Const Bool PlayState)
-> ((Bool -> Const Bool Bool)
    -> ScenarioState -> Const Bool ScenarioState)
-> (Bool -> Const Bool Bool)
-> PlayState
-> Const Bool PlayState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GameState -> Const Bool GameState)
-> ScenarioState -> Const Bool ScenarioState
Lens' ScenarioState GameState
gameState ((GameState -> Const Bool GameState)
 -> ScenarioState -> Const Bool ScenarioState)
-> ((Bool -> Const Bool Bool) -> GameState -> Const Bool GameState)
-> (Bool -> Const Bool Bool)
-> ScenarioState
-> Const Bool ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool) -> GameState -> Const Bool GameState
Lens' GameState Bool
creativeMode
  let hasDebug :: Bool
hasDebug = Bool -> GameState -> Bool
hasDebugCapability Bool
isCreative (GameState -> Bool) -> GameState -> Bool
forall a b. (a -> b) -> a -> b
$ AppState
s AppState -> Getting GameState AppState GameState -> GameState
forall s a. s -> Getting a s a -> a
^. (PlayState -> Const GameState PlayState)
-> AppState -> Const GameState AppState
Lens' AppState PlayState
playState ((PlayState -> Const GameState PlayState)
 -> AppState -> Const GameState AppState)
-> ((GameState -> Const GameState GameState)
    -> PlayState -> Const GameState PlayState)
-> Getting GameState AppState GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState -> Const GameState ScenarioState)
-> PlayState -> Const GameState PlayState
Lens' PlayState ScenarioState
scenarioState ((ScenarioState -> Const GameState ScenarioState)
 -> PlayState -> Const GameState PlayState)
-> ((GameState -> Const GameState GameState)
    -> ScenarioState -> Const GameState ScenarioState)
-> (GameState -> Const GameState GameState)
-> PlayState
-> Const GameState PlayState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GameState -> Const GameState GameState)
-> ScenarioState -> Const GameState ScenarioState
Lens' ScenarioState GameState
gameState
  Bool -> EventM Name AppState () -> EventM Name AppState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Bool
isPaused Bool -> Bool -> Bool
&& Bool
hasDebug) (EventM Name AppState () -> EventM Name AppState ())
-> EventM Name AppState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ do
    Bool
debug <- (PlayState -> (Bool, PlayState)) -> AppState -> (Bool, AppState)
Lens' AppState PlayState
playState ((PlayState -> (Bool, PlayState)) -> AppState -> (Bool, AppState))
-> ((Bool -> (Bool, Bool)) -> PlayState -> (Bool, PlayState))
-> (Bool -> (Bool, Bool))
-> AppState
-> (Bool, AppState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState -> (Bool, ScenarioState))
-> PlayState -> (Bool, PlayState)
Lens' PlayState ScenarioState
scenarioState ((ScenarioState -> (Bool, ScenarioState))
 -> PlayState -> (Bool, PlayState))
-> ((Bool -> (Bool, Bool))
    -> ScenarioState -> (Bool, ScenarioState))
-> (Bool -> (Bool, Bool))
-> PlayState
-> (Bool, PlayState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> (Bool, UIGameplay))
-> ScenarioState -> (Bool, ScenarioState)
Lens' ScenarioState UIGameplay
uiGameplay ((UIGameplay -> (Bool, UIGameplay))
 -> ScenarioState -> (Bool, ScenarioState))
-> ((Bool -> (Bool, Bool)) -> UIGameplay -> (Bool, UIGameplay))
-> (Bool -> (Bool, Bool))
-> ScenarioState
-> (Bool, ScenarioState)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> (Bool, Bool)) -> UIGameplay -> (Bool, UIGameplay)
Lens' UIGameplay Bool
uiShowDebug ((Bool -> (Bool, Bool)) -> AppState -> (Bool, AppState))
-> (Bool -> Bool) -> EventM Name AppState Bool
forall s (m :: * -> *) b a.
MonadState s m =>
LensLike ((,) b) s s a b -> (a -> b) -> m b
Lens.<%= Bool -> Bool
not
    if Bool
debug
      then (PlayState -> Identity PlayState) -> AppState -> Identity AppState
Lens' AppState PlayState
playState ((PlayState -> Identity PlayState)
 -> AppState -> Identity AppState)
-> ((Step -> Identity Step) -> PlayState -> Identity PlayState)
-> (Step -> Identity Step)
-> AppState
-> Identity AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState -> Identity ScenarioState)
-> PlayState -> Identity PlayState
Lens' PlayState ScenarioState
scenarioState ((ScenarioState -> Identity ScenarioState)
 -> PlayState -> Identity PlayState)
-> ((Step -> Identity Step)
    -> ScenarioState -> Identity ScenarioState)
-> (Step -> Identity Step)
-> PlayState
-> Identity PlayState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GameState -> Identity GameState)
-> ScenarioState -> Identity ScenarioState
Lens' ScenarioState GameState
gameState ((GameState -> Identity GameState)
 -> ScenarioState -> Identity ScenarioState)
-> ((Step -> Identity Step) -> GameState -> Identity GameState)
-> (Step -> Identity Step)
-> ScenarioState
-> Identity ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TemporalState -> Identity TemporalState)
-> GameState -> Identity GameState
Lens' GameState TemporalState
temporal ((TemporalState -> Identity TemporalState)
 -> GameState -> Identity GameState)
-> ((Step -> Identity Step)
    -> TemporalState -> Identity TemporalState)
-> (Step -> Identity Step)
-> GameState
-> Identity GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Step -> Identity Step) -> TemporalState -> Identity TemporalState
Lens' TemporalState Step
gameStep ((Step -> Identity Step) -> AppState -> Identity AppState)
-> Step -> EventM Name AppState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= SingleStep -> Step
RobotStep SingleStep
SBefore
      else StateC GameState (TimeIOC (LiftC IO)) () -> EventM Name AppState ()
forall (m :: * -> *) a.
(MonadState AppState m, MonadIO m) =>
StateC GameState (TimeIOC (LiftC IO)) a -> m a
zoomGameStateFromAppState StateC GameState (TimeIOC (LiftC IO)) ()
forall (sig :: (* -> *) -> * -> *) (m :: * -> *).
HasGameStepState sig m =>
m ()
finishGameTick EventM Name AppState ()
-> EventM Name AppState () -> EventM Name AppState ()
forall a b.
EventM Name AppState a
-> EventM Name AppState b -> EventM Name AppState b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> EventM Name AppState Bool -> EventM Name AppState ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void EventM Name AppState Bool
updateUI

runSingleTick :: EventM Name AppState ()
runSingleTick :: EventM Name AppState ()
runSingleTick = do
  (PlayState -> Identity PlayState) -> AppState -> Identity AppState
Lens' AppState PlayState
playState ((PlayState -> Identity PlayState)
 -> AppState -> Identity AppState)
-> ((RunStatus -> Identity RunStatus)
    -> PlayState -> Identity PlayState)
-> (RunStatus -> Identity RunStatus)
-> AppState
-> Identity AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState -> Identity ScenarioState)
-> PlayState -> Identity PlayState
Lens' PlayState ScenarioState
scenarioState ((ScenarioState -> Identity ScenarioState)
 -> PlayState -> Identity PlayState)
-> ((RunStatus -> Identity RunStatus)
    -> ScenarioState -> Identity ScenarioState)
-> (RunStatus -> Identity RunStatus)
-> PlayState
-> Identity PlayState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GameState -> Identity GameState)
-> ScenarioState -> Identity ScenarioState
Lens' ScenarioState GameState
gameState ((GameState -> Identity GameState)
 -> ScenarioState -> Identity ScenarioState)
-> ((RunStatus -> Identity RunStatus)
    -> GameState -> Identity GameState)
-> (RunStatus -> Identity RunStatus)
-> ScenarioState
-> Identity ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TemporalState -> Identity TemporalState)
-> GameState -> Identity GameState
Lens' GameState TemporalState
temporal ((TemporalState -> Identity TemporalState)
 -> GameState -> Identity GameState)
-> ((RunStatus -> Identity RunStatus)
    -> TemporalState -> Identity TemporalState)
-> (RunStatus -> Identity RunStatus)
-> GameState
-> Identity GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (RunStatus -> Identity RunStatus)
-> TemporalState -> Identity TemporalState
Lens' TemporalState RunStatus
runStatus ((RunStatus -> Identity RunStatus)
 -> AppState -> Identity AppState)
-> RunStatus -> EventM Name AppState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= RunStatus
ManualPause
  EventM Name AppState ()
runGameTickUI

-- | Adjust the ticks per second speed.
adjustTPS :: (Int -> Int -> Int) -> ScenarioState -> ScenarioState
adjustTPS :: (Int -> Int -> Int) -> ScenarioState -> ScenarioState
adjustTPS Int -> Int -> Int
(+/-) = (UIGameplay -> Identity UIGameplay)
-> ScenarioState -> Identity ScenarioState
Lens' ScenarioState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> ScenarioState -> Identity ScenarioState)
-> ((Int -> Identity Int) -> UIGameplay -> Identity UIGameplay)
-> (Int -> Identity Int)
-> ScenarioState
-> Identity ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UITiming -> Identity UITiming)
-> UIGameplay -> Identity UIGameplay
Lens' UIGameplay UITiming
uiTiming ((UITiming -> Identity UITiming)
 -> UIGameplay -> Identity UIGameplay)
-> ((Int -> Identity Int) -> UITiming -> Identity UITiming)
-> (Int -> Identity Int)
-> UIGameplay
-> Identity UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Identity Int) -> UITiming -> Identity UITiming
Lens' UITiming Int
lgTicksPerSecond ((Int -> Identity Int) -> ScenarioState -> Identity ScenarioState)
-> (Int -> Int) -> ScenarioState -> ScenarioState
forall s t a b. ASetter s t a b -> (a -> b) -> s -> t
%~ (Int -> Int -> Int
+/- Int
1)

toggleCreativeMode :: EventM Name ScenarioState ()
toggleCreativeMode :: EventM Name ScenarioState ()
toggleCreativeMode = (GameState -> Identity GameState)
-> ScenarioState -> Identity ScenarioState
Lens' ScenarioState GameState
gameState ((GameState -> Identity GameState)
 -> ScenarioState -> Identity ScenarioState)
-> ((Bool -> Identity Bool) -> GameState -> Identity GameState)
-> (Bool -> Identity Bool)
-> ScenarioState
-> Identity ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool) -> GameState -> Identity GameState
Lens' GameState Bool
creativeMode ((Bool -> Identity Bool)
 -> ScenarioState -> Identity ScenarioState)
-> (Bool -> Bool) -> EventM Name ScenarioState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Bool -> Bool
not

toggleWorldEditor :: EventM Name ScenarioState ()
toggleWorldEditor :: EventM Name ScenarioState ()
toggleWorldEditor = do
  (UIGameplay -> Identity UIGameplay)
-> ScenarioState -> Identity ScenarioState
Lens' ScenarioState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> ScenarioState -> Identity ScenarioState)
-> ((Bool -> Identity Bool) -> UIGameplay -> Identity UIGameplay)
-> (Bool -> Identity Bool)
-> ScenarioState
-> Identity ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WorldEditor Name -> Identity (WorldEditor Name))
-> UIGameplay -> Identity UIGameplay
Lens' UIGameplay (WorldEditor Name)
uiWorldEditor ((WorldEditor Name -> Identity (WorldEditor Name))
 -> UIGameplay -> Identity UIGameplay)
-> ((Bool -> Identity Bool)
    -> WorldEditor Name -> Identity (WorldEditor Name))
-> (Bool -> Identity Bool)
-> UIGameplay
-> Identity UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WorldOverdraw -> Identity WorldOverdraw)
-> WorldEditor Name -> Identity (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(WorldOverdraw -> f WorldOverdraw)
-> WorldEditor n -> f (WorldEditor n)
worldOverdraw ((WorldOverdraw -> Identity WorldOverdraw)
 -> WorldEditor Name -> Identity (WorldEditor Name))
-> ((Bool -> Identity Bool)
    -> WorldOverdraw -> Identity WorldOverdraw)
-> (Bool -> Identity Bool)
-> WorldEditor Name
-> Identity (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool) -> WorldOverdraw -> Identity WorldOverdraw
Lens' WorldOverdraw Bool
isWorldEditorEnabled ((Bool -> Identity Bool)
 -> ScenarioState -> Identity ScenarioState)
-> (Bool -> Bool) -> EventM Name ScenarioState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Bool -> Bool
not
  FocusablePanel -> EventM Name ScenarioState ()
setFocus FocusablePanel
WorldEditorPanel

toggleREPLVisibility :: EventM Name ScenarioState ()
toggleREPLVisibility :: EventM Name ScenarioState ()
toggleREPLVisibility = do
  Name -> EventM Name ScenarioState ()
forall n s. Ord n => n -> EventM n s ()
invalidateCacheEntry Name
WorldCache
  (UIGameplay -> Identity UIGameplay)
-> ScenarioState -> Identity ScenarioState
Lens' ScenarioState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> ScenarioState -> Identity ScenarioState)
-> ((Bool -> Identity Bool) -> UIGameplay -> Identity UIGameplay)
-> (Bool -> Identity Bool)
-> ScenarioState
-> Identity ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool) -> UIGameplay -> Identity UIGameplay
Lens' UIGameplay Bool
uiShowREPL ((Bool -> Identity Bool)
 -> ScenarioState -> Identity ScenarioState)
-> (Bool -> Bool) -> EventM Name ScenarioState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Bool -> Bool
not

viewBase :: EventM Name ScenarioState ()
viewBase :: EventM Name ScenarioState ()
viewBase = do
  Name -> EventM Name ScenarioState ()
forall n s. Ord n => n -> EventM n s ()
invalidateCacheEntry Name
WorldCache
  (GameState -> Identity GameState)
-> ScenarioState -> Identity ScenarioState
Lens' ScenarioState GameState
gameState ((GameState -> Identity GameState)
 -> ScenarioState -> Identity ScenarioState)
-> ((ViewCenterRule -> Identity ViewCenterRule)
    -> GameState -> Identity GameState)
-> (ViewCenterRule -> Identity ViewCenterRule)
-> ScenarioState
-> Identity ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Robots -> Identity Robots) -> GameState -> Identity GameState
Lens' GameState Robots
robotInfo ((Robots -> Identity Robots) -> GameState -> Identity GameState)
-> ((ViewCenterRule -> Identity ViewCenterRule)
    -> Robots -> Identity Robots)
-> (ViewCenterRule -> Identity ViewCenterRule)
-> GameState
-> Identity GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ViewCenterRule -> Identity ViewCenterRule)
-> Robots -> Identity Robots
Lens' Robots ViewCenterRule
viewCenterRule ((ViewCenterRule -> Identity ViewCenterRule)
 -> ScenarioState -> Identity ScenarioState)
-> ViewCenterRule -> EventM Name ScenarioState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Int -> ViewCenterRule
VCRobot Int
0

toggleFPS :: EventM Name ScenarioState ()
toggleFPS :: EventM Name ScenarioState ()
toggleFPS = (UIGameplay -> Identity UIGameplay)
-> ScenarioState -> Identity ScenarioState
Lens' ScenarioState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> ScenarioState -> Identity ScenarioState)
-> ((Bool -> Identity Bool) -> UIGameplay -> Identity UIGameplay)
-> (Bool -> Identity Bool)
-> ScenarioState
-> Identity ScenarioState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UITiming -> Identity UITiming)
-> UIGameplay -> Identity UIGameplay
Lens' UIGameplay UITiming
uiTiming ((UITiming -> Identity UITiming)
 -> UIGameplay -> Identity UIGameplay)
-> ((Bool -> Identity Bool) -> UITiming -> Identity UITiming)
-> (Bool -> Identity Bool)
-> UIGameplay
-> Identity UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Identity Bool) -> UITiming -> Identity UITiming
Lens' UITiming Bool
uiShowFPS ((Bool -> Identity Bool)
 -> ScenarioState -> Identity ScenarioState)
-> (Bool -> Bool) -> EventM Name ScenarioState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Bool -> Bool
not

-- ----------------------------------------------
--                 HELPER UTILS
-- ----------------------------------------------

isRunning :: EventM Name ScenarioState Bool
isRunning :: EventM Name ScenarioState Bool
isRunning = do
  Maybe ModalType
mt <- Getting (First ModalType) ScenarioState ModalType
-> EventM Name ScenarioState (Maybe ModalType)
forall s (m :: * -> *) a.
MonadState s m =>
Getting (First a) s a -> m (Maybe a)
preuse (Getting (First ModalType) ScenarioState ModalType
 -> EventM Name ScenarioState (Maybe ModalType))
-> Getting (First ModalType) ScenarioState ModalType
-> EventM Name ScenarioState (Maybe ModalType)
forall a b. (a -> b) -> a -> b
$ (UIGameplay -> Const (First ModalType) UIGameplay)
-> ScenarioState -> Const (First ModalType) ScenarioState
Lens' ScenarioState UIGameplay
uiGameplay ((UIGameplay -> Const (First ModalType) UIGameplay)
 -> ScenarioState -> Const (First ModalType) ScenarioState)
-> ((ModalType -> Const (First ModalType) ModalType)
    -> UIGameplay -> Const (First ModalType) UIGameplay)
-> Getting (First ModalType) ScenarioState ModalType
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIDialogs -> Const (First ModalType) UIDialogs)
-> UIGameplay -> Const (First ModalType) UIGameplay
Lens' UIGameplay UIDialogs
uiDialogs ((UIDialogs -> Const (First ModalType) UIDialogs)
 -> UIGameplay -> Const (First ModalType) UIGameplay)
-> ((ModalType -> Const (First ModalType) ModalType)
    -> UIDialogs -> Const (First ModalType) UIDialogs)
-> (ModalType -> Const (First ModalType) ModalType)
-> UIGameplay
-> Const (First ModalType) UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Modal -> Const (First ModalType) (Maybe Modal))
-> UIDialogs -> Const (First ModalType) UIDialogs
Lens' UIDialogs (Maybe Modal)
uiModal ((Maybe Modal -> Const (First ModalType) (Maybe Modal))
 -> UIDialogs -> Const (First ModalType) UIDialogs)
-> ((ModalType -> Const (First ModalType) ModalType)
    -> Maybe Modal -> Const (First ModalType) (Maybe Modal))
-> (ModalType -> Const (First ModalType) ModalType)
-> UIDialogs
-> Const (First ModalType) UIDialogs
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Modal -> Const (First ModalType) Modal)
-> Maybe Modal -> Const (First ModalType) (Maybe Modal)
forall a b (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p a (f b) -> p (Maybe a) (f (Maybe b))
_Just ((Modal -> Const (First ModalType) Modal)
 -> Maybe Modal -> Const (First ModalType) (Maybe Modal))
-> ((ModalType -> Const (First ModalType) ModalType)
    -> Modal -> Const (First ModalType) Modal)
-> (ModalType -> Const (First ModalType) ModalType)
-> Maybe Modal
-> Const (First ModalType) (Maybe Modal)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ModalType -> Const (First ModalType) ModalType)
-> Modal -> Const (First ModalType) Modal
Lens' Modal ModalType
modalType
  Bool -> EventM Name ScenarioState Bool
forall a. a -> EventM Name ScenarioState a
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> EventM Name ScenarioState Bool)
-> Bool -> EventM Name ScenarioState Bool
forall a b. (a -> b) -> a -> b
$ Bool -> (ModalType -> Bool) -> Maybe ModalType -> Bool
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Bool
True ModalType -> Bool
isRunningModal Maybe ModalType
mt

whenRunningAppState :: EventM Name AppState () -> EventM Name AppState ()
whenRunningAppState :: EventM Name AppState () -> EventM Name AppState ()
whenRunningAppState EventM Name AppState ()
a = LensLike'
  (Zoomed (EventM Name ScenarioState) Bool) AppState ScenarioState
-> EventM Name ScenarioState Bool -> EventM Name AppState Bool
forall c.
LensLike'
  (Zoomed (EventM Name ScenarioState) c) AppState ScenarioState
-> EventM Name ScenarioState c -> EventM Name AppState c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom ((PlayState
 -> Focusing (StateT (EventState Name) IO) Bool PlayState)
-> AppState -> Focusing (StateT (EventState Name) IO) Bool AppState
Lens' AppState PlayState
playState ((PlayState
  -> Focusing (StateT (EventState Name) IO) Bool PlayState)
 -> AppState
 -> Focusing (StateT (EventState Name) IO) Bool AppState)
-> ((ScenarioState
     -> Focusing (StateT (EventState Name) IO) Bool ScenarioState)
    -> PlayState
    -> Focusing (StateT (EventState Name) IO) Bool PlayState)
-> (ScenarioState
    -> Focusing (StateT (EventState Name) IO) Bool ScenarioState)
-> AppState
-> Focusing (StateT (EventState Name) IO) Bool AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ScenarioState
 -> Focusing (StateT (EventState Name) IO) Bool ScenarioState)
-> PlayState
-> Focusing (StateT (EventState Name) IO) Bool PlayState
Lens' PlayState ScenarioState
scenarioState) EventM Name ScenarioState Bool
isRunning EventM Name AppState Bool
-> (Bool -> EventM Name AppState ()) -> EventM Name AppState ()
forall a b.
EventM Name AppState a
-> (a -> EventM Name AppState b) -> EventM Name AppState b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
r -> Bool -> EventM Name AppState () -> EventM Name AppState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
r EventM Name AppState ()
a

whenRunningPlayState :: EventM Name ScenarioState () -> EventM Name ScenarioState ()
whenRunningPlayState :: EventM Name ScenarioState () -> EventM Name ScenarioState ()
whenRunningPlayState EventM Name ScenarioState ()
a = EventM Name ScenarioState Bool
isRunning EventM Name ScenarioState Bool
-> (Bool -> EventM Name ScenarioState ())
-> EventM Name ScenarioState ()
forall a b.
EventM Name ScenarioState a
-> (a -> EventM Name ScenarioState b)
-> EventM Name ScenarioState b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
r -> Bool
-> EventM Name ScenarioState () -> EventM Name ScenarioState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
r EventM Name ScenarioState ()
a

whenDebug :: DebugOption -> EventM Name AppState () -> EventM Name AppState ()
whenDebug :: DebugOption -> EventM Name AppState () -> EventM Name AppState ()
whenDebug DebugOption
d EventM Name AppState ()
a = do
  Bool
debug <- Getting Bool AppState Bool -> EventM Name AppState Bool
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting Bool AppState Bool -> EventM Name AppState Bool)
-> Getting Bool AppState Bool -> EventM Name AppState Bool
forall a b. (a -> b) -> a -> b
$ (UIState -> Const Bool UIState) -> AppState -> Const Bool AppState
Lens' AppState UIState
uiState ((UIState -> Const Bool UIState)
 -> AppState -> Const Bool AppState)
-> ((Bool -> Const Bool Bool) -> UIState -> Const Bool UIState)
-> Getting Bool AppState Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Set DebugOption -> Const Bool (Set DebugOption))
-> UIState -> Const Bool UIState
Lens' UIState (Set DebugOption)
uiDebugOptions ((Set DebugOption -> Const Bool (Set DebugOption))
 -> UIState -> Const Bool UIState)
-> ((Bool -> Const Bool Bool)
    -> Set DebugOption -> Const Bool (Set DebugOption))
-> (Bool -> Const Bool Bool)
-> UIState
-> Const Bool UIState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Index (Set DebugOption) -> Lens' (Set DebugOption) Bool
forall m. Contains m => Index m -> Lens' m Bool
contains Index (Set DebugOption)
DebugOption
d
  Bool -> EventM Name AppState () -> EventM Name AppState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
debug EventM Name AppState ()
a