@scm-js/plugin-api 1.34.0 → 1.36.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.
- package/index.d.ts +29 -2
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -2249,6 +2249,25 @@ export interface PluginApi {
|
|
|
2249
2249
|
readonly storage: StorageApi;
|
|
2250
2250
|
/** `console.log` with the plugin's name in front. */
|
|
2251
2251
|
log(...args: unknown[]): void;
|
|
2252
|
+
/**
|
|
2253
|
+
* A child of this API with a lifetime of its own. Everything registered through
|
|
2254
|
+
* `scope.api` — menu items, hotkeys, event listeners, panels, dialogs, overlays, map
|
|
2255
|
+
* tools, commands, services, trigger claims — goes when `scope.dispose()` is called, and
|
|
2256
|
+
* with the plugin if it is turned off first. After the dispose, the child's document
|
|
2257
|
+
* writes are refused as a turned-off plugin's are, so a timer or a fetch that outlives
|
|
2258
|
+
* the scope cannot change the map. Scopes nest.
|
|
2259
|
+
*
|
|
2260
|
+
* It is for a plugin that runs other code for a while and then takes it all back: the
|
|
2261
|
+
* API Playground runs each snippet in one. The child speaks as the same plugin — same
|
|
2262
|
+
* id, storage and log name.
|
|
2263
|
+
*/
|
|
2264
|
+
scope(): PluginScope;
|
|
2265
|
+
}
|
|
2266
|
+
/** A child API that can be taken back as a whole (`PluginApi.scope`). */
|
|
2267
|
+
export interface PluginScope extends Disposable {
|
|
2268
|
+
readonly api: PluginApi;
|
|
2269
|
+
/** True once `dispose` has run, or once the plugin that made the scope was turned off. */
|
|
2270
|
+
readonly disposed: boolean;
|
|
2252
2271
|
}
|
|
2253
2272
|
export interface DocumentInfo {
|
|
2254
2273
|
name: string;
|
|
@@ -2473,8 +2492,9 @@ export interface DocumentApi {
|
|
|
2473
2492
|
*
|
|
2474
2493
|
* @example
|
|
2475
2494
|
* // One undo entry called "Fill", however many operations it takes.
|
|
2495
|
+
* const ground = api.terrain.types()[1].id; // the tileset's second flat terrain
|
|
2476
2496
|
* const result = api.document.edit("Fill", (tx) => {
|
|
2477
|
-
* tx.stampTerrain({ x0: 0, y0: 0, x1: 8, y1: 8 },
|
|
2497
|
+
* tx.stampTerrain({ x0: 0, y0: 0, x1: 8, y1: 8 }, ground);
|
|
2478
2498
|
* tx.placeUnit(api.consts.unit.startLocation, 0, 4 * api.consts.tile, 4 * api.consts.tile);
|
|
2479
2499
|
* });
|
|
2480
2500
|
* api.ui.status(`${result.tiles} tiles, ${result.units} units`);
|
|
@@ -2646,6 +2666,12 @@ export interface SectionsApi {
|
|
|
2646
2666
|
move(from: number, to: number): RawEditResult;
|
|
2647
2667
|
/** Replace the whole CHK, the way File ▸ Open reads one. */
|
|
2648
2668
|
replaceFile(bytes: Uint8Array): RawEditResult;
|
|
2669
|
+
/**
|
|
2670
|
+
* The CHK inside a map file — an `.scx` / `.scm` archive's `staredit\scenario.chk`, or
|
|
2671
|
+
* the bytes themselves for a bare CHK — the way File ▸ Open reads it, for `replaceFile`.
|
|
2672
|
+
* Reads only; rejects with the reason for a file it cannot read.
|
|
2673
|
+
*/
|
|
2674
|
+
chkOf(file: Uint8Array): Promise<Uint8Array>;
|
|
2649
2675
|
/**
|
|
2650
2676
|
* Bytes after the last chunk the reader could parse — what follows a chunk header with
|
|
2651
2677
|
* a negative length, say. Save writes them back as they are; a `replaceFile` without
|
|
@@ -3292,7 +3318,8 @@ export interface ViewApi {
|
|
|
3292
3318
|
* clean up.
|
|
3293
3319
|
*
|
|
3294
3320
|
* @example
|
|
3295
|
-
* const
|
|
3321
|
+
* const rect = { x0: 4, y0: 4, x1: 12, y1: 12 };
|
|
3322
|
+
* const r = api.document.edit("Fill", (tx) => tx.fillFlat(rect, api.terrain.types()[1].id));
|
|
3296
3323
|
* if (r.changed) api.view.flash({ rect });
|
|
3297
3324
|
*/
|
|
3298
3325
|
flash(target: FlashTarget): void;
|