{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
module Swarm.TUI.Model.UI.Gameplay (
UIGameplay (..),
UITiming (..),
UIInventory (..),
GoalDisplay (..),
UIDialogs (..),
uiTiming,
uiInventory,
uiFocusRing,
uiWorldCursor,
uiWorldEditor,
uiREPL,
uiInventoryList,
uiInventorySort,
uiInventorySearch,
uiScrollToEnd,
uiModal,
uiGoal,
uiStructure,
uiRobot,
uiDialogs,
uiIsAutoPlay,
uiAutoShowObjectives,
lgTicksPerSecond,
lastFrameTime,
accumulatedTime,
tickCount,
frameCount,
frameTickCount,
lastInfoTime,
uiShowFPS,
uiShowREPL,
uiShowZero,
uiShowDebug,
uiShowRobots,
uiHideRobotsUntil,
uiInventoryShouldUpdate,
uiTPF,
uiFPS,
scenarioRef,
) where
import Brick.Focus
import Brick.Widgets.List qualified as BL
import Control.Lens hiding (from, (<.>))
import Data.Bits (FiniteBits (finiteBitSize))
import Data.Text (Text)
import Swarm.Game.Scenario.Status (ScenarioPath)
import Swarm.Game.ScenarioInfo (
ScenarioWith,
)
import Swarm.Game.Universe
import Swarm.Game.World.Coords
import Swarm.TUI.Editor.Model
import Swarm.TUI.Inventory.Sorting
import Swarm.TUI.Model.Dialog.Goal
import Swarm.TUI.Model.Dialog.Structure
import Swarm.TUI.Model.Menu
import Swarm.TUI.Model.Name
import Swarm.TUI.Model.Repl
import Swarm.TUI.View.Robot.Type
import Swarm.Util.Lens (makeLensesExcluding, makeLensesNoSigs)
import System.Clock
data UITiming = UITiming
{ UITiming -> Bool
_uiShowFPS :: Bool
, UITiming -> Double
_uiTPF :: Double
, UITiming -> Double
_uiFPS :: Double
, UITiming -> Int
_lgTicksPerSecond :: Int
, UITiming -> Int
_tickCount :: Int
, UITiming -> Int
_frameCount :: Int
, UITiming -> Int
_frameTickCount :: Int
, UITiming -> TimeSpec
_lastFrameTime :: TimeSpec
, UITiming -> TimeSpec
_accumulatedTime :: TimeSpec
, UITiming -> TimeSpec
_lastInfoTime :: TimeSpec
}
makeLensesExcluding ['_lgTicksPerSecond] ''UITiming
uiShowFPS :: Lens' UITiming Bool
uiTPF :: Lens' UITiming Double
uiFPS :: Lens' UITiming Double
lgTicksPerSecond :: Lens' UITiming Int
lgTicksPerSecond :: Lens' UITiming Int
lgTicksPerSecond = (UITiming -> Int)
-> (UITiming -> Int -> UITiming) -> Lens' UITiming Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
lens UITiming -> Int
_lgTicksPerSecond UITiming -> Int -> UITiming
safeSetLgTicks
where
maxLog :: Int
maxLog = Int -> Int
forall b. FiniteBits b => b -> Int
finiteBitSize (Int
forall a. Bounded a => a
maxBound :: Int)
maxTicks :: Int
maxTicks = Int
maxLog Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
2
minTicks :: Int
minTicks = Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
maxLog
safeSetLgTicks :: UITiming -> Int -> UITiming
safeSetLgTicks UITiming
ui Int
lTicks
| Int
lTicks Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
minTicks = UITiming -> Int -> UITiming
setLgTicks UITiming
ui Int
minTicks
| Int
lTicks Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
maxTicks = UITiming -> Int -> UITiming
setLgTicks UITiming
ui Int
maxTicks
| Bool
otherwise = UITiming -> Int -> UITiming
setLgTicks UITiming
ui Int
lTicks
setLgTicks :: UITiming -> Int -> UITiming
setLgTicks UITiming
ui Int
lTicks = UITiming
ui {_lgTicksPerSecond = lTicks}
tickCount :: Lens' UITiming Int
frameCount :: Lens' UITiming Int
frameTickCount :: Lens' UITiming Int
lastInfoTime :: Lens' UITiming TimeSpec
lastFrameTime :: Lens' UITiming TimeSpec
accumulatedTime :: Lens' UITiming TimeSpec
data UIInventory = UIInventory
{ UIInventory -> Maybe (Int, List Name InventoryListEntry)
_uiInventoryList :: Maybe (Int, BL.List Name InventoryListEntry)
, UIInventory -> InventorySortOptions
_uiInventorySort :: InventorySortOptions
, UIInventory -> Maybe Text
_uiInventorySearch :: Maybe Text
, UIInventory -> Bool
_uiShowZero :: Bool
, UIInventory -> Bool
_uiInventoryShouldUpdate :: Bool
}
makeLensesNoSigs ''UIInventory
uiInventorySort :: Lens' UIInventory InventorySortOptions
uiInventorySearch :: Lens' UIInventory (Maybe Text)
uiInventoryList :: Lens' UIInventory (Maybe (Int, BL.List Name InventoryListEntry))
uiShowZero :: Lens' UIInventory Bool
uiInventoryShouldUpdate :: Lens' UIInventory Bool
data UIDialogs = UIDialogs
{ UIDialogs -> Maybe Modal
_uiModal :: Maybe Modal
, UIDialogs -> GoalDisplay
_uiGoal :: GoalDisplay
, UIDialogs -> StructureDisplay
_uiStructure :: StructureDisplay
, UIDialogs -> RobotDisplay
_uiRobot :: RobotDisplay
}
makeLensesNoSigs ''UIDialogs
uiModal :: Lens' UIDialogs (Maybe Modal)
uiGoal :: Lens' UIDialogs GoalDisplay
uiStructure :: Lens' UIDialogs StructureDisplay
uiRobot :: Lens' UIDialogs RobotDisplay
data UIGameplay = UIGameplay
{ UIGameplay -> FocusRing Name
_uiFocusRing :: FocusRing Name
, UIGameplay -> Maybe (Cosmic Coords)
_uiWorldCursor :: Maybe (Cosmic Coords)
, UIGameplay -> WorldEditor Name
_uiWorldEditor :: WorldEditor Name
, UIGameplay -> REPLState
_uiREPL :: REPLState
, UIGameplay -> UIInventory
_uiInventory :: UIInventory
, UIGameplay -> Bool
_uiScrollToEnd :: Bool
, UIGameplay -> UIDialogs
_uiDialogs :: UIDialogs
, UIGameplay -> Bool
_uiIsAutoPlay :: Bool
, UIGameplay -> Bool
_uiAutoShowObjectives :: Bool
, UIGameplay -> Bool
_uiShowREPL :: Bool
, UIGameplay -> Bool
_uiShowDebug :: Bool
, UIGameplay -> TimeSpec
_uiHideRobotsUntil :: TimeSpec
, UIGameplay -> UITiming
_uiTiming :: UITiming
, UIGameplay -> Maybe (ScenarioWith ScenarioPath)
_scenarioRef :: Maybe (ScenarioWith ScenarioPath)
}
makeLensesNoSigs ''UIGameplay
uiTiming :: Lens' UIGameplay UITiming
uiInventory :: Lens' UIGameplay UIInventory
uiFocusRing :: Lens' UIGameplay (FocusRing Name)
uiWorldCursor :: Lens' UIGameplay (Maybe (Cosmic Coords))
uiWorldEditor :: Lens' UIGameplay (WorldEditor Name)
uiREPL :: Lens' UIGameplay REPLState
uiScrollToEnd :: Lens' UIGameplay Bool
uiDialogs :: Lens' UIGameplay UIDialogs
uiIsAutoPlay :: Lens' UIGameplay Bool
uiAutoShowObjectives :: Lens' UIGameplay Bool
uiShowREPL :: Lens' UIGameplay Bool
uiShowDebug :: Lens' UIGameplay Bool
uiHideRobotsUntil :: Lens' UIGameplay TimeSpec
uiShowRobots :: Getter UIGameplay Bool
uiShowRobots :: Getter UIGameplay Bool
uiShowRobots = (UIGameplay -> Bool)
-> (Bool -> f Bool) -> UIGameplay -> f UIGameplay
forall (p :: * -> * -> *) (f :: * -> *) s a.
(Profunctor p, Contravariant f) =>
(s -> a) -> Optic' p f s a
to (\UIGameplay
ui -> UIGameplay
ui UIGameplay -> Getting TimeSpec UIGameplay TimeSpec -> TimeSpec
forall s a. s -> Getting a s a -> a
^. (UITiming -> Const TimeSpec UITiming)
-> UIGameplay -> Const TimeSpec UIGameplay
Lens' UIGameplay UITiming
uiTiming ((UITiming -> Const TimeSpec UITiming)
-> UIGameplay -> Const TimeSpec UIGameplay)
-> ((TimeSpec -> Const TimeSpec TimeSpec)
-> UITiming -> Const TimeSpec UITiming)
-> Getting TimeSpec UIGameplay TimeSpec
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (TimeSpec -> Const TimeSpec TimeSpec)
-> UITiming -> Const TimeSpec UITiming
Lens' UITiming TimeSpec
lastFrameTime TimeSpec -> TimeSpec -> Bool
forall a. Ord a => a -> a -> Bool
> UIGameplay
ui UIGameplay -> Getting TimeSpec UIGameplay TimeSpec -> TimeSpec
forall s a. s -> Getting a s a -> a
^. Getting TimeSpec UIGameplay TimeSpec
Lens' UIGameplay TimeSpec
uiHideRobotsUntil)
scenarioRef :: Lens' UIGameplay (Maybe (ScenarioWith ScenarioPath))