@scm-js/plugin-api 1.25.0 → 1.26.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 +59 -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,51 @@ 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
+ export interface BuildStepsApi {
2183
+ add(spec: BuildStepSpec): Disposable;
2184
+ /** The steps behind the file the open map came from or was last saved to; null for a plain map. */
2185
+ builtBy(): BuiltBy[] | null;
2186
+ }
2129
2187
  /**
2130
2188
  * The files stored in the map archive next to `staredit\scenario.chk`: custom sounds,
2131
2189
  * graphics, and anything a plugin wants to keep with the map. Names are archive paths
@@ -2347,6 +2405,7 @@ export interface DocumentApi {
2347
2405
  changeTileset(options: ChangeTilesetOptions): Promise<ChangeTilesetResult | null>;
2348
2406
  readonly extras: ExtrasApi;
2349
2407
  readonly sections: SectionsApi;
2408
+ readonly buildSteps: BuildStepsApi;
2350
2409
  }
2351
2410
  /** What a raw section edit reported: the parser's remarks about the file it produced. */
2352
2411
  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.26.0",
4
4
  "description": "Type declarations for the scmJS plugin API",
5
5
  "license": "MIT",
6
6
  "types": "index.d.ts",