UiScreenDescription
Since 0.6
A whole screen, as ctx.ui.screen takes it.
Signature
export interface UiScreenDescription {
/** The contract version. Always 1. */
format: 1
/** The screen's name, as `push`, `replace` and `GET /ui/screens` use it. */
screen: string
root: UiNode
}
Import: import type { UiScreenDescription } from "@argus/api"
Members
| Member | Signature | Description |
|---|---|---|
format | format: 1 | The contract version. Always 1. |
screen | screen: string | The screen's name, as push, replace and GET /ui/screens use it. |
root | root: UiNode |
Example
The tested fixture fixtures/recipes/hud-score-timer/scenes/behaviors/hud-score-timer.ts.
import type { Behavior } from "@argus/api"
/**
* A score and a countdown on the stock HUD.
*
* Space scores a point, the clock runs down from `seconds`, and at zero the round emits
* `time-up` once and stops.
*
* How a number reads is the scene's business, not this file's: `meta.hud.timer` says
* `format: "time"` so 29.5 draws as `0:30`, and `meta.hud.score` adds the `Score ` prefix.
* Without those entries a number draws raw, as `timer: 29.5`. Writing both every tick is
* fine — an unchanged HUD value costs nothing.
*/
interface State {
score: number
/** Seconds left in the round. */
left: number
over: boolean
}
interface Props {
/** Length of the round in seconds. Default 30. */
seconds?: number
}
export default {
init(ctx) {
if (typeof ctx.state.score !== "number") ctx.state.score = 0
if (typeof ctx.state.left !== "number") ctx.state.left = ctx.props.seconds ?? 30
if (typeof ctx.state.over !== "boolean") ctx.state.over = false
},
update(ctx, dt) {
if (!ctx.state.over) {
if (ctx.input !== null && ctx.input.pressed("score")) ctx.state.score += 1
ctx.state.left = Math.max(0, ctx.state.left - dt)
if (ctx.state.left === 0) {
ctx.state.over = true
ctx.events.emit("time-up", { score: ctx.state.score })
}
}
ctx.hud.score(ctx.state.score)
ctx.hud.timer(ctx.state.left)
},
} satisfies Behavior<State, Props>