ui
The ui component is the central manager for the game's HUD. It orchestrates multiple components, handles user input (keyboard/mouse) and synchronizes game state (inventory, buildings, parties).
Ui public
Bounded to game as game.ui. Extends EventEmitter, alias: game.uiType.
The Ui class initializes the HUD structure, appends it to the DOM, and manages the lifecycle of all HUD components. It also serves as the primary event bus for UI-related updates.
Properties
| Property | Type | Description |
|---|---|---|
components | object | Map of registered UI components. |
buildings | object | Currently placed buildings owned by the player/party. |
buildingSchema | object | Data defining building costs, health, and limits. |
inventory | object | Current items held by the player. |
itemSchema | object | Data defining item costs and tiers. |
spellSchema | object | Data defining spell costs and cooldowns. |
parties | object | Information about all parties in the game. |
playerTick | object | The most recent tick data for the local player. |
mousePosition | object | Current {x, y} coordinates of the mouse. |
isMouseDown | boolean | Whether the primary mouse button is currently held down. |
Core Methods
constructor()
function constructor(): voidInitializes the UI system, sets up HUD containers, registers all components, and binds event listeners for input and network updates.
addComponent()
function addComponent(name: string, component: object, anchor: number = null): voidRegisters a new UI component and appends its element to the specified UiAnchor.
getComponent()
function getComponent(name: string): objectReturns the component instance registered under the given name.
createElement()
function createElement(html: string): HTMLElementHelper method to convert an HTML string into a DOM element.
Getters & Setters
getBuildings()
function getBuildings(): objectReturns the map of placed buildings.
getBuildingSchema()
function getBuildingSchema(): objectReturns the building metadata schema.
getInventory()
function getInventory(): objectReturns the player's current inventory.
getItemSchema()
function getItemSchema(): objectReturns the item metadata schema.
getSpellSchema()
function getSpellSchema(): objectReturns the spell metadata schema.
getParties()
function getParties(): objectReturns the list of active parties.
getPlayerTick()
function getPlayerTick(): objectReturns the latest player state tick.
setPlayerTick()
function setPlayerTick(tick: object): voidUpdates the local player state. Triggers logic for party changes, weapon/hat/pet updates, and invulnerability status. Emits playerTickUpdate.
getPlayerWeaponName()
function getPlayerWeaponName(): stringReturns the name of the equipped weapon.
getPlayerHatName()
function getPlayerHatName(): stringReturns the name of the equipped hat.
getPlayerPetUid()
function getPlayerPetUid(): numberReturns the UID of the equipped pet.
getPlayerPetName()
function getPlayerPetName(): stringReturns the name of the equipped pet.
getPlayerPetTick()
function getPlayerPetTick(): objectReturns the latest state tick for the pet.
getPlayerPartyId()
function getPlayerPartyId(): numberReturns the player's current party ID.
getPlayerPartyMembers()
function getPlayerPartyMembers(): ArrayReturns the list of party members.
getPlayerPartyShareKey()
function getPlayerPartyShareKey(): stringReturns the party's private share key.
getPlayerPartyLeader()
function getPlayerPartyLeader(): booleanReturns true if the player is the party leader.
getPlayerPartyCanSell()
function getPlayerPartyCanSell(): booleanReturns true if the player has permission to sell buildings.
getOption()
function getOption(key: string): anyRetrieves a value from the UI options.
setOption()
function setOption(key: string, value: any): voidSets a value in the UI options.
getMousePosition()
function getMousePosition(): objectReturns the current mouse {x, y} position.
getIsMouseDown()
function getIsMouseDown(): booleanReturns true if the mouse button is pressed.
getIsWavePaused()
function getIsWavePaused(): booleanReturns true if the game wave is currently paused.
Utility Helpers
useHealthPotion()
function useHealthPotion(): voidEmits a request to equip/use a Health Potion if available in the inventory.
cycleWeapon()
function cycleWeapon(): voidCycles through available weapons in the inventory (Pickaxe → Spear → Bow → Bomb).
Input Handlers
These methods handle raw input events from the InputManager.
| Method | Description |
|---|---|
onMouseDown() | Handles building placement if PlacementOverlay is active. |
onMouseUp() | Handles building selection/watching and spell casting. |
onMouseRightUp() | Cancels current placement, casting, or building watching. |
onMouseMoved() | Updates mouse coordinates and notifies overlays. |
onMouseMovedWhileDown() | Handles continuous building placement during drag. |
onKeyPress() | Handles Shift key state for "Upgrade All" and continuous placement while moving. |
onKeyRelease() | Maps keys to UI actions. |
Keyboard Shortcuts
| Key | Action |
|---|---|
| Esc | Cancels current actions (placing, casting) and hides menus. |
| Enter | Starts chat typing. |
| P | Toggles the Party menu. |
| B / O | Toggles the Shop menu. |
| R | Cycles building direction. |
| E | Upgrades the currently watched building. |
| T | Sells the currently watched building. |
| F | Uses a Health Potion. |
| Q | Cycles weapons. |
| Shift | Toggles "Upgrade All" mode in the BuildingOverlay. |
| 0-9 | Shortcuts for placing buildings as defined in the building schema. |
Network & State Listeners
These methods synchronize the UI with network RPCs and game events.
| Method | Description |
|---|---|
onConnectionOpen() / onConnectionClose() | Handles the visibility of the Reconnect overlay. |
onEnterWorld() | Resets UI state (inventory, buildings, parties) when successfully joining a server. |
onServerShuttingDown() | Displays a high-priority announcement overlay. |
onLocalBuildingUpdate() | Synchronizes the local buildings list and updates building limits based on stash status. |
onLocalItemUpdate() | Updates the local inventory object. |
onBuildingSchemaUpdate() / onItemSchemaUpdate() / onSpellSchemaUpdate() | Parses JSON data from the server to populate the respective schemas (costs, health, damage, etc.). |
onPartyInfoUpdate() | Updates party membership, leader status, and recalculates building limits based on party size. |
onPartyShareKeyUpdate() | Updates the party's share key. |
onAddParty() / onRemoveParty() / onSetPartyList() | Manages the global list of parties available in the world. |
onGenericFailure() | Displays localized error hints (e.g., "Too far from stash", "Not enough resources") via the PopupOverlay. |
onPlayerDeath() | Hides active menus and cancels overlays when the player dies. |
onItemEquippedOrUsed() | Cancels building/spell overlays when a new weapon is equipped. |
onDragOver() | Prevents default browser drag behavior. |
onBeforeUnload() | Prompts the user for confirmation if they try to leave the page while alive in the world. |
Enumerations
UiAnchor private
An enumeration used to position components within the HUD containers.
| Constant | Value |
|---|---|
TOP_LEFT | 1 |
TOP_CENTER | 2 |
TOP_RIGHT | 3 |
BOTTOM_LEFT | 4 |
BOTTOM_CENTER | 5 |
BOTTOM_RIGHT | 6 |
CENTER_LEFT | 7 |
CENTER_RIGHT | 8 |