Skip to content

Give your game its own interface ​

Make the game look like yours: change the colours, replace one part of the HUD, or draw every screen with your own code in any framework.

Quick start ​

ts
export const myView: GameView = {
	hud: {
		theme: { accent: '#7fe07a', radius: '6px' }, // a theme by name, values over the default, or a function of the base
		hide: ['clock', 'layoutButton']
	}
}

The whole HUD takes your accent colour and corners, and the clock and layout button are gone. The look is CSS variables (--vg-panel, --vg-accent, --vg-radius; the Tokens type), written onto the game's element only.

Build it yourself ​

1. Themes in code ​

ts
client.theme.set('moonlight')
client.theme.set({ accent: '#7fe07a' })
client.theme.reset()
registerTheme('orc', { accent: '#c0392b' }) // a theme every game on the page can name

Import @v12-engine/client/styles.css, or @v12-engine/client/tailwind.css with your own Tailwind (bg-panel, text-accent). --vg-motion: 0 stops animation.

2. Panels from the kit ​

ts
import { useOverlays } from '@v12-engine/client/kit'

const { toast, confirm, openMenu } = useOverlays()
toast('Gold mine collapsed', { tone: 'danger' })
if (await confirm({ title: 'Leave the game?', danger: true })) leave()
openMenu({ x, y }, [{ label: 'Rename', key: 'F2', run: rename }])

@v12-engine/client/kit has Button, Panel, Text, Meter, Dialog, Select, Slider, Tabs and more (Ark UI underneath, so keyboard and screen readers work). Tooltips: data-tip="Attack". Without Solid: kit.button(label, run, options), kit.panel(), kit.classes.button({ variant: 'primary' }), kit.render(element, Component, props).

3. Replace a part of the HUD ​

tsx
hud: {
	widgets: [
		{ id: 'minimap', mount: (element, client) => drawMyMinimap(element, client) }, // any HTML in its place
		{ id: 'card', component: (props) => <MyFrame title='Orders'>{props.children}</MyFrame> } // wrap the client's
	]
}

Part names are HUD_WIDGETS; places are HUD_PLACE_NAMES. launch({ hud: false }) drops the HUD; build your own from @v12-engine/client/hud (CommandCard, Minimap, SelectionPanel, Resources…).

4. Follow the client's state from any framework ​

ts
const selectionPart: HudWidgetDef = {
	id: 'my.selection',
	place: 'left',
	mount(element, client) {
		const draw = (items: { name: string }[]) => {
			element.style.display = items.length ? '' : 'none'
			element.textContent = items.length === 1 ? items[0].name : `${items.length} selected`
		}
		draw(client.ui.snapshot().selection)
		return client.ui.watch(() => client.ui.selection(), draw)
	}
}

Add it with GameView.hud.widgets or client.hud.widgets.add(part). In React, use useSyncExternalStore over client.ui.watch and client.ui.snapshot.

5. Replace a screen, keep its controller ​

ts
{
	id: 'saves',
	mount(element, client) {
		const saves = client.saves
		if (!saves) return () => {}
		const draw = (list: { id: string; name: string }[]) =>
			element.replaceChildren(...list.map((saved) => kit.button(saved.name, () => void saves.load(saved.id))))
		draw(saves.list())
		return watch(saves.list, draw)
	}
}

A controller knows what a screen shows and does; you replace only the view. Others: CampaignController, ReplaysController, LobbyController (createLobby), client.connection, client.endings. Their async methods report problems in words (said()), not by throwing.

Reference ​

Four ways for every piece ​

WayExample
Declaredoutcome: { victory: 'The mission is accomplished.', defeat: 'The mission has failed.' }
In codeA function, hook or API deciding the same while the game runs
A componentoutcome.component, given OutcomeProps (client, outcome, restart); wrap OutcomeScreen
An elementoutcome: { mount(element, client, outcome) { …; return () => … } }

Every piece and its four ways: The interface. Screens and controllers: The interface.

Floating things ​

A game's toasts and menus live in its element; an app's are over its menus (startApp(...).overlays); the editor's over the editor. useOverlays() finds the right ones.

In the example ​

  • apps/example/src/scenes/showcase.ts: the replays screen (replaysScene, replayScene).
  • The campaign starter's src/campaign/view/index.ts (outcome words, a HUD part in plain elements) and src/waves-panel.ts (an editor panel in an element).