Shared

scalata.infrastructure.view.terminal.Shared
object Shared

Terminal-view helper utilities shared.

Responsibilities
• Wire a map GameControllerState ⇒ Controller[F] so that the GameEngine
can route the state machine to the correct controller. • Provide a generic run loop that repeatedly asks the user for input until the supplied parse function succeeds.
• Offer small helper parsers (e.g. booleanParse) used by several interactive screens.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Shared.type

Members list

Value members

Concrete methods

def booleanParse(raw: String): Option[Boolean]

Parse a yes/no question.

Parse a yes/no question.

Accepts only a single-letter y or n (case-insensitive), trimmed of surrounding white-space.

Value parameters

raw

user-supplied string

Attributes

Returns

Some(true) if "y" Some(false) if "n" None otherwise

def getControllersMap[F[_] : Sync](view: GameView[F, String]): GameControllerState => Controller[F]

Build the state → controller lookup table for the terminal UI.

Build the state → controller lookup table for the terminal UI.

Type parameters

F

effect type (e.g. IO) in which controllers operate

Value parameters

view

shared GameView used by all controllers for rendering and input

Attributes

Returns

a partial function: given the current scalata.domain.util.GameControllerState, return the corresponding controller instance

def run[F[_] : Sync, I, O](gameView: GameView[F, I], parse: I => Option[O]): F[O]

Generic input loop that keeps asking the player until parse returns Some.

Generic input loop that keeps asking the player until parse returns Some.

Value parameters

gameView

view through which we display prompts / errors and read input

parse

function that tries to convert raw input I to domain value O

Attributes

Returns

the successfully parsed value wrapped in the effect F