The view
phantom.aj.viewThe screen and sound
What of the game is drawn: HUD parts, clean screenshots, zoom kept.
Scripts and plugins
A script has all of it, as phantom.aj.view, and so does a plugin, from ctx.phantom(): the SDK runs in the plugin's own frame. Each call is marked with what it needs: game:read for what the area knows and hears, which "game": "read" in the manifest grants, and game:act for doing things in it as the player, which needs "game": "act" (see Permissions).
Overview
| Member | What it does | Plugins |
|---|---|---|
clean() | Clears the screen for a picture of the room: the interface, the player's own avatar and its name tag, unless one is set false. | game:act |
current() | What is shown now and the room's zoom, read from the client. | game:read |
hide() | Hides one part of the game or several, until the handle it gives back is called, whatever the client does meanwhile. | game:act |
keepZoom() | Zooms the room and keeps it there, until the handle puts the zoom from before back. | game:act |
onChange() | Hears what is shown, or the zoom, change, whoever changed it: read in the game every everyFrames frames (6 by default) and told only on a change, with the state before. | game:read |
Methods
clean
clean(options?: CleanOptions) => Promise<() => Promise<void>>Clears the screen for a picture of the room: the interface, the player's own avatar and its name tag, unless one is set false. The handle puts back exactly what this hid. Other players are phantom.aj.room.players's; the zoom is left alone.
Parameters
| Name | Type | |
|---|---|---|
options optional | CleanOptions |
Returns
Promise<() => Promise<void>>
Types
current
current() => Promise<ViewState>What is shown now and the room's zoom, read from the client.
Returns
Promise<ViewState>
Types
hide
hide(parts: ViewPart | readonly ViewPart[], options?: ActOptions) => Promise<() => Promise<void>>Hides one part of the game or several, until the handle it gives back is called, whatever the client does meanwhile. Each part is held by path, so it stays hidden from room to room, and one asked for before the client has made it is hidden as soon as it does. Hiding something already hidden is harmless: each handle gives back only its own.
Parameters
| Name | Type | |
|---|---|---|
parts | ViewPart | readonly ViewPart[] | |
options optional | ActOptions |
Returns
Promise<() => Promise<void>>
Types
Example
keepZoom
keepZoom(percent: number, options?: ActOptions) => Promise<() => Promise<void>>Zooms the room and keeps it there, until the handle puts the zoom from before back. The client asks for a zoom of its own whenever the window is resized (MainFrame.handleResize); this has the game ask for this one again (updateRoomZoom) on any frame _zoom is not it. Kept within ZOOM_LIMITS; a room smaller than the zoom stops short of it, as the client's own does. A one-off zoom is phantom.aj.room.camera.zoom.
Parameters
| Name | Type | |
|---|---|---|
percent | number | |
options optional | ActOptions |
Returns
Promise<() => Promise<void>>
Types
Example
Events
onChange
onChange(listener: (state: ViewState, previous: ViewState | null) => void, options?: { everyFrames?: number | undefined; }) => () => voidHears what is shown, or the zoom, change, whoever changed it: read in the game every everyFrames frames (6 by default) and told only on a change, with the state before.
Parameters
| Name | Type | |
|---|---|---|
listener | (state: ViewState, previous: ViewState | null) => void | |
options optional | { everyFrames?: number | undefined; } |
Returns
() => void. Call it to stop listening.
Types
Types
The types the calls above take and give, with every field. Import any of them in a plugin from @phantomclient/plugin/sdk, or use them as they are in a script.
ViewState
How the game is drawn now, read from the client.
| Field | Type | |
|---|---|---|
interface | boolean | The game's interface (layerManager.gui) is shown. False before a room is up. |
hud | boolean | The HUD is shown. |
ownAvatar | boolean | The player's own avatar is shown. False before it is made. |
ownNameTag | boolean | The name tag over it is shown. |
zoom | number | null | The scale the room is drawn at, in per cent (layerManager.bkg.scaleX), or null with no room. phantom.aj.room.camera moves and zooms the room. |
ViewPart
What the view hides by name.
interface: the game's whole interface (layerManager.gui): the HUD, windows, popups and minigames. The game goes on underneath it.hud: the HUD alone (GuiManager.mainHud).ownAvatar: the player's own avatar, its name tag and pet with it. Chat balloons stay.ownNameTag: the name tag over the player's own avatar.- a layer's name: one of
LayerManager's layers, such asroom_fg(what is drawn in front of the avatars) orroom_chat(the chat balloons).
type ViewPart = 'interface' | 'hud' | 'ownAvatar' | 'ownNameTag' | ViewLayerActOptions
How long something that acts may take, and what may end it first.
| Field | Type | |
|---|---|---|
timeoutMs optional | number | undefined | 10 seconds by default. |
signal optional | AbortSignal | undefined |
CleanOptions
What clean takes off the screen: all three unless one is set false.
type CleanOptions = ActOptions & {
interface?: boolean;
ownAvatar?: boolean;
ownNameTag?: boolean;
}