@scm-js/plugin-api 1.25.0 → 1.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.d.ts +85 -0
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1679,6 +1679,13 @@ export interface SaveOptions {
1679
1679
  /** Drop bytes after the last section header the file could parse. */
1680
1680
  dropTrailing: boolean;
1681
1681
  }
1682
+ /** A step as the manifest remembers it. */
1683
+ export interface BuiltBy {
1684
+ /** `plugin id/step id`. */
1685
+ id: string;
1686
+ /** The step's label when it ran, for a notice about a step that is no longer there. */
1687
+ label: string;
1688
+ }
1682
1689
  export interface ChangeTilesetResult {
1683
1690
  from: number;
1684
1691
  to: number;
@@ -2113,6 +2120,12 @@ export interface ExportOptions {
2113
2120
  * an opened one), so the bytes are what Save would write unless you say otherwise.
2114
2121
  */
2115
2122
  saveOptions?: Partial<Omit<SaveOptions, "format">>;
2123
+ /**
2124
+ * False gives the map without its build steps (`document.buildSteps`): the scenario as the
2125
+ * editor holds it. By default the file is the one Save would write, steps run — except
2126
+ * from inside a step, where it is always the map without them.
2127
+ */
2128
+ built?: boolean;
2116
2129
  }
2117
2130
  /** `document.save` / `saveAs`. */
2118
2131
  export interface SaveDocumentOptions {
@@ -2126,6 +2139,77 @@ export interface ChangeTilesetOptions {
2126
2139
  /** Keep the tile numbers and change only ERA (what SCMDraft's switch does). */
2127
2140
  keepTiles?: boolean;
2128
2141
  }
2142
+ /** Why the map is leaving the editor: File ▸ Save (and its copies), Tools ▸ Test Map, or `document.export`. */
2143
+ export type BuildPurpose = "save" | "test" | "export";
2144
+ export interface BuildStepInput {
2145
+ /**
2146
+ * The map as Save would write it without the steps, or the step before this one's
2147
+ * output: an `.scx` / `.scm` archive, the archive extras inside.
2148
+ */
2149
+ map: Uint8Array;
2150
+ fileName: string;
2151
+ purpose: BuildPurpose;
2152
+ /** Aborted when the user chooses to save without waiting. */
2153
+ signal: AbortSignal;
2154
+ }
2155
+ /**
2156
+ * A compiler that stands between the map and the disk. The editor keeps showing the map
2157
+ * the user edits; whenever the map leaves — Save, Test Map, `export` — every step that
2158
+ * `applies` is run over the bytes, in the order the plugins were activated, and what the
2159
+ * last one returns is what is written. The editor stores the map as it was *before* the
2160
+ * steps inside the same file and gives that back on open, so a step's output (generated
2161
+ * triggers, a payload in the string table) never shows up in the editor.
2162
+ *
2163
+ * A step that throws, or that the user stops waiting for, does not stop a save: the map is
2164
+ * written without the steps and a notice says why. Test Map stops instead, since a map
2165
+ * without its built part is not the one to test. A bare `.chk` is never built.
2166
+ */
2167
+ export interface BuildStepSpec {
2168
+ /** Unique within the plugin; the file remembers `plugin id/id`. */
2169
+ id: string;
2170
+ /** What the notice says is running: "eudplib". */
2171
+ label: string;
2172
+ /** Whether the open map has anything for this step. Cheap and synchronous; false leaves Save exactly as it was. */
2173
+ applies(): boolean;
2174
+ /**
2175
+ * Build. Return an archive (or a bare scenario) — the editor takes the scenario and any
2176
+ * *new* members from it and lays the final file out with the user's save options; the
2177
+ * map's own members are written as they were. Throw an `Error` whose message says what
2178
+ * is wrong in the user's terms.
2179
+ */
2180
+ run(input: BuildStepInput): Promise<Uint8Array>;
2181
+ }
2182
+ /**
2183
+ * Work a plugin does on the *document* before the map's bytes are produced for Save, Test
2184
+ * Map or `export` — the place to bring generated content up to date, such as writing a
2185
+ * script's triggers into the trigger list with `document.update`. It runs before any
2186
+ * build step is asked whether it applies, so a step can rely on what it did.
2187
+ */
2188
+ export interface BeforeBuildSpec {
2189
+ /** Unique within the plugin. */
2190
+ id: string;
2191
+ /** What a failure notice names: "TrigScript". */
2192
+ label: string;
2193
+ /** Whether there is anything to do for the open map. Cheap and synchronous; every save asks. Always, when omitted. */
2194
+ applies?(): boolean;
2195
+ /**
2196
+ * May be asynchronous and may write to the document. A throw does not stop the save:
2197
+ * the map is written as it stands and a notice shows the error's message, so word it
2198
+ * for the user. Inside it `document.export()` answers the map as it stands, without
2199
+ * running anything.
2200
+ */
2201
+ run(ctx: {
2202
+ purpose: BuildPurpose;
2203
+ signal: AbortSignal;
2204
+ }): void | Promise<void>;
2205
+ }
2206
+ export interface BuildStepsApi {
2207
+ add(spec: BuildStepSpec): Disposable;
2208
+ /** Run `spec.run` before the map's bytes are produced, every time the map leaves the editor. */
2209
+ before(spec: BeforeBuildSpec): Disposable;
2210
+ /** The steps behind the file the open map came from or was last saved to; null for a plain map. */
2211
+ builtBy(): BuiltBy[] | null;
2212
+ }
2129
2213
  /**
2130
2214
  * The files stored in the map archive next to `staredit\scenario.chk`: custom sounds,
2131
2215
  * graphics, and anything a plugin wants to keep with the map. Names are archive paths
@@ -2347,6 +2431,7 @@ export interface DocumentApi {
2347
2431
  changeTileset(options: ChangeTilesetOptions): Promise<ChangeTilesetResult | null>;
2348
2432
  readonly extras: ExtrasApi;
2349
2433
  readonly sections: SectionsApi;
2434
+ readonly buildSteps: BuildStepsApi;
2350
2435
  }
2351
2436
  /** What a raw section edit reported: the parser's remarks about the file it produced. */
2352
2437
  export interface RawEditResult {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scm-js/plugin-api",
3
- "version": "1.25.0",
3
+ "version": "1.27.0",
4
4
  "description": "Type declarations for the scmJS plugin API",
5
5
  "license": "MIT",
6
6
  "types": "index.d.ts",