api.events
EventsApi
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 document.sections) simply raises a fresh "document" event with
reason "replace", which every other listener sees in turn.
Members
on
on(event: "document", listener: (event: DocumentEvent) => void): Disposable;
api.events.on("document", (e) => {
if (e.reason === "open") api.ui.status(`Opened ${e.fileName ?? "a map"}`);
});
const selection = api.events.on("selection", () => api.log(`${api.selection.units().length} units selected`));
// Stop listening early; otherwise the listener goes when the plugin is turned off.
setTimeout(() => selection.dispose(), 60_000);Try iton
on(event: "commit", listener: (event: CommitEvent) => void): Disposable;
on
on(event: PluginEvent, listener: () => void): Disposable;
Types
Declarations only this group names.
CommitReasontype
type CommitReason = "edit" | "undo" | "redo" | "tables" | "whole" | "remote";
Why the map changed: an edit recorded in the history, an undo or redo of one, a dialog writing its tables (settings, triggers, strings), a change to the whole document (resize, tileset change, raw section edit), or other people's edits on a shared map.
CommitPartsinterface
interface CommitParts
Which parts of the map one commit touched.
terrain: boolean | |
|---|---|
isom: boolean | |
units: boolean | |
doodads: boolean | |
sprites: boolean | |
locations: boolean | |
fog: boolean | |
settings: boolean | |
triggers: boolean |
LanguagePreferencetype
type LanguagePreference = "auto" | Locale;
"auto" follows the browser (or the desktop app's system language).
HotkeyOverridestype
type HotkeyOverrides = Record<string, string[]>;
What Preferences.hotkeys holds: the commands the user changed, each with its whole list ([] = no keys).
RemasteredEffectsinterface
interface RemasteredEffects
The adjustable part of Remastered's moving water and lava (viewport/effectPass.ts).
How far the picture bends and how the ripple layers drift are the game's own figures;
how large the ripples lie on the map and how fast their pictures change are not in its
files, so these start from values set by eye and can be moved.
bend: number | How far water bends the ground under it, as a multiple of the game's amount. 0 leaves it still. |
|---|---|
glint: number | How much the ripples catch the light. 0 is none. |
large: number | The size of the large, slow ripples and of the fine ones over them, in map pixels a repeat. |
fine: number | |
rate: number | How many ripple pictures go by a second. |
heat: number | How far lava's heat reaches, in map pixels at its strongest. 0 leaves it still. |
Preferencesinterface
interface Preferences
language: LanguagePreference | The editor's own language: |
|---|---|
splash: boolean | Show the splash while the game data loads; off starts straight on the editor. |
confirmClose: boolean | Ask before closing or replacing a map with unsaved changes. |
multipleMaps: boolean | Open each map beside the ones already open, in its own tab, rather than in place of the open one. Off is StarEdit's one map at a time: Open and New replace the map, asking about unsaved changes first. Either way the blank map the editor starts on, untouched, is replaced by the first map opened rather than kept beside it. |
newMap: { tileset: TilesetId; width: number; height: number; version: NewMapVersion; } | What File ▸ New and the startup map start with. |
startup: { reopenLast: boolean; recents: number; } | Startup: |
save: { start: "asOpened" | "everything" | "smallest"; compression: "asOpened" | ArchiveCompression; backup: boolean; } | What the Save dialog starts from: the options the file was opened with
( |
recovery: { enabled: boolean; minutes: number; } | Recovery copies ( |
undoLevels: number | How many edits Undo keeps per map (SCMDraft keeps 200). |
view: { wheel: "scroll" | "zoom"; zoomToCursor: boolean; } | The mouse wheel over the map: scrolling, with Ctrl+wheel zooming (the default), or
zooming, with Shift+wheel scrolling sideways. |
placement: { owner: number; brushSize: number; locationTiles: number; } | What the palettes start on: the owner of placed units and sprites (0 = player 1), the brush size (1–7), and the size of a location the Locations palette's New makes, in tiles. |
animateWater: boolean | Initial View ▸ Animate Water / Animate Units. |
animateUnits: boolean | |
hdGraphics: boolean | Initial View ▸ Remastered Graphics: the 2x terrain and sprites, where the data set in use has them. |
remasteredEffects: RemasteredEffects | How Remastered's water and lava move — the part of the effect the game's files do not fix. |
animateWaterSpeed: number | How fast the two animations run, as a multiple of the game's own speed (1 = the
game's "Fastest"). One of |
animateUnitsSpeed: number | |
classicText: boolean | Preview the |
testMap: { launch: boolean; dir: string; } | Tools ▸ Test Map: whether to start the game after writing the map (desktop build), and
the game folder to use when the desktop build should not search ("" = search). The
browser's folder is a handle in IndexedDB ( |
updates: { checkOnStart: boolean; nightly: boolean; } | The desktop build's in-app updates ( |
plugins: { updates: PluginUpdateMode; } | What to do when an installed plugin has a newer release than the one running
( |
hotkeys: HotkeyOverrides | Preferences ▸ Hotkeys: the commands whose keys the user changed, by command id
( |
statusBar: StatusBarCells | Which cells the status bar shows (Preferences ▸ View). The message, the symmetry badge while a mode is on, and the plugins' items always show. |
StatusBarCellsinterface
interface StatusBarCells
See Preferences.statusBar, in the order the bar draws them.
tile: boolean | |
|---|---|
pixel: boolean | |
tileId: boolean | |
size: boolean | |
tileset: boolean | |
layer: boolean | |
zoom: boolean | |
revision: boolean |
PluginUpdateModetype
type PluginUpdateMode = "notify" | "manual" | "auto";
See Preferences.plugins.updates.
NewMapVersiontype
type NewMapVersion = Extract<MapVersion, "broodwar" | "remastered">;
The revisions a new map can start on; the two older ones are for opening old files, not making new ones.
PluginEventtype
type PluginEvent =
/** A map was opened, closed or replaced. */
"document"
/** A change was committed to the map in front; the listener gets a `CommitEvent` saying what and where. */
| "commit"
/** The editor's language changed (Preferences ▸ Display): re-label what is showing through `api.i18n.t`. */
| "language"
/** Any committed edit (every `document.edit`, stroke, undo and redo bumps it, terrain or not), and a fog edit. */
| "terrain" | "units" | "doodads" | "locations" | "settings" | "triggers" | "layer"
/** THG2 sprites — the same bump doodad edits make. */
| "sprites" | "selection"
/** The marked area or the clip on the clipboard changed. */
| "clipboard"
/** The viewport scrolled, zoomed, or a View menu tick moved. */
| "view"
/** A map tool or a map pick started or stopped. */
| "tool"
/** The map's unsaved-changes flag changed. */
| "modified"
/** A palette's pick changed: terrain brush, unit and owner, sprite, doodad, fog players. */
| "palette"
/** An editing option moved: symmetry, placement rules, doodad rules, location snap, the fog view player, clip parts and paste mode, locked layers, the grid look, Preferences. */
| "options"
/** The document's file changed: its name or handle after a Save, the save options, the archive extras, the recent list. */
| "file"
/** A plugin registered or removed a command — how a plugin learns that one it calls by id has arrived. */
| "commands"
/** A plugin provided or withdrew a service — `services.watch` is the usual way to hear this for one name. */
| "services"
/** A dialog opened or closed — `ui.openDialogs()` says which are open. */
| "dialogs"
/** The game data source changed: installed, switched to another data set, or a copy removed. `gameData.source()` says what it is now. */
| "gameData";
CommitEventinterface
interface CommitEvent
What the "commit" event hands its listeners: one change to the map in front, after it
is in the scenario. Every stroke, document.edit, undo and redo is one commit; so is a
dialog's OK or a document.update (reason "tables"), a resize, tileset change or raw
section edit ("whole"), and a batch of other people's edits on a shared map
("remote"). A dialog that writes both settings and triggers may send two. Opening,
closing and switching maps are not commits — the "document" event says those.
id: number | null |
|
|---|---|
reason: CommitReason | |
label: string | The history label — the words Edit ▸ Undo shows, in the editor's language; for an undo
or redo, the label of the entry taken back or put back. The update's label for a
|
area: Rect | null | The tiles the change fell on, far edges exclusive: every changed tile, and the tile
under each moved, placed or removed object's position (its picture reaches further —
widen the rect by the largest picture you draw). Null when the change has no place on
the map ( |
parts: CommitParts | Which parts changed. All of them for |
// Flash where each change landed, and log what kind of change it was.
api.events.on("commit", (e) => {
if (e.area) api.view.flash({ rect: e.area, kind: "attention" });
const parts = Object.entries(e.parts).filter(([, changed]) => changed).map(([part]) => part);
api.log(e.reason, e.label, parts);
});Try itDocumentChangeReasontype
type DocumentChangeReason =
/** File ▸ Open, drag-and-drop, `document.open`: a file the user chose. */
"open"
/** File ▸ New (the startup map included). */
| "new"
/** File ▸ Close: `document.isOpen()` is now false. */
| "close"
/** The open map parsed again from edited bytes — a `document.sections` write, by any plugin. */
| "replace"
/**
* Another open map came to the front — a tab clicked, `document.activate`, or the map
* in front closed with others still open. Nothing was read or written; the map that
* was in front is still open behind, as it was. `id` says which map is in front now.
*/
| "switch";
Why the document changed.
DocumentEventinterface
interface DocumentEvent
reason: DocumentChangeReason | |
|---|---|
fileName: string | null | |
id: number | null |
|