Pings, floating numbers and unit plates
What players see over the world: pings sent to the team, floating numbers and words (damage, healing, xp, gold), and the plate above each unit (name, health and mana bars, buffs). Anything another player must see goes through the simulation; what only draws stays in the client.
Quick start
import { presetFloats, presetPings, type GameView, type UnitHudDef } from '@v12-engine/client'
const hero: UnitHudDef = {
plates: [
{
show: 'always',
items: [
{ text: (unit) => unit.def.name, size: 12 },
{ bar: 'health', ghost: { seconds: 0.6 } },
{ bar: 'mana', height: 3 }
]
}
]
}
export const view: GameView = {
units: { looks: {}, hud: { def: hero } }, // a plate over every unit
pings: { kinds: presetPings(['look', 'danger', 'assist', 'onMyWay', 'missing', 'retreat']) }, // Ctrl + left button opens the wheel
hud: { floats: presetFloats() } // damage, heals, xp, mana, gold, level up…
}Every unit gets a name, a health bar with a fading "ghost" of lost health, and a mana bar. Players get a ping wheel of six, and numbers float off units as things happen. The melee example has all three (apps/example/src/games/melee).
Common tasks
Float your own words
import type { GameClientApi } from '@v12-engine/client'
declare const client: GameClientApi
declare const unitId: number
client.floats.show('Rally!', { on: unitId })show returns a FloatHandle to update the number or end it. This screen only. For a number others must see, send an event of your own with defineEvent({ id, replicate }) and float it by its id.
Change how damage floats
Each kind is a FloatDef, a function of what's floated, or null for none:
import { presetFloats, type FloatSet } from '@v12-engine/client'
export const floats: FloatSet = {
...presetFloats(),
damage: { text: '-{amount}', style: { color: '#ff5040', size: 16 }, motion: { rise: 1.2 }, seconds: 0.9, merge: { key: 'entity', window: 0.3, countUp: 0.4 } },
xp: null
}Give it to the view as hud: { floats }. merge turns fast hits into one number that counts up.
Send a ping from code
import type { GameClientApi } from '@v12-engine/client'
declare const client: GameClientApi
client.pings.send('danger', { x: 40, z: 22 })Players ping with Alt + left click (the first kind) or Ctrl + left hold (the wheel: drag to pick, release to send).
Show a different plate for enemies
plates are tried in order; the first whose when holds is drawn.
import type { UnitHudDef } from '@v12-engine/client'
export const plates: UnitHudDef = {
plates: [
{ when: { relation: ['enemy'] }, items: [{ bar: 'health', color: '#e03030' }] },
{ items: [{ bar: 'health' }, { bar: 'mana', height: 3 }] }
],
within: 40 // cells from the camera
}Set a plate for one unit type with UnitLook.unitHud, or for one unit on this screen with client.unitHud.set(id, def).
Show the orders queued
While Shift is held, selected units show lines and flags to their queued orders. Colour them with GameView.fx.marks.waypoints = { color }; false draws none.
Editor
- Pings: the Look panel's Pings fold edits
pings.json. - Floating words: the Words panel edits
floats.json. - Plates: the Unit HUD panel edits
hud.json. - Save the map (Ctrl+S). Changes apply at once in a game played from the editor.
A def with functions is "made its own" in the editor first; the parts in code are listed and left out.
Reference
Pings (PingDef)
Label, short word, glyph or picture, colour, chat line (says), sound, effect at the spot (fx), seconds, audience (allies default, or all), place on the wheel, cooldown, focus (clicking the chat line looks there), render ('scene', 'overlay', or a PingDraw). presetPings(kinds?, over?) gives nine: look, danger, need help, on my way, hold, push, enemy missing, fall back, a question.
- The wheel's look:
GameView.pings.wheel(PingWheelLook: radius, dead zone, item size, slots, labels). - In code:
client.pings(defs,def,define,remove,send(kind, point, to?),canSend,cooldownLeft,quick,onPing),client.pingWheel(show,aim,release,cancel,state,look). - Rules:
RuleSettings.talk.pings.kindslists the kinds allowed (pingKindsOf(defs), orpingKinds(registry)for kinds added inpings.json);RuleSettings.talk.pingslimits how often;beforeTalkcan mute, rewrite or redirect;RuleSettings.talk.pings.meaningssays what a kind asks of a computer ally (help,attack,defend,rally,ignore).
Floats (FloatDef, GameView.hud.floats)
Kinds: damage (dealt by others), damageTaken, crit, miss, heal, xp, mana, bounty, levelUp, buff, deny, resource (resource.<pool>), sleep, and any game event by id. A kind left out floats nothing.
| Part | What it sets |
|---|---|
| Words | '-{amount}', '{+amount} xp', any param in braces, or a function |
| Style | style: font, size, weight, colour, outline, box, icon, opacity, lit |
| Motion | motion: rise, drift, arc, pop, bounce, shake, scaleBy the amount, custom; each with an ease |
| Place | at, offset, spread, follow |
| Budget | within cells of the camera, most at once |
merge | { key, window, mode, countUp, pulse, restart }: fast hits become one growing number |
render | canvas (default), dom, gui, world, or your own drawing |
In code: client.floats.show, set(kind, def | null), def(kind), kinds, clear(), shown; the same from a renderer of the game's, through the client. A def whose code throws turns its kind off, logged once.
Plates (UnitHudDef)
Widgets: bar, text, badge, icon, portrait, ring, abilities (cooldowns swept), buffs (time left swept), row, column, stack, space, and your own dom, gui or draw. Every field is a value or a function of the unit. Full widget list: Scenes and the screen.
| Field | What it does |
|---|---|
plates | Tried in order; the first whose when holds is drawn: relation (self, ally, enemy, neutral), selected, hovered, hurt, asleep, constructing, remembered, or a function (of). [] for none |
within, far | Cells from the camera, and a plate for past that |
fixedSize, sizeAt | A fixed size, or a size by distance |
above | Height above the head |
fade | Fade as the plate changes |
audience | Who sees it; also every widget's for |
render | Overlay canvas (default), 'dom' (one element a plate, CSS: PLATE_CSS, --fill), 'gui' |
Where a unit's plate comes from, first found: client.unitHud.set(id, …), client.unitHud.defs.set(type, …), UnitLook.unitHud, GameView.units.hud.def, the client's plain plate. GameView.units.hud.look holds defaults; GameView.units.hud.system replaces the whole system.
Who sees what
Decided on the host per seat; a screen that isn't sent something can't show it.
| What | Reaches | Changed by |
|---|---|---|
| A ping | the sender's allies and observers; all with to: 'all' | PingDef.audience, client.pings.send(kind, point, to), beforeTalk |
| Damage, healing, crits, miss | everyone who sees the target | (the fog) |
| Bounty | the player paid | |
| Xp, mana, a pool | the owner, allies, observers | your own event with defineEvent({ id, replicate }) |
| Health, mana, level, buffs | everyone who sees the unit | |
| Abilities, cooldowns, xp | the owner and allies | RuleSettings.hud.shareAbilities, shareXp |
| Buff time left | nobody unless shared | RuleSettings.hud.shareBuffTimes (true, 'allies', a function) |
| Your own data on a plate | as its component's replicate says | defineComponent({ id, replicate, snapshot }), read with hudData(entity, component) |
A widget's for: 'allies' only hides; it isn't a secret. What an enemy mustn't know is never sent. More: Multiplayer. Replays play pings and floats back as they were.
Layers
| Layer | What draws there |
|---|---|
scene, with the world | floats with render: 'world' (hidden by what stands before them) |
scene, over the world | a ping's mark (default): over trees and units, kept a size on screen |
bars (overlay canvas) | plates and floats (default, and render: 'gui'), ping labels and 'overlay' marks, a canvas wheel |
world (HTML over the game) | plates (.vg-hud) and floats (.vg-float) with render: 'dom', widgets' elements |
| the HUD | the ping wheel (pingWheel), ping chat lines |
The overlay canvas is the cheap default: a thousand words a frame cost little there. See The interface.
Files
| File | Laid over the code with | Edited in |
|---|---|---|
pings.json | [PINGS_FILE, file] in layFiles | the Pings fold (editor) |
floats.json | [FLOATS_FILE, file] | the Words panel (editor) |
hud.json | [HUD_FILE, file], after LOOKS_FILE | the Unit HUD panel (editor) |
A kind in a file replaces the code's whole; null removes one. For ping kinds added in pings.json, the rules read the file as a game file (Rules.files: [defineGameFile({ id: 'pings.json', data, read })]) and list kinds with pingKinds(registry). In code: readPingsFile, pingsText, plainPing, readFloatsFile, floatsText, plainFloat, readHudFile, hudText, plainHud, FloatPreview, HudPreview.
Cost
Measured on 170 units and 5,600 trees: every float kind on in a fight, 0.005 ms a frame; a full plate on every unit, about 0.2 ms (twice that as HTML). A ping costs nothing while none is up. Benches: npm run bench in packages/bench (floats.bench.ts, nameplates.bench.ts, net.bench.ts).