@scm-js/plugin-api 1.35.0 → 1.37.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 +46 -4
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1209,7 +1209,7 @@ export interface StackedLine {
1209
1209
  pieces: number;
1210
1210
  }
1211
1211
  /** Every built-in dialog, by the id `openDialogAtom` takes; `DialogHost` maps each to its component. */
1212
- export type DialogId = "newMap" | "openMap" | "saveAs" | "exportImage" | "mapProperties" | "resizeMap" | "mapRevision" | "playerSettings" | "forceSettings" | "playerColors" | "unitSettings" | "upgradeSettings" | "techSettings" | "stringEditor" | "soundEditor" | "switches" | "locationList" | "unitProperties" | "locationProperties" | "spriteProperties" | "triggerEditor" | "missionBriefing" | "cuwpEditor" | "replaceTerrain" | "autoStarts" | "testMap" | "symmetry" | "gridSettings" | "preferences" | "shortcuts" | "validateMap" | "statistics" | "importTriggers" | "exportTriggers" | "importStrings" | "exportStrings" | "find" | "about" | "confirmClose" | "plugins" | "confirmPlugin" | "pluginDialog" | "gameData" | "update";
1212
+ export type DialogId = "newMap" | "openMap" | "saveAs" | "exportImage" | "mapProperties" | "resizeMap" | "mapRevision" | "playerSettings" | "forceSettings" | "playerColors" | "unitSettings" | "upgradeSettings" | "techSettings" | "stringEditor" | "soundEditor" | "switches" | "locationList" | "unitProperties" | "locationProperties" | "spriteProperties" | "triggerEditor" | "missionBriefing" | "cuwpEditor" | "replaceTerrain" | "autoStarts" | "testMap" | "symmetry" | "gridSettings" | "preferences" | "shortcuts" | "validateMap" | "statistics" | "importTriggers" | "exportTriggers" | "importStrings" | "exportStrings" | "find" | "about" | "confirmClose" | "recovery" | "previousVersions" | "plugins" | "confirmPlugin" | "pluginDialog" | "gameData" | "update";
1213
1213
  export interface MapImageOptions {
1214
1214
  /** Output pixels per map tile. 32 matches the game's art 1:1; 1 is a minimap. */
1215
1215
  pixelsPerTile: number;
@@ -1992,11 +1992,25 @@ export interface Preferences {
1992
1992
  * What the Save dialog starts from: the options the file was opened with
1993
1993
  * (`"asOpened"`, the default), or one of its presets. `compression` is for a map with
1994
1994
  * no origin — new, or opened from a bare .chk — where there is nothing to follow;
1995
- * `"asOpened"` there means StarEdit's PKWARE.
1995
+ * `"asOpened"` there means StarEdit's PKWARE. `backup` keeps the file a save writes
1996
+ * over: `<name>.bak` beside it in the desktop app, the browser's storage otherwise
1997
+ * (`services/previousVersions.ts`).
1996
1998
  */
1997
1999
  save: {
1998
2000
  start: "asOpened" | "everything" | "smallest";
1999
2001
  compression: "asOpened" | ArchiveCompression;
2002
+ backup: boolean;
2003
+ };
2004
+ /**
2005
+ * Recovery copies (`hooks/useRecovery.ts`): while a map has unsaved changes, a copy of
2006
+ * it is kept in the browser's storage every `minutes` and when the editor goes to the
2007
+ * background, and dropped when the map is saved or closed. What a session that ended
2008
+ * without saving left behind is offered back at the next start. Off stops the copies
2009
+ * and drops this session's; copies left by earlier sessions are still offered.
2010
+ */
2011
+ recovery: {
2012
+ enabled: boolean;
2013
+ minutes: number;
2000
2014
  };
2001
2015
  /** How many edits Undo keeps per map (SCMDraft keeps 200). */
2002
2016
  undoLevels: number;
@@ -2249,6 +2263,25 @@ export interface PluginApi {
2249
2263
  readonly storage: StorageApi;
2250
2264
  /** `console.log` with the plugin's name in front. */
2251
2265
  log(...args: unknown[]): void;
2266
+ /**
2267
+ * A child of this API with a lifetime of its own. Everything registered through
2268
+ * `scope.api` — menu items, hotkeys, event listeners, panels, dialogs, overlays, map
2269
+ * tools, commands, services, trigger claims — goes when `scope.dispose()` is called, and
2270
+ * with the plugin if it is turned off first. After the dispose, the child's document
2271
+ * writes are refused as a turned-off plugin's are, so a timer or a fetch that outlives
2272
+ * the scope cannot change the map. Scopes nest.
2273
+ *
2274
+ * It is for a plugin that runs other code for a while and then takes it all back: the
2275
+ * API Playground runs each snippet in one. The child speaks as the same plugin — same
2276
+ * id, storage and log name.
2277
+ */
2278
+ scope(): PluginScope;
2279
+ }
2280
+ /** A child API that can be taken back as a whole (`PluginApi.scope`). */
2281
+ export interface PluginScope extends Disposable {
2282
+ readonly api: PluginApi;
2283
+ /** True once `dispose` has run, or once the plugin that made the scope was turned off. */
2284
+ readonly disposed: boolean;
2252
2285
  }
2253
2286
  export interface DocumentInfo {
2254
2287
  name: string;
@@ -2473,8 +2506,9 @@ export interface DocumentApi {
2473
2506
  *
2474
2507
  * @example
2475
2508
  * // One undo entry called "Fill", however many operations it takes.
2509
+ * const ground = api.terrain.types()[1].id; // the tileset's second flat terrain
2476
2510
  * const result = api.document.edit("Fill", (tx) => {
2477
- * tx.stampTerrain({ x0: 0, y0: 0, x1: 8, y1: 8 }, terrainId);
2511
+ * tx.stampTerrain({ x0: 0, y0: 0, x1: 8, y1: 8 }, ground);
2478
2512
  * tx.placeUnit(api.consts.unit.startLocation, 0, 4 * api.consts.tile, 4 * api.consts.tile);
2479
2513
  * });
2480
2514
  * api.ui.status(`${result.tiles} tiles, ${result.units} units`);
@@ -3298,7 +3332,8 @@ export interface ViewApi {
3298
3332
  * clean up.
3299
3333
  *
3300
3334
  * @example
3301
- * const r = api.document.edit("Fill", (tx) => tx.fillFlat(rect, terrain));
3335
+ * const rect = { x0: 4, y0: 4, x1: 12, y1: 12 };
3336
+ * const r = api.document.edit("Fill", (tx) => tx.fillFlat(rect, api.terrain.types()[1].id));
3302
3337
  * if (r.changed) api.view.flash({ rect });
3303
3338
  */
3304
3339
  flash(target: FlashTarget): void;
@@ -3558,6 +3593,13 @@ export interface GameDataApi {
3558
3593
  select(id: string): Promise<GameDataSource>;
3559
3594
  /** Remove a data set's copy (never the game's bundled files). True when there was one. */
3560
3595
  remove(id: string): Promise<boolean>;
3596
+ /**
3597
+ * One file of the data set in use, by its path in the extracted copy: the archive path in
3598
+ * lower case with forward slashes (`arr/units.dat`, `tileset/jungle.cv5`,
3599
+ * `unit/zerg/drone.grp`). `tileset/manifest.json` and `unit/manifest.json` list what was
3600
+ * extracted. Null when the copy has no such file, or there is no game data.
3601
+ */
3602
+ read(path: string): Promise<Uint8Array | null>;
3561
3603
  }
3562
3604
  /**
3563
3605
  * The constants a plugin needs to *write* a record rather than read one: the bit masks in
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scm-js/plugin-api",
3
- "version": "1.35.0",
3
+ "version": "1.37.0",
4
4
  "description": "Type declarations for the scmJS plugin API",
5
5
  "license": "MIT",
6
6
  "types": "index.d.ts",