Skip to content

UiResources

The UiResources class renders the top HUD resource bar showing the player's current wood, stone, gold, tokens, and wave number. Values are abbreviated using the number-abbreviate library. It also triggers walkthrough step 1 completion when wood and stone both reach ≥ 10.

UiResources private

Extends UiComponent.

Properties

NameTypeDescription
uiUiCurrent Ui instance. Inherited from UiComponent.
componentElemHTMLElementThe root #hud-resources DOM element. Inherited from UiComponent.
woodElemHTMLElementThe .hud-resources-wood element.
stoneElemHTMLElementThe .hud-resources-stone element.
goldElemHTMLElementThe .hud-resources-gold element.
tokensElemHTMLElementThe .hud-resources-tokens element.
waveElemHTMLElementThe .hud-resources-wave element.
lastPlayerTickobjectCached previous tick values for change detection.

Methods

constructor()

ts
function constructor(ui: Ui): void

Initializes the resource bar, queries all resource elements, and registers a listener for playerTickUpdate.

onPlayerTickUpdate()

ts
function onPlayerTickUpdate(playerTick: { wood: number, stone: number, gold: number, token: number, wave: number }): void

Updates each resource display only when its value changes, using numberAbbreviate for formatting. Updates wave display when wave > 0 and changed. Marks walkthrough step 1 as completed when wood ≥ 10 and stone ≥ 10.