Add a HUD part, or replace one
List parts in the view's hud.widgets: add your own at a place of the layout, move or frame the client's, or replace one. hud.hide removes parts. A part is a Solid component or any element of your own.
// in src/game.tsx
import { type GameView, type HudClient } from '@v12-engine/client'
import { createGame } from '@v12-engine/engine'
import { render } from 'solid-js/web'
import { rules } from './rules'
/** The game's own part: what is selected, counted by type, read off the client's signals */
function Selected(props: { client: HudClient }) {
const counts = () => {
const out = new Map<string, number>()
for (const item of props.client.ui.selection()) out.set(item.name, (out.get(item.name) ?? 0) + 1)
return [...out]
}
return (
<ul class='text-[13px]'>
{counts().map(([name, count]) => (
<li>
{count} × {name}
</li>
))}
</ul>
)
}
export const view: GameView = {
units: {
looks: {}
},
hud: {
// gone
hide: ['clock', 'layoutButton'],
widgets: [
// a part of the game's own, in a column over the map under the tray, while something is selected
{
id: 'mygame.selected',
place: 'top-right',
when: (client) => client.ui.selection().length > 0,
mount: (element, client) => render(() => <Selected client={client} />, element)
},
// the client's own part (the children) in a frame of yours
{ id: 'minimap', component: (props) => <div class='rounded-xl border-2 border-amber-700 p-1'>{props.children}</div> },
// an element of your own in its place: any HTML, told as what it reads changes, and what takes it away
{
id: 'resources',
mount: (element, client) =>
client.ui.watch(
() => client.ui.resources().amounts,
(amounts) => (element.textContent = amounts.map((each) => `${each.name} ${each.amount}`).join(' ')),
{ immediate: true }
)
},
// one of the client's moved: the menu's button at the right of the top bar, last
{ id: 'menuButton', place: 'top-bar-right', order: 100 }
]
}
}
export const game = createGame(rules).view(view)Done: the clock and layout button are gone, a selection count shows top-right, the minimap has an amber frame, resources are plain text, and the menu button sits at the right of the top bar.
Add or hide a part in code
const remove = client.hud.widgets.add(part) // returns what takes it away
client.hud.hide('clock')Reference
| Field | What it does |
|---|---|
id | Your own, or one of the client's (HUD_WIDGETS) to change it. |
place | Where it goes (HUD_PLACE_NAMES, below). |
order | Position within the place. The client's parts are at 10, 20, 30… |
when | Show only while this returns true. |
component | A Solid component; for a client part, its own part comes as children. |
mount | Draw into a plain element; return what cleans up. |
| Places | |
|---|---|
| Top bar | top-bar-left, top-bar-center, top-bar-right, tray (under its right end) |
| Bottom bar | bottom-bar-center, bottom-bar-right |
| Over the map | top, top-left, top-right, left, right, center, bottom, bottom-left, bottom-right, side |
| Free | over-map (you position it), overlay (over everything) |
The client's parts: clock, status, resources, allies, saves, layoutButton, legend, stats, heroes, messages, chat, minimap, card, selection… The pieces themselves (Minimap, CommandCard, Resources…) are in @v12-engine/client/hud.
HudClient gives a part: ui (signals such as selection, resources, commands, heroes, objectives, clock; ui.watch(read, then) without Solid; ui.snapshot()), controller, camera, keys, settings, hud. Players move and scale parts in layout mode (Alt+Shift+L).
See The interface, and An interface of your own to replace the whole HUD.