Machine
A machine states made: its trait, and the ways to move and read it.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
Context extends MachineContext |
MachineContext |
Event extends string |
string |
Value |
StateValue |
Tags |
Record<string, StateTag> |
Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
description? |
string |
What it is for, from its config. |
is |
Tags |
Each state’s tag, which each entity whose record is in the state holds, the world for the world’s machine: world.query(Guard.is.answer), and Guard.is.patrol.watch for a state inside another. They follow the record: a send, a wait and a when move them as they move it, a spawn, the stream and a restore write them with it, and a plain set of state moves them at the start of the next step, before any system reads them. |
name |
string |
- |
ownerOnly |
boolean |
Whether a room streams its trait to its character’s player alone. |
stateNames |
string[] |
Every state it has, by the path matches takes: "patrol.watch". |
tagNames |
ReadonlyMap<string, TagTrait> |
Each tag by the name the dump writes it under: the machine’s name and the state’s path, "guard.patrol.watch". |
trait |
Trait<SchemaFor<MachineRecord<Context, Value>>> |
Its snapshot: add it to the world for a game’s phases, or spawn it on an entity. Siege.trait({ waves: 3 }) sets its context. |
Methods
Section titled “Methods”advance()
Section titled “advance()”advance(
world,deltaSeconds):void
Counts the waits on world for one step, then moves each machine
whose state’s when holds. The engine’s step runs it for every
machine, in the order they were declared.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
world |
World |
deltaSeconds |
number |
Returns
Section titled “Returns”void
read()
Section titled “read()”read(
target):MachineRead<Context,Value>
The machine on target as it stands.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
target |
World | Entity |
Returns
Section titled “Returns”MachineRead<Context, Value>
send()
Section titled “send()”send(
target,event):boolean
Sends event to the machine on target, the world or an entity.
Returns whether a state took it; one no state it is in names leaves
it as it was. Send after a walk over the machine’s trait, or from
readEach: updateEach writes its copy of the record back over
the send.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
target |
World | Entity |
event |
MachineEvent<Event> |
Returns
Section titled “Returns”boolean