{-# LANGUAGE OverloadedStrings #-}

-- |
-- SPDX-License-Identifier: BSD-3-Clause
module Swarm.TUI.Editor.Controller where

import Brick hiding (Direction (..), Location (..))
import Brick qualified as B
import Brick.Focus
import Brick.Widgets.List qualified as BL
import Control.Lens
import Control.Monad (forM_, guard, when)
import Control.Monad.Extra (whenJust)
import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Maybe (MaybeT (..), runMaybeT)
import Data.Map qualified as M
import Data.Yaml qualified as Y
import Graphics.Vty qualified as V
import Swarm.Game.Land
import Swarm.Game.Scenario.Topography.EntityFacade
import Swarm.Game.State
import Swarm.Game.State.Landscape
import Swarm.Game.Universe
import Swarm.Game.World.Coords
import Swarm.TUI.Controller.Util
import Swarm.TUI.Editor.Model
import Swarm.TUI.Editor.Palette
import Swarm.TUI.Editor.Util qualified as EU
import Swarm.TUI.Model
import Swarm.TUI.Model.Name
import Swarm.TUI.Model.UI
import Swarm.Util (hoistMaybe)
import Swarm.Util.Erasable (maybeToErasable)
import System.Clock

------------------------------------------------------------
-- World Editor panel events
------------------------------------------------------------

activateWorldEditorFunction :: WorldEditorFocusable -> EventM Name AppState ()
activateWorldEditorFunction :: WorldEditorFocusable -> EventM Name AppState ()
activateWorldEditorFunction WorldEditorFocusable
BrushSelector = ModalType -> EventM Name AppState ()
openModal ModalType
TerrainPaletteModal
activateWorldEditorFunction WorldEditorFocusable
EntitySelector = ModalType -> EventM Name AppState ()
openModal ModalType
EntityPaletteModal
activateWorldEditorFunction WorldEditorFocusable
AreaSelector = do
  BoundsSelectionStep
selectorStage <- Getting BoundsSelectionStep AppState BoundsSelectionStep
-> EventM Name AppState BoundsSelectionStep
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting BoundsSelectionStep AppState BoundsSelectionStep
 -> EventM Name AppState BoundsSelectionStep)
-> Getting BoundsSelectionStep AppState BoundsSelectionStep
-> EventM Name AppState BoundsSelectionStep
forall a b. (a -> b) -> a -> b
$ (UIState -> Const BoundsSelectionStep UIState)
-> AppState -> Const BoundsSelectionStep AppState
Lens' AppState UIState
uiState ((UIState -> Const BoundsSelectionStep UIState)
 -> AppState -> Const BoundsSelectionStep AppState)
-> ((BoundsSelectionStep
     -> Const BoundsSelectionStep BoundsSelectionStep)
    -> UIState -> Const BoundsSelectionStep UIState)
-> Getting BoundsSelectionStep AppState BoundsSelectionStep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Const BoundsSelectionStep UIGameplay)
-> UIState -> Const BoundsSelectionStep UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Const BoundsSelectionStep UIGameplay)
 -> UIState -> Const BoundsSelectionStep UIState)
-> ((BoundsSelectionStep
     -> Const BoundsSelectionStep BoundsSelectionStep)
    -> UIGameplay -> Const BoundsSelectionStep UIGameplay)
-> (BoundsSelectionStep
    -> Const BoundsSelectionStep BoundsSelectionStep)
-> UIState
-> Const BoundsSelectionStep UIState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WorldEditor Name -> Const BoundsSelectionStep (WorldEditor Name))
-> UIGameplay -> Const BoundsSelectionStep UIGameplay
Lens' UIGameplay (WorldEditor Name)
uiWorldEditor ((WorldEditor Name -> Const BoundsSelectionStep (WorldEditor Name))
 -> UIGameplay -> Const BoundsSelectionStep UIGameplay)
-> ((BoundsSelectionStep
     -> Const BoundsSelectionStep BoundsSelectionStep)
    -> WorldEditor Name
    -> Const BoundsSelectionStep (WorldEditor Name))
-> (BoundsSelectionStep
    -> Const BoundsSelectionStep BoundsSelectionStep)
-> UIGameplay
-> Const BoundsSelectionStep UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MapEditingBounds -> Const BoundsSelectionStep MapEditingBounds)
-> WorldEditor Name -> Const BoundsSelectionStep (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(MapEditingBounds -> f MapEditingBounds)
-> WorldEditor n -> f (WorldEditor n)
editingBounds ((MapEditingBounds -> Const BoundsSelectionStep MapEditingBounds)
 -> WorldEditor Name
 -> Const BoundsSelectionStep (WorldEditor Name))
-> ((BoundsSelectionStep
     -> Const BoundsSelectionStep BoundsSelectionStep)
    -> MapEditingBounds -> Const BoundsSelectionStep MapEditingBounds)
-> (BoundsSelectionStep
    -> Const BoundsSelectionStep BoundsSelectionStep)
-> WorldEditor Name
-> Const BoundsSelectionStep (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BoundsSelectionStep
 -> Const BoundsSelectionStep BoundsSelectionStep)
-> MapEditingBounds -> Const BoundsSelectionStep MapEditingBounds
Lens' MapEditingBounds BoundsSelectionStep
boundsSelectionStep
  case BoundsSelectionStep
selectorStage of
    BoundsSelectionStep
SelectionComplete -> (UIState -> Identity UIState) -> AppState -> Identity AppState
Lens' AppState UIState
uiState ((UIState -> Identity UIState) -> AppState -> Identity AppState)
-> ((BoundsSelectionStep -> Identity BoundsSelectionStep)
    -> UIState -> Identity UIState)
-> (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> AppState
-> Identity AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Identity UIGameplay) -> UIState -> Identity UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> UIState -> Identity UIState)
-> ((BoundsSelectionStep -> Identity BoundsSelectionStep)
    -> UIGameplay -> Identity UIGameplay)
-> (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> UIState
-> Identity UIState
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)
-> ((BoundsSelectionStep -> Identity BoundsSelectionStep)
    -> WorldEditor Name -> Identity (WorldEditor Name))
-> (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> UIGameplay
-> Identity UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MapEditingBounds -> Identity MapEditingBounds)
-> WorldEditor Name -> Identity (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(MapEditingBounds -> f MapEditingBounds)
-> WorldEditor n -> f (WorldEditor n)
editingBounds ((MapEditingBounds -> Identity MapEditingBounds)
 -> WorldEditor Name -> Identity (WorldEditor Name))
-> ((BoundsSelectionStep -> Identity BoundsSelectionStep)
    -> MapEditingBounds -> Identity MapEditingBounds)
-> (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> WorldEditor Name
-> Identity (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> MapEditingBounds -> Identity MapEditingBounds
Lens' MapEditingBounds BoundsSelectionStep
boundsSelectionStep ((BoundsSelectionStep -> Identity BoundsSelectionStep)
 -> AppState -> Identity AppState)
-> BoundsSelectionStep -> EventM Name AppState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= BoundsSelectionStep
UpperLeftPending
    BoundsSelectionStep
_ -> () -> EventM Name AppState ()
forall a. a -> EventM Name AppState a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
activateWorldEditorFunction WorldEditorFocusable
OutputPathSelector =
  -- TODO: #1371
  IO () -> EventM Name AppState ()
forall a. IO a -> EventM Name AppState a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> EventM Name AppState ())
-> IO () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ String -> IO ()
putStrLn String
"File selection"
activateWorldEditorFunction WorldEditorFocusable
MapSaveButton = EventM Name AppState ()
saveMapFile
activateWorldEditorFunction WorldEditorFocusable
ClearEntityButton =
  (UIState -> Identity UIState) -> AppState -> Identity AppState
Lens' AppState UIState
uiState ((UIState -> Identity UIState) -> AppState -> Identity AppState)
-> ((Maybe Int -> Identity (Maybe Int))
    -> UIState -> Identity UIState)
-> (Maybe Int -> Identity (Maybe Int))
-> AppState
-> Identity AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Identity UIGameplay) -> UIState -> Identity UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> UIState -> Identity UIState)
-> ((Maybe Int -> Identity (Maybe Int))
    -> UIGameplay -> Identity UIGameplay)
-> (Maybe Int -> Identity (Maybe Int))
-> UIState
-> Identity UIState
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)
-> ((Maybe Int -> Identity (Maybe Int))
    -> WorldEditor Name -> Identity (WorldEditor Name))
-> (Maybe Int -> Identity (Maybe Int))
-> UIGameplay
-> Identity UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (List Name EntityFacade -> Identity (List Name EntityFacade))
-> WorldEditor Name -> Identity (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(List n EntityFacade -> f (List n EntityFacade))
-> WorldEditor n -> f (WorldEditor n)
entityPaintList ((List Name EntityFacade -> Identity (List Name EntityFacade))
 -> WorldEditor Name -> Identity (WorldEditor Name))
-> ((Maybe Int -> Identity (Maybe Int))
    -> List Name EntityFacade -> Identity (List Name EntityFacade))
-> (Maybe Int -> Identity (Maybe Int))
-> WorldEditor Name
-> Identity (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe Int -> Identity (Maybe Int))
-> List Name EntityFacade -> Identity (List Name EntityFacade)
forall n (t :: * -> *) e (f :: * -> *).
Functor f =>
(Maybe Int -> f (Maybe Int))
-> GenericList n t e -> f (GenericList n t e)
BL.listSelectedL ((Maybe Int -> Identity (Maybe Int))
 -> AppState -> Identity AppState)
-> Maybe Int -> EventM Name AppState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Maybe Int
forall a. Maybe a
Nothing

handleCtrlLeftClick :: B.Location -> EventM Name AppState ()
handleCtrlLeftClick :: Location -> EventM Name AppState ()
handleCtrlLeftClick Location
mouseLoc = do
  WorldEditor Name
worldEditor <- Getting (WorldEditor Name) AppState (WorldEditor Name)
-> EventM Name AppState (WorldEditor Name)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting (WorldEditor Name) AppState (WorldEditor Name)
 -> EventM Name AppState (WorldEditor Name))
-> Getting (WorldEditor Name) AppState (WorldEditor Name)
-> EventM Name AppState (WorldEditor Name)
forall a b. (a -> b) -> a -> b
$ (UIState -> Const (WorldEditor Name) UIState)
-> AppState -> Const (WorldEditor Name) AppState
Lens' AppState UIState
uiState ((UIState -> Const (WorldEditor Name) UIState)
 -> AppState -> Const (WorldEditor Name) AppState)
-> ((WorldEditor Name
     -> Const (WorldEditor Name) (WorldEditor Name))
    -> UIState -> Const (WorldEditor Name) UIState)
-> Getting (WorldEditor Name) AppState (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Const (WorldEditor Name) UIGameplay)
-> UIState -> Const (WorldEditor Name) UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Const (WorldEditor Name) UIGameplay)
 -> UIState -> Const (WorldEditor Name) UIState)
-> ((WorldEditor Name
     -> Const (WorldEditor Name) (WorldEditor Name))
    -> UIGameplay -> Const (WorldEditor Name) UIGameplay)
-> (WorldEditor Name
    -> Const (WorldEditor Name) (WorldEditor Name))
-> UIState
-> Const (WorldEditor Name) UIState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WorldEditor Name -> Const (WorldEditor Name) (WorldEditor Name))
-> UIGameplay -> Const (WorldEditor Name) UIGameplay
Lens' UIGameplay (WorldEditor Name)
uiWorldEditor
  Maybe ()
_ <- MaybeT (EventM Name AppState) () -> EventM Name AppState (Maybe ())
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT (EventM Name AppState) ()
 -> EventM Name AppState (Maybe ()))
-> MaybeT (EventM Name AppState) ()
-> EventM Name AppState (Maybe ())
forall a b. (a -> b) -> a -> b
$ do
    Bool -> MaybeT (EventM Name AppState) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> MaybeT (EventM Name AppState) ())
-> Bool -> MaybeT (EventM Name AppState) ()
forall a b. (a -> b) -> a -> b
$ WorldEditor Name
worldEditor WorldEditor Name -> Getting Bool (WorldEditor Name) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WorldOverdraw -> Const Bool WorldOverdraw)
-> WorldEditor Name -> Const Bool (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(WorldOverdraw -> f WorldOverdraw)
-> WorldEditor n -> f (WorldEditor n)
worldOverdraw ((WorldOverdraw -> Const Bool WorldOverdraw)
 -> WorldEditor Name -> Const Bool (WorldEditor Name))
-> ((Bool -> Const Bool Bool)
    -> WorldOverdraw -> Const Bool WorldOverdraw)
-> Getting Bool (WorldEditor Name) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WorldOverdraw -> Const Bool WorldOverdraw
Lens' WorldOverdraw Bool
isWorldEditorEnabled
    let getSelected :: GenericList n t b -> Maybe b
getSelected GenericList n t b
x = (Int, b) -> b
forall a b. (a, b) -> b
snd ((Int, b) -> b) -> Maybe (Int, b) -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> GenericList n t b -> Maybe (Int, b)
forall (t :: * -> *) e n.
(Splittable t, Traversable t, Semigroup (t e)) =>
GenericList n t e -> Maybe (Int, e)
BL.listSelectedElement GenericList n t b
x
        maybeTerrainType :: Maybe TerrainType
maybeTerrainType = GenericList Name Vector TerrainType -> Maybe TerrainType
forall {t :: * -> *} {b} {n}.
(Splittable t, Traversable t, Semigroup (t b)) =>
GenericList n t b -> Maybe b
getSelected (GenericList Name Vector TerrainType -> Maybe TerrainType)
-> GenericList Name Vector TerrainType -> Maybe TerrainType
forall a b. (a -> b) -> a -> b
$ WorldEditor Name
worldEditor WorldEditor Name
-> Getting
     (GenericList Name Vector TerrainType)
     (WorldEditor Name)
     (GenericList Name Vector TerrainType)
-> GenericList Name Vector TerrainType
forall s a. s -> Getting a s a -> a
^. Getting
  (GenericList Name Vector TerrainType)
  (WorldEditor Name)
  (GenericList Name Vector TerrainType)
forall n (f :: * -> *).
Functor f =>
(List n TerrainType -> f (List n TerrainType))
-> WorldEditor n -> f (WorldEditor n)
terrainList
        maybeEntityPaint :: Maybe EntityFacade
maybeEntityPaint = List Name EntityFacade -> Maybe EntityFacade
forall {t :: * -> *} {b} {n}.
(Splittable t, Traversable t, Semigroup (t b)) =>
GenericList n t b -> Maybe b
getSelected (List Name EntityFacade -> Maybe EntityFacade)
-> List Name EntityFacade -> Maybe EntityFacade
forall a b. (a -> b) -> a -> b
$ WorldEditor Name
worldEditor WorldEditor Name
-> Getting
     (List Name EntityFacade)
     (WorldEditor Name)
     (List Name EntityFacade)
-> List Name EntityFacade
forall s a. s -> Getting a s a -> a
^. Getting
  (List Name EntityFacade)
  (WorldEditor Name)
  (List Name EntityFacade)
forall n (f :: * -> *).
Functor f =>
(List n EntityFacade -> f (List n EntityFacade))
-> WorldEditor n -> f (WorldEditor n)
entityPaintList
    TerrainType
terrain <- Maybe TerrainType -> MaybeT (EventM Name AppState) TerrainType
forall (m :: * -> *) b. Applicative m => Maybe b -> MaybeT m b
hoistMaybe Maybe TerrainType
maybeTerrainType
    Cosmic Coords
mouseCoords <- EventM Name AppState (Maybe (Cosmic Coords))
-> MaybeT (EventM Name AppState) (Cosmic Coords)
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (EventM Name AppState (Maybe (Cosmic Coords))
 -> MaybeT (EventM Name AppState) (Cosmic Coords))
-> EventM Name AppState (Maybe (Cosmic Coords))
-> MaybeT (EventM Name AppState) (Cosmic Coords)
forall a b. (a -> b) -> a -> b
$ LensLike'
  (Zoomed (EventM Name GameState) (Maybe (Cosmic Coords)))
  AppState
  GameState
-> EventM Name GameState (Maybe (Cosmic Coords))
-> EventM Name AppState (Maybe (Cosmic Coords))
forall c.
LensLike' (Zoomed (EventM Name GameState) c) AppState GameState
-> EventM Name GameState 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 (GameState
 -> Focusing
      (StateT (EventState Name) IO) (Maybe (Cosmic Coords)) GameState)
-> AppState
-> Focusing
     (StateT (EventState Name) IO) (Maybe (Cosmic Coords)) AppState
LensLike'
  (Zoomed (EventM Name GameState) (Maybe (Cosmic Coords)))
  AppState
  GameState
Lens' AppState GameState
gameState (EventM Name GameState (Maybe (Cosmic Coords))
 -> EventM Name AppState (Maybe (Cosmic Coords)))
-> EventM Name GameState (Maybe (Cosmic Coords))
-> EventM Name AppState (Maybe (Cosmic Coords))
forall a b. (a -> b) -> a -> b
$ Location -> EventM Name GameState (Maybe (Cosmic Coords))
mouseLocToWorldCoords Location
mouseLoc
    LensLike'
  (Zoomed (MaybeT (EventM Name (WorldEditor Name))) ())
  AppState
  (WorldEditor Name)
-> MaybeT (EventM Name (WorldEditor Name)) ()
-> MaybeT (EventM Name AppState) ()
forall c.
LensLike'
  (Zoomed (MaybeT (EventM Name (WorldEditor Name))) c)
  AppState
  (WorldEditor Name)
-> MaybeT (EventM Name (WorldEditor Name)) c
-> MaybeT (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 ((UIState
 -> Zoomed (MaybeT (EventM Name (WorldEditor Name))) () UIState)
-> AppState
-> Zoomed (MaybeT (EventM Name (WorldEditor Name))) () AppState
Lens' AppState UIState
uiState ((UIState
  -> Zoomed (MaybeT (EventM Name (WorldEditor Name))) () UIState)
 -> AppState
 -> Zoomed (MaybeT (EventM Name (WorldEditor Name))) () AppState)
-> ((WorldEditor Name
     -> Zoomed
          (MaybeT (EventM Name (WorldEditor Name))) () (WorldEditor Name))
    -> UIState
    -> Zoomed (MaybeT (EventM Name (WorldEditor Name))) () UIState)
-> LensLike'
     (Zoomed (MaybeT (EventM Name (WorldEditor Name))) ())
     AppState
     (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay
 -> Zoomed (MaybeT (EventM Name (WorldEditor Name))) () UIGameplay)
-> UIState
-> Zoomed (MaybeT (EventM Name (WorldEditor Name))) () UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay
  -> Zoomed (MaybeT (EventM Name (WorldEditor Name))) () UIGameplay)
 -> UIState
 -> Zoomed (MaybeT (EventM Name (WorldEditor Name))) () UIState)
-> ((WorldEditor Name
     -> Zoomed
          (MaybeT (EventM Name (WorldEditor Name))) () (WorldEditor Name))
    -> UIGameplay
    -> Zoomed (MaybeT (EventM Name (WorldEditor Name))) () UIGameplay)
-> (WorldEditor Name
    -> Zoomed
         (MaybeT (EventM Name (WorldEditor Name))) () (WorldEditor Name))
-> UIState
-> Zoomed (MaybeT (EventM Name (WorldEditor Name))) () UIState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WorldEditor Name
 -> Zoomed
      (MaybeT (EventM Name (WorldEditor Name))) () (WorldEditor Name))
-> UIGameplay
-> Zoomed (MaybeT (EventM Name (WorldEditor Name))) () UIGameplay
Lens' UIGameplay (WorldEditor Name)
uiWorldEditor) (MaybeT (EventM Name (WorldEditor Name)) ()
 -> MaybeT (EventM Name AppState) ())
-> MaybeT (EventM Name (WorldEditor Name)) ()
-> MaybeT (EventM Name AppState) ()
forall a b. (a -> b) -> a -> b
$ do
      (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))
-> ((Map Coords (TerrainWith EntityFacade)
     -> Identity (Map Coords (TerrainWith EntityFacade)))
    -> WorldOverdraw -> Identity WorldOverdraw)
-> (Map Coords (TerrainWith EntityFacade)
    -> Identity (Map Coords (TerrainWith EntityFacade)))
-> WorldEditor Name
-> Identity (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map Coords (TerrainWith EntityFacade)
 -> Identity (Map Coords (TerrainWith EntityFacade)))
-> WorldOverdraw -> Identity WorldOverdraw
Lens' WorldOverdraw (Map Coords (TerrainWith EntityFacade))
paintedTerrain ((Map Coords (TerrainWith EntityFacade)
  -> Identity (Map Coords (TerrainWith EntityFacade)))
 -> WorldEditor Name -> Identity (WorldEditor Name))
-> (Map Coords (TerrainWith EntityFacade)
    -> Map Coords (TerrainWith EntityFacade))
-> MaybeT (EventM Name (WorldEditor Name)) ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Coords
-> TerrainWith EntityFacade
-> Map Coords (TerrainWith EntityFacade)
-> Map Coords (TerrainWith EntityFacade)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert (Cosmic Coords
mouseCoords Cosmic Coords -> Getting Coords (Cosmic Coords) Coords -> Coords
forall s a. s -> Getting a s a -> a
^. Getting Coords (Cosmic Coords) Coords
forall a1 a2 (f :: * -> *).
Functor f =>
(a1 -> f a2) -> Cosmic a1 -> f (Cosmic a2)
planar) (TerrainType
terrain, Maybe EntityFacade -> Erasable EntityFacade
forall e. Maybe e -> Erasable e
maybeToErasable Maybe EntityFacade
maybeEntityPaint)
      (Maybe String -> Identity (Maybe String))
-> WorldEditor Name -> Identity (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(Maybe String -> f (Maybe String))
-> WorldEditor n -> f (WorldEditor n)
lastWorldEditorMessage ((Maybe String -> Identity (Maybe String))
 -> WorldEditor Name -> Identity (WorldEditor Name))
-> Maybe String -> MaybeT (EventM Name (WorldEditor Name)) ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Maybe String
forall a. Maybe a
Nothing
  EventM Name AppState ()
immediatelyRedrawWorld
  () -> EventM Name AppState ()
forall a. a -> EventM Name AppState a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

handleRightClick :: B.Location -> EventM Name AppState ()
handleRightClick :: Location -> EventM Name AppState ()
handleRightClick Location
mouseLoc = do
  WorldEditor Name
worldEditor <- Getting (WorldEditor Name) AppState (WorldEditor Name)
-> EventM Name AppState (WorldEditor Name)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting (WorldEditor Name) AppState (WorldEditor Name)
 -> EventM Name AppState (WorldEditor Name))
-> Getting (WorldEditor Name) AppState (WorldEditor Name)
-> EventM Name AppState (WorldEditor Name)
forall a b. (a -> b) -> a -> b
$ (UIState -> Const (WorldEditor Name) UIState)
-> AppState -> Const (WorldEditor Name) AppState
Lens' AppState UIState
uiState ((UIState -> Const (WorldEditor Name) UIState)
 -> AppState -> Const (WorldEditor Name) AppState)
-> ((WorldEditor Name
     -> Const (WorldEditor Name) (WorldEditor Name))
    -> UIState -> Const (WorldEditor Name) UIState)
-> Getting (WorldEditor Name) AppState (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Const (WorldEditor Name) UIGameplay)
-> UIState -> Const (WorldEditor Name) UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Const (WorldEditor Name) UIGameplay)
 -> UIState -> Const (WorldEditor Name) UIState)
-> ((WorldEditor Name
     -> Const (WorldEditor Name) (WorldEditor Name))
    -> UIGameplay -> Const (WorldEditor Name) UIGameplay)
-> (WorldEditor Name
    -> Const (WorldEditor Name) (WorldEditor Name))
-> UIState
-> Const (WorldEditor Name) UIState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WorldEditor Name -> Const (WorldEditor Name) (WorldEditor Name))
-> UIGameplay -> Const (WorldEditor Name) UIGameplay
Lens' UIGameplay (WorldEditor Name)
uiWorldEditor
  Maybe ()
_ <- MaybeT (EventM Name AppState) () -> EventM Name AppState (Maybe ())
forall (m :: * -> *) a. MaybeT m a -> m (Maybe a)
runMaybeT (MaybeT (EventM Name AppState) ()
 -> EventM Name AppState (Maybe ()))
-> MaybeT (EventM Name AppState) ()
-> EventM Name AppState (Maybe ())
forall a b. (a -> b) -> a -> b
$ do
    Bool -> MaybeT (EventM Name AppState) ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (Bool -> MaybeT (EventM Name AppState) ())
-> Bool -> MaybeT (EventM Name AppState) ()
forall a b. (a -> b) -> a -> b
$ WorldEditor Name
worldEditor WorldEditor Name -> Getting Bool (WorldEditor Name) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WorldOverdraw -> Const Bool WorldOverdraw)
-> WorldEditor Name -> Const Bool (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(WorldOverdraw -> f WorldOverdraw)
-> WorldEditor n -> f (WorldEditor n)
worldOverdraw ((WorldOverdraw -> Const Bool WorldOverdraw)
 -> WorldEditor Name -> Const Bool (WorldEditor Name))
-> ((Bool -> Const Bool Bool)
    -> WorldOverdraw -> Const Bool WorldOverdraw)
-> Getting Bool (WorldEditor Name) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WorldOverdraw -> Const Bool WorldOverdraw
Lens' WorldOverdraw Bool
isWorldEditorEnabled
    Cosmic Coords
mouseCoords <- EventM Name AppState (Maybe (Cosmic Coords))
-> MaybeT (EventM Name AppState) (Cosmic Coords)
forall (m :: * -> *) a. m (Maybe a) -> MaybeT m a
MaybeT (EventM Name AppState (Maybe (Cosmic Coords))
 -> MaybeT (EventM Name AppState) (Cosmic Coords))
-> EventM Name AppState (Maybe (Cosmic Coords))
-> MaybeT (EventM Name AppState) (Cosmic Coords)
forall a b. (a -> b) -> a -> b
$ LensLike'
  (Zoomed (EventM Name GameState) (Maybe (Cosmic Coords)))
  AppState
  GameState
-> EventM Name GameState (Maybe (Cosmic Coords))
-> EventM Name AppState (Maybe (Cosmic Coords))
forall c.
LensLike' (Zoomed (EventM Name GameState) c) AppState GameState
-> EventM Name GameState 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 (GameState
 -> Focusing
      (StateT (EventState Name) IO) (Maybe (Cosmic Coords)) GameState)
-> AppState
-> Focusing
     (StateT (EventState Name) IO) (Maybe (Cosmic Coords)) AppState
LensLike'
  (Zoomed (EventM Name GameState) (Maybe (Cosmic Coords)))
  AppState
  GameState
Lens' AppState GameState
gameState (EventM Name GameState (Maybe (Cosmic Coords))
 -> EventM Name AppState (Maybe (Cosmic Coords)))
-> EventM Name GameState (Maybe (Cosmic Coords))
-> EventM Name AppState (Maybe (Cosmic Coords))
forall a b. (a -> b) -> a -> b
$ Location -> EventM Name GameState (Maybe (Cosmic Coords))
mouseLocToWorldCoords Location
mouseLoc
    (UIState -> Identity UIState) -> AppState -> Identity AppState
Lens' AppState UIState
uiState ((UIState -> Identity UIState) -> AppState -> Identity AppState)
-> ((Map Coords (TerrainWith EntityFacade)
     -> Identity (Map Coords (TerrainWith EntityFacade)))
    -> UIState -> Identity UIState)
-> (Map Coords (TerrainWith EntityFacade)
    -> Identity (Map Coords (TerrainWith EntityFacade)))
-> AppState
-> Identity AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Identity UIGameplay) -> UIState -> Identity UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> UIState -> Identity UIState)
-> ((Map Coords (TerrainWith EntityFacade)
     -> Identity (Map Coords (TerrainWith EntityFacade)))
    -> UIGameplay -> Identity UIGameplay)
-> (Map Coords (TerrainWith EntityFacade)
    -> Identity (Map Coords (TerrainWith EntityFacade)))
-> UIState
-> Identity UIState
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)
-> ((Map Coords (TerrainWith EntityFacade)
     -> Identity (Map Coords (TerrainWith EntityFacade)))
    -> WorldEditor Name -> Identity (WorldEditor Name))
-> (Map Coords (TerrainWith EntityFacade)
    -> Identity (Map Coords (TerrainWith EntityFacade)))
-> 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))
-> ((Map Coords (TerrainWith EntityFacade)
     -> Identity (Map Coords (TerrainWith EntityFacade)))
    -> WorldOverdraw -> Identity WorldOverdraw)
-> (Map Coords (TerrainWith EntityFacade)
    -> Identity (Map Coords (TerrainWith EntityFacade)))
-> WorldEditor Name
-> Identity (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Map Coords (TerrainWith EntityFacade)
 -> Identity (Map Coords (TerrainWith EntityFacade)))
-> WorldOverdraw -> Identity WorldOverdraw
Lens' WorldOverdraw (Map Coords (TerrainWith EntityFacade))
paintedTerrain ((Map Coords (TerrainWith EntityFacade)
  -> Identity (Map Coords (TerrainWith EntityFacade)))
 -> AppState -> Identity AppState)
-> (Map Coords (TerrainWith EntityFacade)
    -> Map Coords (TerrainWith EntityFacade))
-> MaybeT (EventM Name AppState) ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= Coords
-> Map Coords (TerrainWith EntityFacade)
-> Map Coords (TerrainWith EntityFacade)
forall k a. Ord k => k -> Map k a -> Map k a
M.delete (Cosmic Coords
mouseCoords Cosmic Coords -> Getting Coords (Cosmic Coords) Coords -> Coords
forall s a. s -> Getting a s a -> a
^. Getting Coords (Cosmic Coords) Coords
forall a1 a2 (f :: * -> *).
Functor f =>
(a1 -> f a2) -> Cosmic a1 -> f (Cosmic a2)
planar)
  EventM Name AppState ()
immediatelyRedrawWorld
  () -> EventM Name AppState ()
forall a. a -> EventM Name AppState a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | "Eye Dropper" tool:
handleMiddleClick :: B.Location -> EventM Name AppState ()
handleMiddleClick :: Location -> EventM Name AppState ()
handleMiddleClick Location
mouseLoc = do
  WorldEditor Name
worldEditor <- Getting (WorldEditor Name) AppState (WorldEditor Name)
-> EventM Name AppState (WorldEditor Name)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting (WorldEditor Name) AppState (WorldEditor Name)
 -> EventM Name AppState (WorldEditor Name))
-> Getting (WorldEditor Name) AppState (WorldEditor Name)
-> EventM Name AppState (WorldEditor Name)
forall a b. (a -> b) -> a -> b
$ (UIState -> Const (WorldEditor Name) UIState)
-> AppState -> Const (WorldEditor Name) AppState
Lens' AppState UIState
uiState ((UIState -> Const (WorldEditor Name) UIState)
 -> AppState -> Const (WorldEditor Name) AppState)
-> ((WorldEditor Name
     -> Const (WorldEditor Name) (WorldEditor Name))
    -> UIState -> Const (WorldEditor Name) UIState)
-> Getting (WorldEditor Name) AppState (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Const (WorldEditor Name) UIGameplay)
-> UIState -> Const (WorldEditor Name) UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Const (WorldEditor Name) UIGameplay)
 -> UIState -> Const (WorldEditor Name) UIState)
-> ((WorldEditor Name
     -> Const (WorldEditor Name) (WorldEditor Name))
    -> UIGameplay -> Const (WorldEditor Name) UIGameplay)
-> (WorldEditor Name
    -> Const (WorldEditor Name) (WorldEditor Name))
-> UIState
-> Const (WorldEditor Name) UIState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WorldEditor Name -> Const (WorldEditor Name) (WorldEditor Name))
-> UIGameplay -> Const (WorldEditor Name) UIGameplay
Lens' UIGameplay (WorldEditor Name)
uiWorldEditor
  Bool -> EventM Name AppState () -> EventM Name AppState ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (WorldEditor Name
worldEditor WorldEditor Name -> Getting Bool (WorldEditor Name) Bool -> Bool
forall s a. s -> Getting a s a -> a
^. (WorldOverdraw -> Const Bool WorldOverdraw)
-> WorldEditor Name -> Const Bool (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(WorldOverdraw -> f WorldOverdraw)
-> WorldEditor n -> f (WorldEditor n)
worldOverdraw ((WorldOverdraw -> Const Bool WorldOverdraw)
 -> WorldEditor Name -> Const Bool (WorldEditor Name))
-> ((Bool -> Const Bool Bool)
    -> WorldOverdraw -> Const Bool WorldOverdraw)
-> Getting Bool (WorldEditor Name) Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Bool -> Const Bool Bool)
-> WorldOverdraw -> Const Bool WorldOverdraw
Lens' WorldOverdraw Bool
isWorldEditorEnabled) (EventM Name AppState () -> EventM Name AppState ())
-> EventM Name AppState () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ do
    MultiWorld Int Entity
w <- Getting (MultiWorld Int Entity) AppState (MultiWorld Int Entity)
-> EventM Name AppState (MultiWorld Int Entity)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting (MultiWorld Int Entity) AppState (MultiWorld Int Entity)
 -> EventM Name AppState (MultiWorld Int Entity))
-> Getting (MultiWorld Int Entity) AppState (MultiWorld Int Entity)
-> EventM Name AppState (MultiWorld Int Entity)
forall a b. (a -> b) -> a -> b
$ (GameState -> Const (MultiWorld Int Entity) GameState)
-> AppState -> Const (MultiWorld Int Entity) AppState
Lens' AppState GameState
gameState ((GameState -> Const (MultiWorld Int Entity) GameState)
 -> AppState -> Const (MultiWorld Int Entity) AppState)
-> ((MultiWorld Int Entity
     -> Const (MultiWorld Int Entity) (MultiWorld Int Entity))
    -> GameState -> Const (MultiWorld Int Entity) GameState)
-> Getting (MultiWorld Int Entity) AppState (MultiWorld Int Entity)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Landscape -> Const (MultiWorld Int Entity) Landscape)
-> GameState -> Const (MultiWorld Int Entity) GameState
Lens' GameState Landscape
landscape ((Landscape -> Const (MultiWorld Int Entity) Landscape)
 -> GameState -> Const (MultiWorld Int Entity) GameState)
-> ((MultiWorld Int Entity
     -> Const (MultiWorld Int Entity) (MultiWorld Int Entity))
    -> Landscape -> Const (MultiWorld Int Entity) Landscape)
-> (MultiWorld Int Entity
    -> Const (MultiWorld Int Entity) (MultiWorld Int Entity))
-> GameState
-> Const (MultiWorld Int Entity) GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MultiWorld Int Entity
 -> Const (MultiWorld Int Entity) (MultiWorld Int Entity))
-> Landscape -> Const (MultiWorld Int Entity) Landscape
Lens' Landscape (MultiWorld Int Entity)
multiWorld
    TerrainMap
tm <- Getting TerrainMap AppState TerrainMap
-> EventM Name AppState TerrainMap
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting TerrainMap AppState TerrainMap
 -> EventM Name AppState TerrainMap)
-> Getting TerrainMap AppState TerrainMap
-> EventM Name AppState TerrainMap
forall a b. (a -> b) -> a -> b
$ (GameState -> Const TerrainMap GameState)
-> AppState -> Const TerrainMap AppState
Lens' AppState GameState
gameState ((GameState -> Const TerrainMap GameState)
 -> AppState -> Const TerrainMap AppState)
-> ((TerrainMap -> Const TerrainMap TerrainMap)
    -> GameState -> Const TerrainMap GameState)
-> Getting TerrainMap AppState TerrainMap
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Landscape -> Const TerrainMap Landscape)
-> GameState -> Const TerrainMap GameState
Lens' GameState Landscape
landscape ((Landscape -> Const TerrainMap Landscape)
 -> GameState -> Const TerrainMap GameState)
-> ((TerrainMap -> Const TerrainMap TerrainMap)
    -> Landscape -> Const TerrainMap Landscape)
-> (TerrainMap -> Const TerrainMap TerrainMap)
-> GameState
-> Const TerrainMap GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TerrainEntityMaps -> Const TerrainMap TerrainEntityMaps)
-> Landscape -> Const TerrainMap Landscape
Lens' Landscape TerrainEntityMaps
terrainAndEntities ((TerrainEntityMaps -> Const TerrainMap TerrainEntityMaps)
 -> Landscape -> Const TerrainMap Landscape)
-> ((TerrainMap -> Const TerrainMap TerrainMap)
    -> TerrainEntityMaps -> Const TerrainMap TerrainEntityMaps)
-> (TerrainMap -> Const TerrainMap TerrainMap)
-> Landscape
-> Const TerrainMap Landscape
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TerrainMap -> Const TerrainMap TerrainMap)
-> TerrainEntityMaps -> Const TerrainMap TerrainEntityMaps
Lens' TerrainEntityMaps TerrainMap
terrainMap
    let setTerrainPaint :: Cosmic Coords -> m ()
setTerrainPaint Cosmic Coords
coords = do
          let (TerrainType
terrain, Maybe EntityPaint
maybeElementPaint) =
                TerrainMap
-> WorldOverdraw
-> MultiWorld Int Entity
-> Cosmic Coords
-> (TerrainType, Maybe EntityPaint)
EU.getEditorContentAt
                  TerrainMap
tm
                  (WorldEditor Name
worldEditor WorldEditor Name
-> Getting WorldOverdraw (WorldEditor Name) WorldOverdraw
-> WorldOverdraw
forall s a. s -> Getting a s a -> a
^. Getting WorldOverdraw (WorldEditor Name) WorldOverdraw
forall n (f :: * -> *).
Functor f =>
(WorldOverdraw -> f WorldOverdraw)
-> WorldEditor n -> f (WorldEditor n)
worldOverdraw)
                  MultiWorld Int Entity
w
                  Cosmic Coords
coords
          (UIState -> Identity UIState) -> AppState -> Identity AppState
Lens' AppState UIState
uiState ((UIState -> Identity UIState) -> AppState -> Identity AppState)
-> ((GenericList Name Vector TerrainType
     -> Identity (GenericList Name Vector TerrainType))
    -> UIState -> Identity UIState)
-> (GenericList Name Vector TerrainType
    -> Identity (GenericList Name Vector TerrainType))
-> AppState
-> Identity AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Identity UIGameplay) -> UIState -> Identity UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> UIState -> Identity UIState)
-> ((GenericList Name Vector TerrainType
     -> Identity (GenericList Name Vector TerrainType))
    -> UIGameplay -> Identity UIGameplay)
-> (GenericList Name Vector TerrainType
    -> Identity (GenericList Name Vector TerrainType))
-> UIState
-> Identity UIState
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)
-> ((GenericList Name Vector TerrainType
     -> Identity (GenericList Name Vector TerrainType))
    -> WorldEditor Name -> Identity (WorldEditor Name))
-> (GenericList Name Vector TerrainType
    -> Identity (GenericList Name Vector TerrainType))
-> UIGameplay
-> Identity UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenericList Name Vector TerrainType
 -> Identity (GenericList Name Vector TerrainType))
-> WorldEditor Name -> Identity (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(List n TerrainType -> f (List n TerrainType))
-> WorldEditor n -> f (WorldEditor n)
terrainList ((GenericList Name Vector TerrainType
  -> Identity (GenericList Name Vector TerrainType))
 -> AppState -> Identity AppState)
-> (GenericList Name Vector TerrainType
    -> GenericList Name Vector TerrainType)
-> m ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= TerrainType
-> GenericList Name Vector TerrainType
-> GenericList Name Vector TerrainType
forall e (t :: * -> *) n.
(Eq e, Foldable t, Splittable t) =>
e -> GenericList n t e -> GenericList n t e
BL.listMoveToElement TerrainType
terrain
          Maybe EntityPaint -> (EntityPaint -> m ()) -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ Maybe EntityPaint
maybeElementPaint ((EntityPaint -> m ()) -> m ()) -> (EntityPaint -> m ()) -> m ()
forall a b. (a -> b) -> a -> b
$ \EntityPaint
elementPaint ->
            let p :: EntityFacade
p = case EntityPaint
elementPaint of
                  Facade EntityFacade
efd -> EntityFacade
efd
                  Ref Entity
r -> Entity -> EntityFacade
mkFacade Entity
r
             in (UIState -> Identity UIState) -> AppState -> Identity AppState
Lens' AppState UIState
uiState ((UIState -> Identity UIState) -> AppState -> Identity AppState)
-> ((List Name EntityFacade -> Identity (List Name EntityFacade))
    -> UIState -> Identity UIState)
-> (List Name EntityFacade -> Identity (List Name EntityFacade))
-> AppState
-> Identity AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Identity UIGameplay) -> UIState -> Identity UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> UIState -> Identity UIState)
-> ((List Name EntityFacade -> Identity (List Name EntityFacade))
    -> UIGameplay -> Identity UIGameplay)
-> (List Name EntityFacade -> Identity (List Name EntityFacade))
-> UIState
-> Identity UIState
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)
-> ((List Name EntityFacade -> Identity (List Name EntityFacade))
    -> WorldEditor Name -> Identity (WorldEditor Name))
-> (List Name EntityFacade -> Identity (List Name EntityFacade))
-> UIGameplay
-> Identity UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (List Name EntityFacade -> Identity (List Name EntityFacade))
-> WorldEditor Name -> Identity (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(List n EntityFacade -> f (List n EntityFacade))
-> WorldEditor n -> f (WorldEditor n)
entityPaintList ((List Name EntityFacade -> Identity (List Name EntityFacade))
 -> AppState -> Identity AppState)
-> (List Name EntityFacade -> List Name EntityFacade) -> m ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= EntityFacade -> List Name EntityFacade -> List Name EntityFacade
forall e (t :: * -> *) n.
(Eq e, Foldable t, Splittable t) =>
e -> GenericList n t e -> GenericList n t e
BL.listMoveToElement EntityFacade
p

    Maybe (Cosmic Coords)
mouseCoordsM <- LensLike'
  (Zoomed (EventM Name GameState) (Maybe (Cosmic Coords)))
  AppState
  GameState
-> EventM Name GameState (Maybe (Cosmic Coords))
-> EventM Name AppState (Maybe (Cosmic Coords))
forall c.
LensLike' (Zoomed (EventM Name GameState) c) AppState GameState
-> EventM Name GameState 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 (GameState
 -> Focusing
      (StateT (EventState Name) IO) (Maybe (Cosmic Coords)) GameState)
-> AppState
-> Focusing
     (StateT (EventState Name) IO) (Maybe (Cosmic Coords)) AppState
LensLike'
  (Zoomed (EventM Name GameState) (Maybe (Cosmic Coords)))
  AppState
  GameState
Lens' AppState GameState
gameState (EventM Name GameState (Maybe (Cosmic Coords))
 -> EventM Name AppState (Maybe (Cosmic Coords)))
-> EventM Name GameState (Maybe (Cosmic Coords))
-> EventM Name AppState (Maybe (Cosmic Coords))
forall a b. (a -> b) -> a -> b
$ Location -> EventM Name GameState (Maybe (Cosmic Coords))
mouseLocToWorldCoords Location
mouseLoc
    Maybe (Cosmic Coords)
-> (Cosmic Coords -> EventM Name AppState ())
-> EventM Name AppState ()
forall (m :: * -> *) a.
Applicative m =>
Maybe a -> (a -> m ()) -> m ()
whenJust Maybe (Cosmic Coords)
mouseCoordsM Cosmic Coords -> EventM Name AppState ()
forall {m :: * -> *}.
MonadState AppState m =>
Cosmic Coords -> m ()
setTerrainPaint

-- | Handle user input events in the robot panel.
handleWorldEditorPanelEvent :: BrickEvent Name AppEvent -> EventM Name AppState ()
handleWorldEditorPanelEvent :: BrickEvent Name AppEvent -> EventM Name AppState ()
handleWorldEditorPanelEvent = \case
  Key Key
V.KEsc -> (UIState -> Identity UIState) -> AppState -> Identity AppState
Lens' AppState UIState
uiState ((UIState -> Identity UIState) -> AppState -> Identity AppState)
-> ((BoundsSelectionStep -> Identity BoundsSelectionStep)
    -> UIState -> Identity UIState)
-> (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> AppState
-> Identity AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Identity UIGameplay) -> UIState -> Identity UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> UIState -> Identity UIState)
-> ((BoundsSelectionStep -> Identity BoundsSelectionStep)
    -> UIGameplay -> Identity UIGameplay)
-> (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> UIState
-> Identity UIState
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)
-> ((BoundsSelectionStep -> Identity BoundsSelectionStep)
    -> WorldEditor Name -> Identity (WorldEditor Name))
-> (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> UIGameplay
-> Identity UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MapEditingBounds -> Identity MapEditingBounds)
-> WorldEditor Name -> Identity (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(MapEditingBounds -> f MapEditingBounds)
-> WorldEditor n -> f (WorldEditor n)
editingBounds ((MapEditingBounds -> Identity MapEditingBounds)
 -> WorldEditor Name -> Identity (WorldEditor Name))
-> ((BoundsSelectionStep -> Identity BoundsSelectionStep)
    -> MapEditingBounds -> Identity MapEditingBounds)
-> (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> WorldEditor Name
-> Identity (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> MapEditingBounds -> Identity MapEditingBounds
Lens' MapEditingBounds BoundsSelectionStep
boundsSelectionStep ((BoundsSelectionStep -> Identity BoundsSelectionStep)
 -> AppState -> Identity AppState)
-> BoundsSelectionStep -> EventM Name AppState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= BoundsSelectionStep
SelectionComplete
  Key Key
V.KEnter -> do
    FocusRing Name
fring <- Getting (FocusRing Name) AppState (FocusRing Name)
-> EventM Name AppState (FocusRing Name)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting (FocusRing Name) AppState (FocusRing Name)
 -> EventM Name AppState (FocusRing Name))
-> Getting (FocusRing Name) AppState (FocusRing Name)
-> EventM Name AppState (FocusRing Name)
forall a b. (a -> b) -> a -> b
$ (UIState -> Const (FocusRing Name) UIState)
-> AppState -> Const (FocusRing Name) AppState
Lens' AppState UIState
uiState ((UIState -> Const (FocusRing Name) UIState)
 -> AppState -> Const (FocusRing Name) AppState)
-> ((FocusRing Name -> Const (FocusRing Name) (FocusRing Name))
    -> UIState -> Const (FocusRing Name) UIState)
-> Getting (FocusRing Name) AppState (FocusRing Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Const (FocusRing Name) UIGameplay)
-> UIState -> Const (FocusRing Name) UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Const (FocusRing Name) UIGameplay)
 -> UIState -> Const (FocusRing Name) UIState)
-> ((FocusRing Name -> Const (FocusRing Name) (FocusRing Name))
    -> UIGameplay -> Const (FocusRing Name) UIGameplay)
-> (FocusRing Name -> Const (FocusRing Name) (FocusRing Name))
-> UIState
-> Const (FocusRing Name) UIState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WorldEditor Name -> Const (FocusRing Name) (WorldEditor Name))
-> UIGameplay -> Const (FocusRing Name) UIGameplay
Lens' UIGameplay (WorldEditor Name)
uiWorldEditor ((WorldEditor Name -> Const (FocusRing Name) (WorldEditor Name))
 -> UIGameplay -> Const (FocusRing Name) UIGameplay)
-> ((FocusRing Name -> Const (FocusRing Name) (FocusRing Name))
    -> WorldEditor Name -> Const (FocusRing Name) (WorldEditor Name))
-> (FocusRing Name -> Const (FocusRing Name) (FocusRing Name))
-> UIGameplay
-> Const (FocusRing Name) UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocusRing Name -> Const (FocusRing Name) (FocusRing Name))
-> WorldEditor Name -> Const (FocusRing Name) (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(FocusRing n -> f (FocusRing n))
-> WorldEditor n -> f (WorldEditor n)
editorFocusRing
    case FocusRing Name -> Maybe Name
forall n. FocusRing n -> Maybe n
focusGetCurrent FocusRing Name
fring of
      Just (WorldEditorPanelControl WorldEditorFocusable
x) -> WorldEditorFocusable -> EventM Name AppState ()
activateWorldEditorFunction WorldEditorFocusable
x
      Maybe Name
_ -> () -> EventM Name AppState ()
forall a. a -> EventM Name AppState a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
  ControlChar Char
's' -> EventM Name AppState ()
saveMapFile
  CharKey Char
'\t' -> (UIState -> Identity UIState) -> AppState -> Identity AppState
Lens' AppState UIState
uiState ((UIState -> Identity UIState) -> AppState -> Identity AppState)
-> ((FocusRing Name -> Identity (FocusRing Name))
    -> UIState -> Identity UIState)
-> (FocusRing Name -> Identity (FocusRing Name))
-> AppState
-> Identity AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Identity UIGameplay) -> UIState -> Identity UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> UIState -> Identity UIState)
-> ((FocusRing Name -> Identity (FocusRing Name))
    -> UIGameplay -> Identity UIGameplay)
-> (FocusRing Name -> Identity (FocusRing Name))
-> UIState
-> Identity UIState
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)
-> ((FocusRing Name -> Identity (FocusRing Name))
    -> WorldEditor Name -> Identity (WorldEditor Name))
-> (FocusRing Name -> Identity (FocusRing Name))
-> UIGameplay
-> Identity UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocusRing Name -> Identity (FocusRing Name))
-> WorldEditor Name -> Identity (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(FocusRing n -> f (FocusRing n))
-> WorldEditor n -> f (WorldEditor n)
editorFocusRing ((FocusRing Name -> Identity (FocusRing Name))
 -> AppState -> Identity AppState)
-> (FocusRing Name -> FocusRing Name) -> EventM Name AppState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= FocusRing Name -> FocusRing Name
forall n. FocusRing n -> FocusRing n
focusNext
  Key Key
V.KBackTab -> (UIState -> Identity UIState) -> AppState -> Identity AppState
Lens' AppState UIState
uiState ((UIState -> Identity UIState) -> AppState -> Identity AppState)
-> ((FocusRing Name -> Identity (FocusRing Name))
    -> UIState -> Identity UIState)
-> (FocusRing Name -> Identity (FocusRing Name))
-> AppState
-> Identity AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Identity UIGameplay) -> UIState -> Identity UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> UIState -> Identity UIState)
-> ((FocusRing Name -> Identity (FocusRing Name))
    -> UIGameplay -> Identity UIGameplay)
-> (FocusRing Name -> Identity (FocusRing Name))
-> UIState
-> Identity UIState
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)
-> ((FocusRing Name -> Identity (FocusRing Name))
    -> WorldEditor Name -> Identity (WorldEditor Name))
-> (FocusRing Name -> Identity (FocusRing Name))
-> UIGameplay
-> Identity UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (FocusRing Name -> Identity (FocusRing Name))
-> WorldEditor Name -> Identity (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(FocusRing n -> f (FocusRing n))
-> WorldEditor n -> f (WorldEditor n)
editorFocusRing ((FocusRing Name -> Identity (FocusRing Name))
 -> AppState -> Identity AppState)
-> (FocusRing Name -> FocusRing Name) -> EventM Name AppState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> (a -> b) -> m ()
%= FocusRing Name -> FocusRing Name
forall n. FocusRing n -> FocusRing n
focusPrev
  BrickEvent Name AppEvent
_ -> () -> EventM Name AppState ()
forall a. a -> EventM Name AppState a
forall (m :: * -> *) a. Monad m => a -> m a
return ()

-- | Return value: whether the cursor position should be updated
updateAreaBounds :: Maybe (Cosmic Coords) -> EventM Name AppState Bool
updateAreaBounds :: Maybe (Cosmic Coords) -> EventM Name AppState Bool
updateAreaBounds = \case
  Maybe (Cosmic Coords)
Nothing -> Bool -> EventM Name AppState Bool
forall a. a -> EventM Name AppState a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True
  Just Cosmic Coords
mouseCoords -> do
    BoundsSelectionStep
selectorStage <- Getting BoundsSelectionStep AppState BoundsSelectionStep
-> EventM Name AppState BoundsSelectionStep
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting BoundsSelectionStep AppState BoundsSelectionStep
 -> EventM Name AppState BoundsSelectionStep)
-> Getting BoundsSelectionStep AppState BoundsSelectionStep
-> EventM Name AppState BoundsSelectionStep
forall a b. (a -> b) -> a -> b
$ (UIState -> Const BoundsSelectionStep UIState)
-> AppState -> Const BoundsSelectionStep AppState
Lens' AppState UIState
uiState ((UIState -> Const BoundsSelectionStep UIState)
 -> AppState -> Const BoundsSelectionStep AppState)
-> ((BoundsSelectionStep
     -> Const BoundsSelectionStep BoundsSelectionStep)
    -> UIState -> Const BoundsSelectionStep UIState)
-> Getting BoundsSelectionStep AppState BoundsSelectionStep
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Const BoundsSelectionStep UIGameplay)
-> UIState -> Const BoundsSelectionStep UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Const BoundsSelectionStep UIGameplay)
 -> UIState -> Const BoundsSelectionStep UIState)
-> ((BoundsSelectionStep
     -> Const BoundsSelectionStep BoundsSelectionStep)
    -> UIGameplay -> Const BoundsSelectionStep UIGameplay)
-> (BoundsSelectionStep
    -> Const BoundsSelectionStep BoundsSelectionStep)
-> UIState
-> Const BoundsSelectionStep UIState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WorldEditor Name -> Const BoundsSelectionStep (WorldEditor Name))
-> UIGameplay -> Const BoundsSelectionStep UIGameplay
Lens' UIGameplay (WorldEditor Name)
uiWorldEditor ((WorldEditor Name -> Const BoundsSelectionStep (WorldEditor Name))
 -> UIGameplay -> Const BoundsSelectionStep UIGameplay)
-> ((BoundsSelectionStep
     -> Const BoundsSelectionStep BoundsSelectionStep)
    -> WorldEditor Name
    -> Const BoundsSelectionStep (WorldEditor Name))
-> (BoundsSelectionStep
    -> Const BoundsSelectionStep BoundsSelectionStep)
-> UIGameplay
-> Const BoundsSelectionStep UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MapEditingBounds -> Const BoundsSelectionStep MapEditingBounds)
-> WorldEditor Name -> Const BoundsSelectionStep (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(MapEditingBounds -> f MapEditingBounds)
-> WorldEditor n -> f (WorldEditor n)
editingBounds ((MapEditingBounds -> Const BoundsSelectionStep MapEditingBounds)
 -> WorldEditor Name
 -> Const BoundsSelectionStep (WorldEditor Name))
-> ((BoundsSelectionStep
     -> Const BoundsSelectionStep BoundsSelectionStep)
    -> MapEditingBounds -> Const BoundsSelectionStep MapEditingBounds)
-> (BoundsSelectionStep
    -> Const BoundsSelectionStep BoundsSelectionStep)
-> WorldEditor Name
-> Const BoundsSelectionStep (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BoundsSelectionStep
 -> Const BoundsSelectionStep BoundsSelectionStep)
-> MapEditingBounds -> Const BoundsSelectionStep MapEditingBounds
Lens' MapEditingBounds BoundsSelectionStep
boundsSelectionStep
    case BoundsSelectionStep
selectorStage of
      BoundsSelectionStep
UpperLeftPending -> do
        (UIState -> Identity UIState) -> AppState -> Identity AppState
Lens' AppState UIState
uiState ((UIState -> Identity UIState) -> AppState -> Identity AppState)
-> ((BoundsSelectionStep -> Identity BoundsSelectionStep)
    -> UIState -> Identity UIState)
-> (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> AppState
-> Identity AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Identity UIGameplay) -> UIState -> Identity UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> UIState -> Identity UIState)
-> ((BoundsSelectionStep -> Identity BoundsSelectionStep)
    -> UIGameplay -> Identity UIGameplay)
-> (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> UIState
-> Identity UIState
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)
-> ((BoundsSelectionStep -> Identity BoundsSelectionStep)
    -> WorldEditor Name -> Identity (WorldEditor Name))
-> (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> UIGameplay
-> Identity UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MapEditingBounds -> Identity MapEditingBounds)
-> WorldEditor Name -> Identity (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(MapEditingBounds -> f MapEditingBounds)
-> WorldEditor n -> f (WorldEditor n)
editingBounds ((MapEditingBounds -> Identity MapEditingBounds)
 -> WorldEditor Name -> Identity (WorldEditor Name))
-> ((BoundsSelectionStep -> Identity BoundsSelectionStep)
    -> MapEditingBounds -> Identity MapEditingBounds)
-> (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> WorldEditor Name
-> Identity (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> MapEditingBounds -> Identity MapEditingBounds
Lens' MapEditingBounds BoundsSelectionStep
boundsSelectionStep ((BoundsSelectionStep -> Identity BoundsSelectionStep)
 -> AppState -> Identity AppState)
-> BoundsSelectionStep -> EventM Name AppState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Cosmic Coords -> BoundsSelectionStep
LowerRightPending Cosmic Coords
mouseCoords
        Bool -> EventM Name AppState Bool
forall a. a -> EventM Name AppState a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
      -- TODO (#1152): Validate that the lower-right click is below and to the right of
      -- the top-left coord and that they are within the same subworld
      LowerRightPending Cosmic Coords
upperLeftMouseCoords -> do
        TimeSpec
t <- IO TimeSpec -> EventM Name AppState TimeSpec
forall a. IO a -> EventM Name AppState a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO TimeSpec -> EventM Name AppState TimeSpec)
-> IO TimeSpec -> EventM Name AppState TimeSpec
forall a b. (a -> b) -> a -> b
$ Clock -> IO TimeSpec
getTime Clock
Monotonic
        LensLike'
  (Zoomed (EventM Name (WorldEditor Name)) ())
  AppState
  (WorldEditor Name)
-> EventM Name (WorldEditor Name) () -> EventM Name AppState ()
forall c.
LensLike'
  (Zoomed (EventM Name (WorldEditor Name)) c)
  AppState
  (WorldEditor Name)
-> EventM Name (WorldEditor Name) 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 ((UIState -> Zoomed (EventM Name (WorldEditor Name)) () UIState)
-> AppState -> Zoomed (EventM Name (WorldEditor Name)) () AppState
Lens' AppState UIState
uiState ((UIState -> Zoomed (EventM Name (WorldEditor Name)) () UIState)
 -> AppState -> Zoomed (EventM Name (WorldEditor Name)) () AppState)
-> ((WorldEditor Name
     -> Zoomed (EventM Name (WorldEditor Name)) () (WorldEditor Name))
    -> UIState -> Zoomed (EventM Name (WorldEditor Name)) () UIState)
-> LensLike'
     (Zoomed (EventM Name (WorldEditor Name)) ())
     AppState
     (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay
 -> Zoomed (EventM Name (WorldEditor Name)) () UIGameplay)
-> UIState -> Zoomed (EventM Name (WorldEditor Name)) () UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay
  -> Zoomed (EventM Name (WorldEditor Name)) () UIGameplay)
 -> UIState -> Zoomed (EventM Name (WorldEditor Name)) () UIState)
-> ((WorldEditor Name
     -> Zoomed (EventM Name (WorldEditor Name)) () (WorldEditor Name))
    -> UIGameplay
    -> Zoomed (EventM Name (WorldEditor Name)) () UIGameplay)
-> (WorldEditor Name
    -> Zoomed (EventM Name (WorldEditor Name)) () (WorldEditor Name))
-> UIState
-> Zoomed (EventM Name (WorldEditor Name)) () UIState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WorldEditor Name
 -> Zoomed (EventM Name (WorldEditor Name)) () (WorldEditor Name))
-> UIGameplay
-> Zoomed (EventM Name (WorldEditor Name)) () UIGameplay
Lens' UIGameplay (WorldEditor Name)
uiWorldEditor) (EventM Name (WorldEditor Name) () -> EventM Name AppState ())
-> EventM Name (WorldEditor Name) () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ do
          (Maybe String -> Identity (Maybe String))
-> WorldEditor Name -> Identity (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(Maybe String -> f (Maybe String))
-> WorldEditor n -> f (WorldEditor n)
lastWorldEditorMessage ((Maybe String -> Identity (Maybe String))
 -> WorldEditor Name -> Identity (WorldEditor Name))
-> Maybe String -> EventM Name (WorldEditor Name) ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Maybe String
forall a. Maybe a
Nothing
          LensLike'
  (Zoomed (EventM Name MapEditingBounds) ())
  (WorldEditor Name)
  MapEditingBounds
-> EventM Name MapEditingBounds ()
-> EventM Name (WorldEditor Name) ()
forall c.
LensLike'
  (Zoomed (EventM Name MapEditingBounds) c)
  (WorldEditor Name)
  MapEditingBounds
-> EventM Name MapEditingBounds c
-> EventM Name (WorldEditor Name) c
forall (m :: * -> *) (n :: * -> *) s t c.
Zoom m n s t =>
LensLike' (Zoomed m c) t s -> m c -> n c
Brick.zoom LensLike'
  (Zoomed (EventM Name MapEditingBounds) ())
  (WorldEditor Name)
  MapEditingBounds
forall n (f :: * -> *).
Functor f =>
(MapEditingBounds -> f MapEditingBounds)
-> WorldEditor n -> f (WorldEditor n)
editingBounds (EventM Name MapEditingBounds ()
 -> EventM Name (WorldEditor Name) ())
-> EventM Name MapEditingBounds ()
-> EventM Name (WorldEditor Name) ()
forall a b. (a -> b) -> a -> b
$ do
            (Maybe (Cosmic BoundsRectangle)
 -> Identity (Maybe (Cosmic BoundsRectangle)))
-> MapEditingBounds -> Identity MapEditingBounds
Lens' MapEditingBounds (Maybe (Cosmic BoundsRectangle))
boundsRect ((Maybe (Cosmic BoundsRectangle)
  -> Identity (Maybe (Cosmic BoundsRectangle)))
 -> MapEditingBounds -> Identity MapEditingBounds)
-> Maybe (Cosmic BoundsRectangle)
-> EventM Name MapEditingBounds ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= Cosmic BoundsRectangle -> Maybe (Cosmic BoundsRectangle)
forall a. a -> Maybe a
Just ((Coords -> BoundsRectangle)
-> Cosmic Coords -> Cosmic BoundsRectangle
forall a b. (a -> b) -> Cosmic a -> Cosmic b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (,Getting Coords (Cosmic Coords) Coords -> Cosmic Coords -> Coords
forall s (m :: * -> *) a. MonadReader s m => Getting a s a -> m a
view Getting Coords (Cosmic Coords) Coords
forall a1 a2 (f :: * -> *).
Functor f =>
(a1 -> f a2) -> Cosmic a1 -> f (Cosmic a2)
planar Cosmic Coords
mouseCoords) Cosmic Coords
upperLeftMouseCoords)
            (BoundsSelectionStep -> Identity BoundsSelectionStep)
-> MapEditingBounds -> Identity MapEditingBounds
Lens' MapEditingBounds BoundsSelectionStep
boundsSelectionStep ((BoundsSelectionStep -> Identity BoundsSelectionStep)
 -> MapEditingBounds -> Identity MapEditingBounds)
-> BoundsSelectionStep -> EventM Name MapEditingBounds ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= BoundsSelectionStep
SelectionComplete
            (TimeSpec -> Identity TimeSpec)
-> MapEditingBounds -> Identity MapEditingBounds
Lens' MapEditingBounds TimeSpec
boundsPersistDisplayUntil ((TimeSpec -> Identity TimeSpec)
 -> MapEditingBounds -> Identity MapEditingBounds)
-> TimeSpec -> EventM Name MapEditingBounds ()
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
        FocusablePanel -> EventM Name AppState ()
setFocus FocusablePanel
WorldEditorPanel
        Bool -> EventM Name AppState Bool
forall a. a -> EventM Name AppState a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
      BoundsSelectionStep
SelectionComplete -> Bool -> EventM Name AppState Bool
forall a. a -> EventM Name AppState a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
True

saveMapFile :: EventM Name AppState ()
saveMapFile :: EventM Name AppState ()
saveMapFile = do
  WorldEditor Name
worldEditor <- Getting (WorldEditor Name) AppState (WorldEditor Name)
-> EventM Name AppState (WorldEditor Name)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting (WorldEditor Name) AppState (WorldEditor Name)
 -> EventM Name AppState (WorldEditor Name))
-> Getting (WorldEditor Name) AppState (WorldEditor Name)
-> EventM Name AppState (WorldEditor Name)
forall a b. (a -> b) -> a -> b
$ (UIState -> Const (WorldEditor Name) UIState)
-> AppState -> Const (WorldEditor Name) AppState
Lens' AppState UIState
uiState ((UIState -> Const (WorldEditor Name) UIState)
 -> AppState -> Const (WorldEditor Name) AppState)
-> ((WorldEditor Name
     -> Const (WorldEditor Name) (WorldEditor Name))
    -> UIState -> Const (WorldEditor Name) UIState)
-> Getting (WorldEditor Name) AppState (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Const (WorldEditor Name) UIGameplay)
-> UIState -> Const (WorldEditor Name) UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Const (WorldEditor Name) UIGameplay)
 -> UIState -> Const (WorldEditor Name) UIState)
-> ((WorldEditor Name
     -> Const (WorldEditor Name) (WorldEditor Name))
    -> UIGameplay -> Const (WorldEditor Name) UIGameplay)
-> (WorldEditor Name
    -> Const (WorldEditor Name) (WorldEditor Name))
-> UIState
-> Const (WorldEditor Name) UIState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WorldEditor Name -> Const (WorldEditor Name) (WorldEditor Name))
-> UIGameplay -> Const (WorldEditor Name) UIGameplay
Lens' UIGameplay (WorldEditor Name)
uiWorldEditor
  Maybe (Cosmic BoundsRectangle)
maybeBounds <- Getting
  (Maybe (Cosmic BoundsRectangle))
  AppState
  (Maybe (Cosmic BoundsRectangle))
-> EventM Name AppState (Maybe (Cosmic BoundsRectangle))
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting
   (Maybe (Cosmic BoundsRectangle))
   AppState
   (Maybe (Cosmic BoundsRectangle))
 -> EventM Name AppState (Maybe (Cosmic BoundsRectangle)))
-> Getting
     (Maybe (Cosmic BoundsRectangle))
     AppState
     (Maybe (Cosmic BoundsRectangle))
-> EventM Name AppState (Maybe (Cosmic BoundsRectangle))
forall a b. (a -> b) -> a -> b
$ (UIState -> Const (Maybe (Cosmic BoundsRectangle)) UIState)
-> AppState -> Const (Maybe (Cosmic BoundsRectangle)) AppState
Lens' AppState UIState
uiState ((UIState -> Const (Maybe (Cosmic BoundsRectangle)) UIState)
 -> AppState -> Const (Maybe (Cosmic BoundsRectangle)) AppState)
-> ((Maybe (Cosmic BoundsRectangle)
     -> Const
          (Maybe (Cosmic BoundsRectangle)) (Maybe (Cosmic BoundsRectangle)))
    -> UIState -> Const (Maybe (Cosmic BoundsRectangle)) UIState)
-> Getting
     (Maybe (Cosmic BoundsRectangle))
     AppState
     (Maybe (Cosmic BoundsRectangle))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Const (Maybe (Cosmic BoundsRectangle)) UIGameplay)
-> UIState -> Const (Maybe (Cosmic BoundsRectangle)) UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Const (Maybe (Cosmic BoundsRectangle)) UIGameplay)
 -> UIState -> Const (Maybe (Cosmic BoundsRectangle)) UIState)
-> ((Maybe (Cosmic BoundsRectangle)
     -> Const
          (Maybe (Cosmic BoundsRectangle)) (Maybe (Cosmic BoundsRectangle)))
    -> UIGameplay -> Const (Maybe (Cosmic BoundsRectangle)) UIGameplay)
-> (Maybe (Cosmic BoundsRectangle)
    -> Const
         (Maybe (Cosmic BoundsRectangle)) (Maybe (Cosmic BoundsRectangle)))
-> UIState
-> Const (Maybe (Cosmic BoundsRectangle)) UIState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WorldEditor Name
 -> Const (Maybe (Cosmic BoundsRectangle)) (WorldEditor Name))
-> UIGameplay -> Const (Maybe (Cosmic BoundsRectangle)) UIGameplay
Lens' UIGameplay (WorldEditor Name)
uiWorldEditor ((WorldEditor Name
  -> Const (Maybe (Cosmic BoundsRectangle)) (WorldEditor Name))
 -> UIGameplay -> Const (Maybe (Cosmic BoundsRectangle)) UIGameplay)
-> ((Maybe (Cosmic BoundsRectangle)
     -> Const
          (Maybe (Cosmic BoundsRectangle)) (Maybe (Cosmic BoundsRectangle)))
    -> WorldEditor Name
    -> Const (Maybe (Cosmic BoundsRectangle)) (WorldEditor Name))
-> (Maybe (Cosmic BoundsRectangle)
    -> Const
         (Maybe (Cosmic BoundsRectangle)) (Maybe (Cosmic BoundsRectangle)))
-> UIGameplay
-> Const (Maybe (Cosmic BoundsRectangle)) UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MapEditingBounds
 -> Const (Maybe (Cosmic BoundsRectangle)) MapEditingBounds)
-> WorldEditor Name
-> Const (Maybe (Cosmic BoundsRectangle)) (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(MapEditingBounds -> f MapEditingBounds)
-> WorldEditor n -> f (WorldEditor n)
editingBounds ((MapEditingBounds
  -> Const (Maybe (Cosmic BoundsRectangle)) MapEditingBounds)
 -> WorldEditor Name
 -> Const (Maybe (Cosmic BoundsRectangle)) (WorldEditor Name))
-> ((Maybe (Cosmic BoundsRectangle)
     -> Const
          (Maybe (Cosmic BoundsRectangle)) (Maybe (Cosmic BoundsRectangle)))
    -> MapEditingBounds
    -> Const (Maybe (Cosmic BoundsRectangle)) MapEditingBounds)
-> (Maybe (Cosmic BoundsRectangle)
    -> Const
         (Maybe (Cosmic BoundsRectangle)) (Maybe (Cosmic BoundsRectangle)))
-> WorldEditor Name
-> Const (Maybe (Cosmic BoundsRectangle)) (WorldEditor Name)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe (Cosmic BoundsRectangle)
 -> Const
      (Maybe (Cosmic BoundsRectangle)) (Maybe (Cosmic BoundsRectangle)))
-> MapEditingBounds
-> Const (Maybe (Cosmic BoundsRectangle)) MapEditingBounds
Lens' MapEditingBounds (Maybe (Cosmic BoundsRectangle))
boundsRect
  MultiWorld Int Entity
w <- Getting (MultiWorld Int Entity) AppState (MultiWorld Int Entity)
-> EventM Name AppState (MultiWorld Int Entity)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting (MultiWorld Int Entity) AppState (MultiWorld Int Entity)
 -> EventM Name AppState (MultiWorld Int Entity))
-> Getting (MultiWorld Int Entity) AppState (MultiWorld Int Entity)
-> EventM Name AppState (MultiWorld Int Entity)
forall a b. (a -> b) -> a -> b
$ (GameState -> Const (MultiWorld Int Entity) GameState)
-> AppState -> Const (MultiWorld Int Entity) AppState
Lens' AppState GameState
gameState ((GameState -> Const (MultiWorld Int Entity) GameState)
 -> AppState -> Const (MultiWorld Int Entity) AppState)
-> ((MultiWorld Int Entity
     -> Const (MultiWorld Int Entity) (MultiWorld Int Entity))
    -> GameState -> Const (MultiWorld Int Entity) GameState)
-> Getting (MultiWorld Int Entity) AppState (MultiWorld Int Entity)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Landscape -> Const (MultiWorld Int Entity) Landscape)
-> GameState -> Const (MultiWorld Int Entity) GameState
Lens' GameState Landscape
landscape ((Landscape -> Const (MultiWorld Int Entity) Landscape)
 -> GameState -> Const (MultiWorld Int Entity) GameState)
-> ((MultiWorld Int Entity
     -> Const (MultiWorld Int Entity) (MultiWorld Int Entity))
    -> Landscape -> Const (MultiWorld Int Entity) Landscape)
-> (MultiWorld Int Entity
    -> Const (MultiWorld Int Entity) (MultiWorld Int Entity))
-> GameState
-> Const (MultiWorld Int Entity) GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (MultiWorld Int Entity
 -> Const (MultiWorld Int Entity) (MultiWorld Int Entity))
-> Landscape -> Const (MultiWorld Int Entity) Landscape
Lens' Landscape (MultiWorld Int Entity)
multiWorld
  TerrainMap
tm <- Getting TerrainMap AppState TerrainMap
-> EventM Name AppState TerrainMap
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting TerrainMap AppState TerrainMap
 -> EventM Name AppState TerrainMap)
-> Getting TerrainMap AppState TerrainMap
-> EventM Name AppState TerrainMap
forall a b. (a -> b) -> a -> b
$ (GameState -> Const TerrainMap GameState)
-> AppState -> Const TerrainMap AppState
Lens' AppState GameState
gameState ((GameState -> Const TerrainMap GameState)
 -> AppState -> Const TerrainMap AppState)
-> ((TerrainMap -> Const TerrainMap TerrainMap)
    -> GameState -> Const TerrainMap GameState)
-> Getting TerrainMap AppState TerrainMap
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Landscape -> Const TerrainMap Landscape)
-> GameState -> Const TerrainMap GameState
Lens' GameState Landscape
landscape ((Landscape -> Const TerrainMap Landscape)
 -> GameState -> Const TerrainMap GameState)
-> ((TerrainMap -> Const TerrainMap TerrainMap)
    -> Landscape -> Const TerrainMap Landscape)
-> (TerrainMap -> Const TerrainMap TerrainMap)
-> GameState
-> Const TerrainMap GameState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TerrainEntityMaps -> Const TerrainMap TerrainEntityMaps)
-> Landscape -> Const TerrainMap Landscape
Lens' Landscape TerrainEntityMaps
terrainAndEntities ((TerrainEntityMaps -> Const TerrainMap TerrainEntityMaps)
 -> Landscape -> Const TerrainMap Landscape)
-> ((TerrainMap -> Const TerrainMap TerrainMap)
    -> TerrainEntityMaps -> Const TerrainMap TerrainEntityMaps)
-> (TerrainMap -> Const TerrainMap TerrainMap)
-> Landscape
-> Const TerrainMap Landscape
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TerrainMap -> Const TerrainMap TerrainMap)
-> TerrainEntityMaps -> Const TerrainMap TerrainEntityMaps
Lens' TerrainEntityMaps TerrainMap
terrainMap
  let mapCellGrid :: Grid (Maybe CellPaintDisplay)
mapCellGrid =
        CellPaintDisplay -> Maybe CellPaintDisplay
forall a. a -> Maybe a
Just
          (CellPaintDisplay -> Maybe CellPaintDisplay)
-> Grid CellPaintDisplay -> Grid (Maybe CellPaintDisplay)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TerrainMap
-> WorldOverdraw
-> Maybe (Cosmic BoundsRectangle)
-> MultiWorld Int Entity
-> Grid CellPaintDisplay
EU.getEditedMapRectangle TerrainMap
tm (WorldEditor Name
worldEditor WorldEditor Name
-> Getting WorldOverdraw (WorldEditor Name) WorldOverdraw
-> WorldOverdraw
forall s a. s -> Getting a s a -> a
^. Getting WorldOverdraw (WorldEditor Name) WorldOverdraw
forall n (f :: * -> *).
Functor f =>
(WorldOverdraw -> f WorldOverdraw)
-> WorldEditor n -> f (WorldEditor n)
worldOverdraw) Maybe (Cosmic BoundsRectangle)
maybeBounds MultiWorld Int Entity
w

  let fp :: String
fp = WorldEditor Name
worldEditor WorldEditor Name
-> Getting String (WorldEditor Name) String -> String
forall s a. s -> Getting a s a -> a
^. Getting String (WorldEditor Name) String
forall n (f :: * -> *).
Functor f =>
(String -> f String) -> WorldEditor n -> f (WorldEditor n)
outputFilePath
  Maybe ScenarioInfoPair
maybeScenarioPair <- Getting (Maybe ScenarioInfoPair) AppState (Maybe ScenarioInfoPair)
-> EventM Name AppState (Maybe ScenarioInfoPair)
forall s (m :: * -> *) a. MonadState s m => Getting a s a -> m a
use (Getting (Maybe ScenarioInfoPair) AppState (Maybe ScenarioInfoPair)
 -> EventM Name AppState (Maybe ScenarioInfoPair))
-> Getting
     (Maybe ScenarioInfoPair) AppState (Maybe ScenarioInfoPair)
-> EventM Name AppState (Maybe ScenarioInfoPair)
forall a b. (a -> b) -> a -> b
$ (UIState -> Const (Maybe ScenarioInfoPair) UIState)
-> AppState -> Const (Maybe ScenarioInfoPair) AppState
Lens' AppState UIState
uiState ((UIState -> Const (Maybe ScenarioInfoPair) UIState)
 -> AppState -> Const (Maybe ScenarioInfoPair) AppState)
-> ((Maybe ScenarioInfoPair
     -> Const (Maybe ScenarioInfoPair) (Maybe ScenarioInfoPair))
    -> UIState -> Const (Maybe ScenarioInfoPair) UIState)
-> Getting
     (Maybe ScenarioInfoPair) AppState (Maybe ScenarioInfoPair)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Const (Maybe ScenarioInfoPair) UIGameplay)
-> UIState -> Const (Maybe ScenarioInfoPair) UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Const (Maybe ScenarioInfoPair) UIGameplay)
 -> UIState -> Const (Maybe ScenarioInfoPair) UIState)
-> ((Maybe ScenarioInfoPair
     -> Const (Maybe ScenarioInfoPair) (Maybe ScenarioInfoPair))
    -> UIGameplay -> Const (Maybe ScenarioInfoPair) UIGameplay)
-> (Maybe ScenarioInfoPair
    -> Const (Maybe ScenarioInfoPair) (Maybe ScenarioInfoPair))
-> UIState
-> Const (Maybe ScenarioInfoPair) UIState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe ScenarioInfoPair
 -> Const (Maybe ScenarioInfoPair) (Maybe ScenarioInfoPair))
-> UIGameplay -> Const (Maybe ScenarioInfoPair) UIGameplay
Lens' UIGameplay (Maybe ScenarioInfoPair)
scenarioRef
  IO () -> EventM Name AppState ()
forall a. IO a -> EventM Name AppState a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> EventM Name AppState ())
-> IO () -> EventM Name AppState ()
forall a b. (a -> b) -> a -> b
$ String -> SkeletonScenario -> IO ()
forall a. ToJSON a => String -> a -> IO ()
Y.encodeFile String
fp (SkeletonScenario -> IO ()) -> SkeletonScenario -> IO ()
forall a b. (a -> b) -> a -> b
$ Maybe Scenario -> Grid (Maybe CellPaintDisplay) -> SkeletonScenario
constructScenario (ScenarioInfoPair -> Scenario
forall a b. (a, b) -> a
fst (ScenarioInfoPair -> Scenario)
-> Maybe ScenarioInfoPair -> Maybe Scenario
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ScenarioInfoPair
maybeScenarioPair) Grid (Maybe CellPaintDisplay)
mapCellGrid

  (UIState -> Identity UIState) -> AppState -> Identity AppState
Lens' AppState UIState
uiState ((UIState -> Identity UIState) -> AppState -> Identity AppState)
-> ((Maybe String -> Identity (Maybe String))
    -> UIState -> Identity UIState)
-> (Maybe String -> Identity (Maybe String))
-> AppState
-> Identity AppState
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (UIGameplay -> Identity UIGameplay) -> UIState -> Identity UIState
Lens' UIState UIGameplay
uiGameplay ((UIGameplay -> Identity UIGameplay)
 -> UIState -> Identity UIState)
-> ((Maybe String -> Identity (Maybe String))
    -> UIGameplay -> Identity UIGameplay)
-> (Maybe String -> Identity (Maybe String))
-> UIState
-> Identity UIState
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)
-> ((Maybe String -> Identity (Maybe String))
    -> WorldEditor Name -> Identity (WorldEditor Name))
-> (Maybe String -> Identity (Maybe String))
-> UIGameplay
-> Identity UIGameplay
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Maybe String -> Identity (Maybe String))
-> WorldEditor Name -> Identity (WorldEditor Name)
forall n (f :: * -> *).
Functor f =>
(Maybe String -> f (Maybe String))
-> WorldEditor n -> f (WorldEditor n)
lastWorldEditorMessage ((Maybe String -> Identity (Maybe String))
 -> AppState -> Identity AppState)
-> Maybe String -> EventM Name AppState ()
forall s (m :: * -> *) a b.
MonadState s m =>
ASetter s s a b -> b -> m ()
.= String -> Maybe String
forall a. a -> Maybe a
Just String
"Saved."