definePlugin
Call Signature
Section titled “Call Signature”definePlugin<
Options,Systems,Inputs,Actions,Layers,Commands,Contexts,Saves>(build):PluginFactory<[WithSaves<Options,Saves>],PluginMade<Systems,Inputs,Actions,Layers,Commands,Contexts,Saves>>
Makes a plugin’s factory from build, which returns the plugin as its
author writes it for its options: the call a game lists, matches(),
which makes one plugin for each distinct options the plugin records,
so a list written again on each render, and a kit that lists the plugin
with the same options as the game, name one plugin. The factory carries
the plugin’s handles, read from a call with no options, so they never
depend on its options: matches.systems.advance for an anchor,
matches.commands.start for what a page sends, and the plugin’s name, so
another plugin writes requires: [matches]. The engine’s plugins and a
game’s own are written the same way.
The parameter’s annotation types the options, and the handles are
inferred from what build returns: resources.systems.regenerate for
a listed defineSystem, abilities.commands.cast for a declared
command. Two calls make one plugin when their recorded options are the
same JSON and each function and handle they were given is the same
object, such as a Team from defineTeam: a handle is compared by
identity, so two worlds’ teams of one key are two plugins. So a build
that takes options records them in options, which the type requires,
and a call that passes options to a plugin that records none throws.
A record may leave out each setting at its default. A plugin
whose options are required, as teams()’s are, names the options its
handles are read from in handlesFrom, and a game’s call must pass its
own.
Each call checks what one plugin can know: its name, that no two systems share one, that each sibling anchor names a system of the list, that each replacement names another plugin’s system, that each answered command is its own or another plugin’s by handle, and that it does not require itself. What needs the whole list, a missing requirement, an anchor’s plugin, a clash between plugins, the composer checks as the game’s module loads.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
Options |
- |
Systems extends readonly SystemDefinition<"input" | "rules" | "motion" | "physics", boolean, RunContext, string>[] |
readonly [] |
Inputs extends Readonly<Record<string, ButtonInputDeclaration | AxisInputDeclaration | VectorInputDeclaration | AngleInputDeclaration>> |
Readonly<Record<never, never>> |
Actions extends Readonly<Record<string, PageActionDeclaration>> |
Readonly<Record<never, never>> |
Layers extends string |
never |
Commands extends Readonly<Record<string, CommandDeclaration<Readonly<Record<string, CommandField>>, string, Readonly<Record<string, ReturnField>> | undefined, boolean, boolean, boolean, boolean>>> |
Readonly<Record<never, never>> |
Contexts extends Readonly<Record<string, InputContextDeclaration>> |
Readonly<Record<never, never>> |
Saves extends Readonly<Record<string, SaveDeclaration<SaveSchema, SaveScopes, SaveRequires>>> |
Record<never, never> |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
build |
(options?) => PluginConfig<Systems, Inputs, Actions, Layers, Commands, Contexts, Saves> & RecordedOptions<NoInfer<Options>> |
Returns
Section titled “Returns”PluginFactory<[WithSaves<Options, Saves>], PluginMade<Systems, Inputs, Actions, Layers, Commands, Contexts, Saves>>
Call Signature
Section titled “Call Signature”definePlugin<
Options,Systems,Inputs,Actions,Layers,Commands,Contexts,Saves>(build,handles):PluginFactory<[WithSaves<Options,Saves>],PluginMade<Systems,Inputs,Actions,Layers,Commands,Contexts,Saves>>
Makes a plugin’s factory from build, which returns the plugin as its
author writes it for its options: the call a game lists, matches(),
which makes one plugin for each distinct options the plugin records,
so a list written again on each render, and a kit that lists the plugin
with the same options as the game, name one plugin. The factory carries
the plugin’s handles, read from a call with no options, so they never
depend on its options: matches.systems.advance for an anchor,
matches.commands.start for what a page sends, and the plugin’s name, so
another plugin writes requires: [matches]. The engine’s plugins and a
game’s own are written the same way.
The parameter’s annotation types the options, and the handles are
inferred from what build returns: resources.systems.regenerate for
a listed defineSystem, abilities.commands.cast for a declared
command. Two calls make one plugin when their recorded options are the
same JSON and each function and handle they were given is the same
object, such as a Team from defineTeam: a handle is compared by
identity, so two worlds’ teams of one key are two plugins. So a build
that takes options records them in options, which the type requires,
and a call that passes options to a plugin that records none throws.
A record may leave out each setting at its default. A plugin
whose options are required, as teams()’s are, names the options its
handles are read from in handlesFrom, and a game’s call must pass its
own.
Each call checks what one plugin can know: its name, that no two systems share one, that each sibling anchor names a system of the list, that each replacement names another plugin’s system, that each answered command is its own or another plugin’s by handle, and that it does not require itself. What needs the whole list, a missing requirement, an anchor’s plugin, a clash between plugins, the composer checks as the game’s module loads.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
Options |
- |
Systems extends readonly SystemDefinition<"input" | "rules" | "motion" | "physics", boolean, RunContext, string>[] |
readonly [] |
Inputs extends Readonly<Record<string, ButtonInputDeclaration | AxisInputDeclaration | VectorInputDeclaration | AngleInputDeclaration>> |
Readonly<Record<never, never>> |
Actions extends Readonly<Record<string, PageActionDeclaration>> |
Readonly<Record<never, never>> |
Layers extends string |
never |
Commands extends Readonly<Record<string, CommandDeclaration<Readonly<Record<string, CommandField>>, string, Readonly<Record<string, ReturnField>> | undefined, boolean, boolean, boolean, boolean>>> |
Readonly<Record<never, never>> |
Contexts extends Readonly<Record<string, InputContextDeclaration>> |
Readonly<Record<never, never>> |
Saves extends Readonly<Record<string, SaveDeclaration<SaveSchema, SaveScopes, SaveRequires>>> |
Record<never, never> |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
build |
(options) => PluginConfig<Systems, Inputs, Actions, Layers, Commands, Contexts, Saves> & RecordedOptions<NoInfer<Options>> |
handles |
PluginFactoryOptions<NoInfer<Options>> |
Returns
Section titled “Returns”PluginFactory<[WithSaves<Options, Saves>], PluginMade<Systems, Inputs, Actions, Layers, Commands, Contexts, Saves>>