In-game tools · interface
Command
Every change to the world, as an object that can be undone.
Explained in In-game tools.
interface Commandimport type { Command } from '@driftengine/tools';In depth
Built before any panel exists, and that order is the point. An undo stack added after the panels is an undo stack with holes in it, and the holes are found by users rather than by tests: one panel mutated directly, once, and now a particular sequence of actions cannot be taken back. Built first, every panel is written against it.
A panel is never handed the world. Panel.route returns a Command or nothing, so a panel
physically cannot change anything — the rule is enforced by the signature rather than by review.
Merging is what makes a drag usable. A gizmo emits a command per frame; sixty of them in the
undo stack means sixty presses of undo to take back one movement. merge lets a command absorb
the next of its kind, so a drag is one entry.
Properties
| Name | Type | Description |
|---|---|---|
labelreadonly | string | Shown in the undo menu and in the palette. |
Methods
apply
apply(): voidrevert
revert(): voidmergeoptional
merge?(next: Command): booleanAbsorb a following command of the same kind. Return true if it was absorbed.
| Parameter | Type | Description |
|---|---|---|
next | Command |
More
Called after the stack has already applied next, and an implementation must not apply it
again. Apply happens exactly once, by the stack, for every command — the alternative splits
that responsibility between the stack and each mergeable command, and the first implementation
of this got it wrong in exactly that way: the change ran twice and a drag moved twice as far
as the pointer.
What absorbing means is that the earlier command's revert now takes back both.