Skip to content

Change the plate over a unit ​

The plate over a unit's head is a tree of widgets (UnitHudPlate). A UnitHudDef holds plates and says which shows for whom, when, and how far away. Set the default in GameView.units.hud.def, or a type's own in its look's unitHud.

ts
// in src/game.ts
import { type GameView, type UnitHudDef } from '@v12-engine/client'
import { createGame } from '@v12-engine/engine'
import { rules } from './rules'

const hero: UnitHudDef = {
	plates: [
		// the player's own and allies: picture, name, level, health with what was just lost draining, mana, abilities, buffs
		{
			when: { relation: ['self', 'ally'] },
			show: 'always',
			items: [
				{
					row: [
						{ portrait: true, size: 26, border: 'owner' },
						{
							column: [
								{ text: (unit) => unit.def.name, size: 12, color: 'owner' },
								{ bar: 'health', width: 84, ghost: { seconds: 0.6 }, ticks: 100 },
								{ bar: 'mana', width: 84, height: 3 }
							]
						},
						{ badge: (unit) => unit.level ?? 1, size: 16 }
					],
					gap: 3
				},
				{ abilities: 'own', size: 14, gap: 2 },
				{ buffs: 'all', size: 12, dots: true }
			]
		},
		// everyone else: health alone, with its points when selected
		{ when: { selected: true }, show: 'always', items: [{ bar: 'health', label: 'value', height: 10 }] },
		{ show: 'always', items: [{ bar: 'health' }] }
	],
	// past 45 cells of the camera, a dot in its side's colour
	within: 45,
	far: { show: 'always', items: [{ ring: 'health', size: 8 }] }
}

export const view: GameView = {
	units: {
		looks: {
			paladin: { height: 1.8, shapes: [], model: { src: 'units/paladin.glb', scale: 1 }, unitHud: hero },
			// trees and mines: nothing over them
			goldMine: { height: 2.5, shapes: [], model: { src: 'buildings/mine.glb', scale: 1 }, unitHud: { plates: [] } }
		},
		hud: {
			// every other unit: health when hurt
			def: { plates: [{ show: 'hurt', items: [{ bar: 'health', ghost: { seconds: 0.5 } }] }] },
			// the defaults of every def: drawn as HTML, faded in and out
			look: { render: 'dom', fade: 0.2 }
		}
	}
}

export const game = createGame(rules).view(view)

Done: your paladin shows portrait, name, level, draining health, mana, abilities and buffs to you and allies; enemies see a health bar; past 45 cells it's a dot. Mines show nothing.

Change a plate in code, on this screen only ​

ts
client.unitHud.set(heroId, { plates: [{ show: 'always', items: [{ text: 'Target', color: '#ff4040' }, { bar: 'health' }] }] })
client.unitHud.set(heroId, undefined) // back to its type's
client.unitHud.defs.set('footman', { plates: [{ show: 'always', items: [{ bar: 'health' }] }] })
client.unitHud.look.within = 60
console.log(client.unitHud.plate(heroId)) // the plate it shows now

In the editor ​

  1. Open the Unit HUD panel (the heart on the right rail). A unit type stands on a stage with its plate drawn live.
  2. Turn the knobs (health, mana, level, buffs, selection, viewer) to test it.
  3. Edit plates, when and widgets. Texts and badges can say {level} and {name}.
  4. It writes hud.json, laid over the view with layFiles (HUD_FILE, after LOOKS_FILE).

Reference ​

WidgetShows
barhealth, mana…; ghost drains what was lost, ticks, label.
textWords, or {level} / {name} as data.
badgeA small number, like a level.
portraitThe unit's picture.
abilities, buffsTheir icons.
ringA round bar.
row, columnLayout.
Plate fieldWhat it does
whenrelation (self, ally…), selected…
showalways, hurt…
within, farBeyond this distance, show the far plate.
look.rendercanvas (default), dom (styled by CSS) or gui.

Every field takes a value or a function of the unit. Enemies' plates show no abilities or cooldowns unless the rules share them (RuleSettings.hud). A number of your own reaches other screens through a component with replicate, read with hudData(unit, component). See Pings, floating words and plates and Multiplayer.