swarm-0.5.0.0: 2D resource gathering game with programmable robots
LicenseBSD-3-Clause
Safe HaskellSafe-Inferred
LanguageHaskell2010

Swarm.TUI.Model

Description

Application state for the brick-based Swarm TUI.

Synopsis

Custom UI label types

These types are used as parameters to various brick types.

data AppEvent Source #

AppEvent represents a type for custom event types our app can receive. The primary custom event Frame is sent by a separate thread as fast as it can, telling the TUI to render a new frame.

Instances

Instances details
Show AppEvent Source # 
Instance details

Defined in Swarm.TUI.Model

newtype WebCommand Source #

Constructors

RunWebCode Text 

Instances

Instances details
Show WebCommand Source # 
Instance details

Defined in Swarm.TUI.Model

data FocusablePanel Source #

Constructors

REPLPanel

The panel containing the REPL.

WorldPanel

The panel containing the world view.

WorldEditorPanel

The panel containing the world editor controls.

RobotPanel

The panel showing robot info and inventory on the top left.

InfoPanel

The info panel on the bottom left.

Instances

Instances details
Bounded FocusablePanel Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Enum FocusablePanel Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Read FocusablePanel Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Show FocusablePanel Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Eq FocusablePanel Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Ord FocusablePanel Source # 
Instance details

Defined in Swarm.TUI.Model.Name

data Name Source #

Name represents names to uniquely identify various components of the UI, such as forms, panels, caches, extents, lists, and buttons.

Constructors

FocusablePanel FocusablePanel 
WorldEditorPanelControl WorldEditorFocusable

An individual control within the world editor panel.

REPLInput

The REPL input form.

REPLHistoryCache

The REPL history cache.

WorldCache

The render cache for the world view.

WorldExtent

The cached extent for the world view.

WorldPositionIndicator

The cursor/viewCenter display in the bottom left of the World view

EntityPaintList

The list of possible entities to paint a map with.

EntityPaintListItem Int

The entity paint item position in the EntityPaintList.

TerrainList

The list of possible terrain materials.

TerrainListItem Int

The terrain item position in the TerrainList.

InventoryList

The list of inventory items for the currently focused robot.

InventoryListItem Int

The inventory item position in the InventoryList.

MenuList

The list of main menu choices.

AchievementList

The list of achievements.

ScenarioConfigControl ScenarioConfigPanel

An individual control within the scenario launch config panel

GoalWidgets GoalWidget

The list of goals/objectives.

ScenarioList

The list of scenario choices.

InfoViewport

The scrollable viewport for the info panel.

ModalViewport

The scrollable viewport for any modal dialog.

REPLViewport

The scrollable viewport for the REPL.

Button Button

A clickable button in a modal dialog.

Instances

Instances details
Read Name Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Show Name Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Methods

showsPrec :: Int -> Name -> ShowS #

show :: Name -> String #

showList :: [Name] -> ShowS #

Eq Name Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Methods

(==) :: Name -> Name -> Bool #

(/=) :: Name -> Name -> Bool #

Ord Name Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Methods

compare :: Name -> Name -> Ordering #

(<) :: Name -> Name -> Bool #

(<=) :: Name -> Name -> Bool #

(>) :: Name -> Name -> Bool #

(>=) :: Name -> Name -> Bool #

max :: Name -> Name -> Name #

min :: Name -> Name -> Name #

Menus and dialogs

data ScenarioOutcome Source #

Constructors

WinModal 
LoseModal 

Instances

Instances details
Show ScenarioOutcome Source # 
Instance details

Defined in Swarm.TUI.Model.Menu

data Button Source #

Clickable buttons in modal dialogs.

Instances

Instances details
Bounded Button Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Enum Button Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Read Button Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Show Button Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Eq Button Source # 
Instance details

Defined in Swarm.TUI.Model.Name

Methods

(==) :: Button -> Button -> Bool #

(/=) :: Button -> Button -> Bool #

Ord Button Source # 
Instance details

Defined in Swarm.TUI.Model.Name

data MainMenuEntry Source #

Instances

Instances details
Bounded MainMenuEntry Source # 
Instance details

Defined in Swarm.TUI.Model.Menu

Enum MainMenuEntry Source # 
Instance details

Defined in Swarm.TUI.Model.Menu

Read MainMenuEntry Source # 
Instance details

Defined in Swarm.TUI.Model.Menu

Show MainMenuEntry Source # 
Instance details

Defined in Swarm.TUI.Model.Menu

Eq MainMenuEntry Source # 
Instance details

Defined in Swarm.TUI.Model.Menu

Ord MainMenuEntry Source # 
Instance details

Defined in Swarm.TUI.Model.Menu

data Menu Source #

Constructors

NoMenu

We started playing directly from command line, no menu to show

MainMenu (List Name MainMenuEntry) 
NewGameMenu (NonEmpty (List Name ScenarioItem))

Stack of scenario item lists. INVARIANT: the currently selected menu item is ALWAYS the same as the scenario currently being played. See https://github.com/swarm-game/swarm/issues/1064 and https://github.com/swarm-game/swarm/pull/1065.

AchievementsMenu (List Name CategorizedAchievement) 
MessagesMenu 
AboutMenu 

mkScenarioList :: Bool -> ScenarioCollection -> List Name ScenarioItem Source #

Create a brick List of scenario items from a ScenarioCollection.

mkNewGameMenu :: Bool -> ScenarioCollection -> FilePath -> Maybe Menu Source #

Given a ScenarioCollection and a FilePath which is the canonical path to some folder or scenario, construct a NewGameMenu stack focused on the given item, if possible.

UI state

REPL

data REPLHistItem Source #

An item in the REPL history.

Constructors

REPLEntry Text

Something entered by the user.

REPLOutput Text

A response printed by the system.

REPLError Text

An error printed by the system.

replItemText :: REPLHistItem -> Text Source #

Get the text of REPL input/output.

isREPLEntry :: REPLHistItem -> Bool Source #

Useful helper function to filter out REPL output.

getREPLEntry :: REPLHistItem -> Maybe Text Source #

Useful helper function to only get user input text.

data REPLHistory Source #

History of the REPL with indices (0 is first entry) to the current line and to the first entry since loading saved history. We also (ab)use the length of the REPL as the index of current input line, since that number is one past the index of last entry.

Instances

Instances details
Show REPLHistory Source # 
Instance details

Defined in Swarm.TUI.Model.Repl

replIndex :: Lens' REPLHistory Int Source #

The current index in the REPL history (if the user is going back through the history using up/down keys).

replLength :: REPLHistory -> Int Source #

Current number lines of the REPL history - (ab)used as index of input buffer.

replSeq :: Lens' REPLHistory (Seq REPLHistItem) Source #

Sequence of REPL inputs and outputs, oldest entry is leftmost.

newREPLHistory :: [REPLHistItem] -> REPLHistory Source #

Create new REPL history (i.e. from loaded history file lines).

addREPLItem :: REPLHistItem -> REPLHistory -> REPLHistory Source #

Add new REPL input - the index must have been pointing one past the last element already, so we increment it to keep it that way.

restartREPLHistory :: REPLHistory -> REPLHistory Source #

Point the start of REPL history after current last line. See replStart.

getLatestREPLHistoryItems :: Int -> REPLHistory -> [REPLHistItem] Source #

Get the latest N items in history, starting with the oldest one.

This is used to show previous REPL lines in UI, so we need the items sorted in the order they were entered and will be drawn top to bottom.

data TimeDir Source #

Constructors

Newer 
Older 

Instances

Instances details
Show TimeDir Source # 
Instance details

Defined in Swarm.TUI.Model.Repl

Eq TimeDir Source # 
Instance details

Defined in Swarm.TUI.Model.Repl

Methods

(==) :: TimeDir -> TimeDir -> Bool #

(/=) :: TimeDir -> TimeDir -> Bool #

Ord TimeDir Source # 
Instance details

Defined in Swarm.TUI.Model.Repl

Prompt utils

data REPLPrompt Source #

This data type tells us how to interpret the text typed by the player at the prompt (which is stored in Editor).

Constructors

CmdPrompt [Text]

Interpret the prompt text as a regular command. The list is for potential completions, which we can cycle through by hitting Tab repeatedly

SearchPrompt REPLHistory

Interpret the prompt text as "search this text in history"

removeEntry :: Text -> REPLHistory -> REPLHistory Source #

Given some text, removes the REPLEntry within REPLHistory which is equal to that. This is used when the user enters in search mode and want to traverse the history. If a command has been used many times, the history will be populated with it causing the effect that search command always finds the same command.

Inventory

data InventoryListEntry Source #

An entry in the inventory list displayed in the info panel. We can either have an entity with a count in the robot's inventory, an entity equipped on the robot, or a labelled separator. The purpose of the separators is to show a clear distinction between the robot's inventory and its equipped devices.

Instances

Instances details
Eq InventoryListEntry Source # 
Instance details

Defined in Swarm.TUI.Model.Menu

REPL Panel Model

data ReplControlMode Source #

What is being done with user input to the REPL panel?

Constructors

Typing

The user is typing at the REPL.

Piloting

The user is driving the base using piloting mode.

Handling

A custom user key handler is processing user input.

replPromptType :: Lens' REPLState REPLPrompt Source #

The way we interpret text typed by the player in the REPL prompt.

replPromptEditor :: Lens' REPLState (Editor Text Name) Source #

The prompt where the user can type input at the REPL.

replPromptText :: Lens' REPLState Text Source #

Convenience lens to get text from editor and replace it with new one that has the provided text.

replValid :: Lens' REPLState Bool Source #

Whether the prompt text is a valid Term.

replLast :: Lens' REPLState Text Source #

The last thing the user has typed which isn't part of the history. This is used to restore the repl form after the user visited the history.

replType :: Lens' REPLState (Maybe Polytype) Source #

The type of the current REPL input which should be displayed to the user (if any).

replControlMode :: Lens' REPLState ReplControlMode Source #

The current REPL control mode, i.e. how user input to the REPL panel is being handled.

replHistory :: Lens' REPLState REPLHistory Source #

History of things the user has typed at the REPL, interleaved with outputs the system has generated.

Updating

populateInventoryList :: MonadState UIState m => Maybe Robot -> m () Source #

Given the focused robot, populate the UI inventory list in the info panel with information about its inventory.

Runtime state

webPort :: Lens' RuntimeState (Maybe Port) Source #

The port on which the HTTP debug service is running.

eventLog :: Lens' RuntimeState (Notifications LogEntry) Source #

A log of runtime events.

This logging is separate from the logging done during game-play. If some error happens before a game is even selected, this is the place to log it.

worlds :: Lens' RuntimeState WorldMap Source #

A collection of typechecked world DSL terms that are available to be used in scenario definitions.

scenarios :: Lens' RuntimeState ScenarioCollection Source #

The collection of scenarios that comes with the game.

stdEntityMap :: Lens' RuntimeState EntityMap Source #

The standard entity map loaded from disk. Individual scenarios may define additional entities which will get added to this map when loading the scenario.

stdRecipes :: Lens' RuntimeState [Recipe Entity] Source #

The standard list of recipes loaded from disk. Individual scenarios may define additional recipes which will get added to this list when loading the scenario.

appData :: Lens' RuntimeState (Map Text Text) Source #

Free-form data loaded from the data directory, for things like the logo, about page, tutorial story, etc.

nameParts :: Lens' RuntimeState NameGenerator Source #

Lists of words/adjectives for use in building random robot names.

Utility

logEvent :: LogSource -> Severity -> Text -> Text -> Notifications LogEntry -> Notifications LogEntry Source #

Simply log to the runtime event log.

App state

data AppState Source #

The AppState just stores together the other states.

This is so you can use a smaller state when e.g. writing some game logic or updating the UI. Also consider that GameState can change when loading a new scenario - if the state should persist games, use RuntimeState.

Initialization

data AppOpts Source #

Command-line options for configuring the app.

Constructors

AppOpts 

Fields

defaultAppOpts :: AppOpts Source #

A default/empty AppOpts record.

type Seed = Int Source #

Re-exported types used in options

data ColorMode #

Instances

Instances details
Show ColorMode 
Instance details

Defined in Graphics.Vty.Attributes.Color

Eq ColorMode 
Instance details

Defined in Graphics.Vty.Attributes.Color

Utility

topContext :: AppState -> RobotContext Source #

Context for the REPL commands to execute in. Contains the base robot context plus the it variable that refer to the previously computed values. (Note that `it{n}` variables are set in the base robot context; we only set it here because it's so transient)

focusedItem :: AppState -> Maybe InventoryListEntry Source #

Get the currently focused InventoryListEntry from the robot info panel (if any).

focusedEntity :: AppState -> Maybe Entity Source #

Get the currently focused entity from the robot info panel (if any). This is just like focusedItem but forgets the distinction between plain inventory items and equipped devices.

nextScenario :: Menu -> Maybe ScenarioInfoPair Source #

Extract the scenario which would come next in the menu from the currently selected scenario (if any). Can return Nothing if either we are not in the NewGameMenu, or the current scenario is the last among its siblings.