Talos docs

HudController

Since 0.6Changed in 0.7
Plain text

Signature

export class HudController {
  readonly strings: Strings
  readonly goals: GoalSpec[]
  readonly reached = new Set<string>()
  score = 0
  timeLeft: number | null = null
  constructor(ctx: Ctx, opts: HudOptions = {})
  static discoverGoals(ctx: Ctx): GoalSpec[]
  get currentGoal(): GoalSpec | null
  get total(): number
  get completed(): number
  get progressText(): string
  get done(): boolean
  start(): void
  complete(goalId: string): boolean
  handle(ev: GameEvent): boolean
  refresh(): void
  objective(textKey: string): void
  prompt(textKey: string | null): void
  timer(seconds: number | null): void
  startTimer(seconds: number): void
  stopTimer(): void
  setScore(value: number): void
  addScore(delta: number): void
  set(field: HudField, value: string | number | null, options?: HudFieldOptions): void
  update(dt: number): void
}

Import: import { HudController } from "@argus/gameplay"

Members

MemberSignatureDescription
stringsreadonly strings: Strings
goalsreadonly goals: GoalSpec[]
reachedreadonly reached = new Set<string>()
scorescore = 0Current score, as last published.
timeLefttimeLeft: number | null = nullRemaining countdown in seconds, or null when no timer is running.
constructorconstructor(ctx: Ctx, opts: HudOptions = {})
discoverGoalsstatic discoverGoals(ctx: Ctx): GoalSpec[]Every goal component in the scene, in contract order.
currentGoalget currentGoal(): GoalSpec | nullThe lowest-ordered goal not yet reached, or null when they are all done.
totalget total(): number
completedget completed(): number
progressTextget progressText(): string"2/5", the string published to the progress field.
doneget done(): boolean
startstart(): voidPublish the current objective and progress. Call once from init.
completecomplete(goalId: string): booleanMark a goal reached and republish. Returns false when the id is unknown or already reached. An unknown id is no longer dropped in silence. It is looked for once more — the goals may simply not have been discovered yet — and if it is still unknown it is remembered in pending and logged, so a mistyped labelKey or a goal-reached for something that is not a goal shows up in the run's log instead of as a HUD that never moves.
handlehandle(ev: GameEvent): booleanHandle one delivered event. Returns true when it was a goal event that moved the HUD on, which happens in the same tick the event is delivered.
refreshrefresh(): voidPush the objective and progress for the current state.
objectiveobjective(textKey: string): voidSet the objective explicitly, outside the goal sequence.
promptprompt(textKey: string | null): voidShow or hide a contextual prompt.
timertimer(seconds: number | null): voidShow a countdown without running it.
startTimerstartTimer(seconds: number): voidStart a countdown this controller ticks down in update.
stopTimerstopTimer(): voidStop and hide a running countdown.
setScoresetScore(value: number): void
addScoreaddScore(delta: number): void
setset(field: HudField, value: string | number | null, options?: HudFieldOptions): voidAny field, built-in or custom. Text values are keys and are checked against the string table. options give the field a label, a unit and fixed decimals (ctx.hud.set's; e.g. { unit: "km/h" }).
updateupdate(dt: number): voidTick a running countdown. Emits the timer event once when it reaches zero.