API reference
Everything a plugin can see and do, as the editor declares it. Plugin API version 1; generated from src/plugins/api.ts, the same declarations @scm-js/plugin-api publishes.
A plugin is one activate(api) function. Everything below hangs off that argument.
import type { PluginApi } from "@scm-js/plugin-api";
export default function activate(api: PluginApi) {
api.menu.add("Tools", { label: "Say hello", run: () => api.ui.toast({ title: "Hello" }) });
}
Nothing here is written by hand. A member with no description has no doc comment in api.ts; the fix belongs there, not on this page.
An example marked Try it runs as it is written: the link opens it in the editor's API Playground, and nothing runs until you press Run.
Groups
api.document |
The open map: what it says, and the three ways of writing to it — |
|---|---|
api.settings |
The settings dialogs' tables, read-only; |
api.triggers |
Reading triggers, and the pure helpers that make them presentable. Writing goes
through |
api.terrain |
Reading the terrain: the tileset's paintable types, the ISOM lattice, flood regions,
blend candidates and the symmetry mode. Painting goes through |
api.tileset |
The loaded tileset graphics: whether they are there, and the decoded files behind them. |
api.selection |
What is selected on each object layer, the marked area, the active layer and the locked ones. |
api.clipboard |
Cut / Copy / Paste: the clip, its parts, and pasting — what the clipboard layer does. |
api.exchange |
The file formats behind File ▸ Import / Export: |
api.palette |
The palettes' current picks — the terrain brush, the unit, sprite and doodad, the fog mode — and the placement options a plugin that places things should honour. |
api.names |
The names behind the numbers a map stores, so a plugin that shows raw values need not
carry the game's tables itself. The per-map ones ( |
api.text |
StarCraft's |
api.query |
Reading the open map: what is under a point, what lies in a rectangle, and the editor's own analyses — Check Map's issues, Tools ▸ Statistics, the Ctrl+F search and the string usage map the String Editor is built on. Everything here is a read: nothing changes the map, and nothing throws without one (an empty list, or null). |
api.data |
The game's own tables, as the editor decoded them: Everything is null until the tables are loaded ( |
api.gameData |
Which set of game files the editor draws from — the game's own or a mod's — and installing, switching and removing sets. |
api.consts |
Bit masks, special unit ids and the pixels-per-tile every record is written in. |
api.graphics |
The pictures the viewport draws, for a plugin's own lists and previews: the same cached canvases, so asking for one costs nothing after the first time. Everything is null when the graphics it needs were never extracted — a plugin shows a name instead. |
api.view |
The map view: where the viewport is looking, how far in, and what it draws over the terrain. A plugin that finds something needs this to show the user where it is. |
api.ui |
Everything a plugin puts on the screen: the status line, toasts, dialogs, floating
panels, |
api.menu |
Items in the editor's menu bar. A path whose last segment names no submenu makes one. |
api.contextMenu |
Items in the right-click menus of the map and the terrain palette. |
api.hotkeys |
Key combinations, tried before the editor's own and never while a text field has focus. |
api.commands |
Named things a plugin can do, so a menu item, a hotkey, a context entry and another
plugin all reach the same one. |
api.services |
Live objects one plugin holds out for others to use, found by name and watched for arriving. |
api.i18n |
The plugin's words in the editor's language: its own catalogues, and a |
api.events |
Listeners are notifications: they run after the change, in the order the plugins were
activated, and cannot veto or reorder one another. A listener that rewrites the map in
response (through |
api.sync |
Editing the map in front together with other editors: every change to it is handed out as an op for the plugin to carry to them, and theirs come back in, in the order a server puts them. The scmjs.dev plugin's shared maps are built on it; the transport, the server and who may join are the plugin's. |
api.storage |
A small key-value store of the plugin's own, kept in the browser's local storage under the plugin's id and listed with everything else in Preferences ▸ Browser storage. |
On the api object itself
api.apiVersion— numberapi.plugin— PluginInfoapi.log— console.log with the plugin's name in front.api.scope— A child of this API with a lifetime of its own. Everything registered through scope.api — menu items, hotkeys, event listeners, panels, dialogs, overlays, map tools, commands, services, trigger claims — goes when scope.dispose() is called, and with the plugin if it is turned off first. After the dispose, the child's document writes are refused as a turned-off plugin's are, so a timer or a fetch that outlives the scope cannot change the map. Scopes nest. It is for a plugin that runs other code for a while and then takes it all back: the API Playground runs each snippet in one. The child speaks as the same plugin — same id, storage and log name.api.plugin— the manifest of the plugin thisapibelongs to (PluginInfo).
Plugins to read
Every plugin the editor ships is a repository of its own, compiled against these declarations; Plugins to read says what each one demonstrates.
- Hello Worldthe smallest complete plugin: one menu item and one dialog, to copy from
- Paintmap tools, a floating panel, and painting with the active layer's brush
- Walkabilitya read-only overlay drawn over the map
- Section Explorerraw section bytes, re-parsed into the open map
- Repairchecking a file on open and repairing it
- Melee Wizardplacing units with the editor's own placement checks
- Terrain from Imagean image turned into terrain, one transaction
- scmscx.comopening a map fetched from elsewhere
- TrigScriptgenerating a run of triggers and claiming it
- TrigEditthe text trigger format, and a dialog that offers a slot to other plugins
- Magentaa trigger editor that needs another plugin's service
- eudpliba library plugin: one versioned service for others to build with
- Stamp Libraryclips kept in storage, drawn as thumbnails and pasted as one edit
- Timelapsefollowing every commit, one frame per change
- Aftermatha replay drawn over its map with an overlay
- scmjs.devan account, shared maps, docked panels and dialog slots