definePlugin
Your plugin's entry file default-exports definePlugin({...}), which returns what you pass it, typed. Everything in it is optional.
import { definePlugin } from '@phantomclient/plugin';
export default definePlugin({
requires: ['game'],
setup(ctx) {
return () => {};
},
pages: {},
panels: {},
widgets: {},
commands: {},
commandViews: {},
});requires
What the game must have reached before setup runs: game, room, language, hud, interface, shops. Phantom waits for it, shows what your plugin is waiting for, then runs setup.
It's combined with your manifest's requires, so you can put it in either place. Each one needs the permission for the area it reads. See Waiting for the game.
setup(ctx)
Runs once when the plugin's logic starts. An each-game plugin runs it once for each game it's allowed on, with that game as ctx.phantom(). A single plugin runs it once. It can be async.
Whatever it returns runs when the plugin stops on that game: when the plugin is turned off, the game is closed, or the code reloads in development. Return something that undoes what setup started, such as listeners, timers and anything you drew in the game, or a drawing stays after the plugin stops.
With requires, it runs once the game has what you asked for rather than as soon as your code loads. Throw NotReady to have Phantom try again later, with a growing gap between tries. Anything else it throws is a crash, and setup isn't run again.
pages, panels, widgets, commandViews
Vue components, keyed by their contribution's id in the manifest. A panel sits beside a game and a page fills the main panel. A widget is a tile on the canvas, not bound to a game. A command view opens when a command declared with view returns props.
commands
Functions, keyed by command id:
const find: Command = async (input, phantom, ctx) => {
ctx.log('Arguments:', input.arguments);
return { message: 'Done', tone: 'success' };
};| Argument | What it is |
|---|---|
input.arguments | What the player filled in, keyed by the names in the command's arguments. |
phantom | The game the command was run on. |
ctx | The plugin's context. See ctx. |
A command can return { message, tone } to show a toast, { props } to open its view with those props, or nothing. tone is neutral, info, success, warning or danger.