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 nowIn the editor
- Open the Unit HUD panel (the heart on the right rail). A unit type stands on a stage with its plate drawn live.
- Turn the knobs (health, mana, level, buffs, selection, viewer) to test it.
- Edit plates,
whenand widgets. Texts and badges can say{level}and{name}. - It writes
hud.json, laid over the view withlayFiles(HUD_FILE, afterLOOKS_FILE).
Reference
| Widget | Shows |
|---|---|
bar | health, mana…; ghost drains what was lost, ticks, label. |
text | Words, or {level} / {name} as data. |
badge | A small number, like a level. |
portrait | The unit's picture. |
abilities, buffs | Their icons. |
ring | A round bar. |
row, column | Layout. |
| Plate field | What it does |
|---|---|
when | relation (self, ally…), selected… |
show | always, hurt… |
within, far | Beyond this distance, show the far plate. |
look.render | canvas (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.