@scm-js/plugin-api 1.36.0 → 1.38.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 +142 -3
  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;
@@ -1327,6 +1327,80 @@ export interface TextTrigger {
1327
1327
  /** 1-based line the `Trigger(` header starts on. */
1328
1328
  line: number;
1329
1329
  }
1330
+ /** Every kind of thing a condition or action can refer to. */
1331
+ export type TriggerRefKind =
1332
+ /** A switch; `id` is its 0-based number. */
1333
+ "switch"
1334
+ /** A death counter; `id` is the unit id, `players` the slots whose cell it is. */
1335
+ | "deaths"
1336
+ /** A death counter out of range — an EUD read or write; `address` is the dword it reaches, `id` the unit value as written. */
1337
+ | "memory"
1338
+ /** A location; `id` is its 0-based slot (63 is Anywhere). */
1339
+ | "location"
1340
+ /** The countdown timer; `id` is 0. */
1341
+ | "timer"
1342
+ /** A player's ore or gas; `id` is the `ResourceType`. */
1343
+ | "resources"
1344
+ /** A player's score; `id` is the `ScoreType`. */
1345
+ | "score"
1346
+ /** Units of a type; `id` is the unit id (a class id for *Any unit*, *Men*, …). */
1347
+ | "units"
1348
+ /** Victory, Defeat or Draw; `id` is the action type, `players` the trigger's owners. */
1349
+ | "outcome"
1350
+ /** A string of the map's string table; `id` is the 1-based string index. */
1351
+ | "string"
1352
+ /** A sound; `id` is the string index of its file name. */
1353
+ | "wav"
1354
+ /** A Run AI Script code (four characters as a little-endian u32). */
1355
+ | "aiScript"
1356
+ /** A Create Unit with Properties slot, 0-based. */
1357
+ | "cuwp";
1358
+ /**
1359
+ * `read`: a condition tests it. `write`: an action changes it. `use`: an action names it
1360
+ * without changing it — the location units appear at, the text a message shows.
1361
+ */
1362
+ export type TriggerRefAccess = "read" | "write" | "use";
1363
+ export interface TriggerRef {
1364
+ kind: TriggerRefKind;
1365
+ access: TriggerRefAccess;
1366
+ /** Whether a condition or an action refers to it. */
1367
+ part: "condition" | "action";
1368
+ /** The condition's or action's position in the trigger. */
1369
+ slot: number;
1370
+ /** The condition or action type. */
1371
+ type: number;
1372
+ id: number;
1373
+ /**
1374
+ * The 0-based player slots it is about, for the kinds that belong to a player
1375
+ * (`deaths`, `resources`, `score`, `units`, `outcome`); empty for the rest, and for a
1376
+ * condition such as *Command the Most* that compares every player.
1377
+ */
1378
+ players: number[];
1379
+ /** The player group as the record stores it, where the record has one. */
1380
+ group?: number;
1381
+ /**
1382
+ * The group resolves only while the game runs (*Foes*, *Allies*, *Neutral Players*,
1383
+ * *Non Allied Victory Players*), so `players` is every slot it could name.
1384
+ */
1385
+ approximate?: boolean;
1386
+ /** `memory`: the address reached (rounded down to a dword). */
1387
+ address?: number;
1388
+ /** `memory`: the bits a masked record reaches (its `location` field), when the record is masked. */
1389
+ mask?: number;
1390
+ /** The condition or action is switched off (its Disabled flag); the game skips it. */
1391
+ disabled?: boolean;
1392
+ }
1393
+ export interface TriggerRefs {
1394
+ /** The trigger's index in the list. */
1395
+ index: number;
1396
+ /** The 0-based slots the trigger runs for. */
1397
+ owners: number[];
1398
+ /** The player groups ticked in the trigger, as stored. */
1399
+ groups: number[];
1400
+ /** Set by the Disabled flag, or no player owns it: the game never runs it. */
1401
+ inert: boolean;
1402
+ refs: TriggerRef[];
1403
+ }
1330
1404
  export type IssueLevel = "error" | "warn" | "info";
1331
1405
  export type IssueTarget = {
1332
1406
  kind: "location";
@@ -1992,11 +2066,25 @@ export interface Preferences {
1992
2066
  * What the Save dialog starts from: the options the file was opened with
1993
2067
  * (`"asOpened"`, the default), or one of its presets. `compression` is for a map with
1994
2068
  * no origin — new, or opened from a bare .chk — where there is nothing to follow;
1995
- * `"asOpened"` there means StarEdit's PKWARE.
2069
+ * `"asOpened"` there means StarEdit's PKWARE. `backup` keeps the file a save writes
2070
+ * over: `<name>.bak` beside it in the desktop app, the browser's storage otherwise
2071
+ * (`services/previousVersions.ts`).
1996
2072
  */
1997
2073
  save: {
1998
2074
  start: "asOpened" | "everything" | "smallest";
1999
2075
  compression: "asOpened" | ArchiveCompression;
2076
+ backup: boolean;
2077
+ };
2078
+ /**
2079
+ * Recovery copies (`hooks/useRecovery.ts`): while a map has unsaved changes, a copy of
2080
+ * it is kept in the browser's storage every `minutes` and when the editor goes to the
2081
+ * background, and dropped when the map is saved or closed. What a session that ended
2082
+ * without saving left behind is offered back at the next start. Off stops the copies
2083
+ * and drops this session's; copies left by earlier sessions are still offered.
2084
+ */
2085
+ recovery: {
2086
+ enabled: boolean;
2087
+ minutes: number;
2000
2088
  };
2001
2089
  /** How many edits Undo keeps per map (SCMDraft keeps 200). */
2002
2090
  undoLevels: number;
@@ -3147,6 +3235,39 @@ export interface TriggersApi {
3147
3235
  ][];
3148
3236
  switches: number[];
3149
3237
  };
3238
+ /**
3239
+ * What each trigger reads, writes and names — TRIG when `list` is omitted, one entry per
3240
+ * trigger in list order. A condition *reads* (a switch, a death counter, the timer, a
3241
+ * player's ore, units at a location); an action *writes* (Set Switch, Set Deaths, Create
3242
+ * Unit, Move Location's target, Victory) or *uses* something without changing it (the
3243
+ * location units appear at, the text a message shows, a sound). Player groups are
3244
+ * resolved to slots against the map's forces, *Current Player* as the trigger's owners;
3245
+ * a Deaths record past the counters is a `memory` reference with its address.
3246
+ *
3247
+ * What a plugin needs to draw how triggers depend on each other, find a switch that is
3248
+ * set and never tested, or answer "which triggers can end the game". With `briefing`,
3249
+ * MBRF, where only strings and sounds are referred to.
3250
+ *
3251
+ * @example
3252
+ * // Switches something tests that nothing ever sets.
3253
+ * const refs = api.triggers.references().flatMap((t) => t.refs).filter((r) => r.kind === "switch");
3254
+ * const set = new Set(refs.filter((r) => r.access === "write").map((r) => r.id));
3255
+ * const never = [...new Set(refs.filter((r) => r.access === "read" && !set.has(r.id)).map((r) => r.id))];
3256
+ */
3257
+ references(list?: TriggerRecord[], options?: {
3258
+ briefing?: boolean;
3259
+ }): TriggerRefs[];
3260
+ /**
3261
+ * The 0-based player slots a player group names on the open map: a slot itself, the
3262
+ * members of a force, players 1–8 for *All Players*, and for *Current Player* the slots
3263
+ * of `owners` (the groups a trigger is ticked for). `approximate` when the group is only
3264
+ * settled while the game runs (*Foes*, *Allies*, *Neutral Players*, *Non Allied Victory
3265
+ * Players*); `players` is then every slot it could name.
3266
+ */
3267
+ resolvePlayers(group: number, owners?: number[]): {
3268
+ players: number[];
3269
+ approximate: boolean;
3270
+ };
3150
3271
  /**
3151
3272
  * Tell the editor that a run of the trigger list is generated by this plugin. The
3152
3273
  * Trigger Editor badges those rows, locks them and offers the plugin's own editor in
@@ -3275,6 +3396,12 @@ export type GoTo = {
3275
3396
  } | {
3276
3397
  kind: "location";
3277
3398
  index: number;
3399
+ }
3400
+ /** Opens the Trigger Editor (or, with `briefing`, the Mission Briefing) on that trigger. */
3401
+ | {
3402
+ kind: "trigger";
3403
+ index: number;
3404
+ briefing?: boolean;
3278
3405
  };
3279
3406
  /**
3280
3407
  * The map view: where the viewport is looking, how far in, and what it draws over the
@@ -3579,6 +3706,13 @@ export interface GameDataApi {
3579
3706
  select(id: string): Promise<GameDataSource>;
3580
3707
  /** Remove a data set's copy (never the game's bundled files). True when there was one. */
3581
3708
  remove(id: string): Promise<boolean>;
3709
+ /**
3710
+ * One file of the data set in use, by its path in the extracted copy: the archive path in
3711
+ * lower case with forward slashes (`arr/units.dat`, `tileset/jungle.cv5`,
3712
+ * `unit/zerg/drone.grp`). `tileset/manifest.json` and `unit/manifest.json` list what was
3713
+ * extracted. Null when the copy has no such file, or there is no game data.
3714
+ */
3715
+ read(path: string): Promise<Uint8Array | null>;
3582
3716
  }
3583
3717
  /**
3584
3718
  * The constants a plugin needs to *write* a record rather than read one: the bit masks in
@@ -4266,7 +4400,12 @@ export interface MapButtonHandle {
4266
4400
  * not yet applied to the map — so a slot's button can fill it in and leave OK to them.
4267
4401
  *
4268
4402
  * - `mapProperties`: `name`, `description`.
4269
- * - `triggerEditor`, `stringEditor`, `playerSettings`, `missionBriefing`: no fields, a slot only.
4403
+ * - `triggerEditor`, `missionBriefing`: `selected`, the selected row's index in the list
4404
+ * as text (`""` for none). Setting it selects that row. The index is into the dialog's
4405
+ * working copy, which matches `triggers.list()` until the person inserts or removes rows.
4406
+ * And `modified`, `"1"` while that working copy has changes not yet applied (read only):
4407
+ * `close()` discards them, so ask before closing when it is set.
4408
+ * - `stringEditor`, `playerSettings`: no fields, a slot only.
4270
4409
  *
4271
4410
  * A plugin's own dialog can offer a slot too (`DialogSpec.slot`), under an id of its
4272
4411
  * choosing — `"trigedit.text"` is the Text Trigger Editor's, lending `text` with
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scm-js/plugin-api",
3
- "version": "1.36.0",
3
+ "version": "1.38.0",
4
4
  "description": "Type declarations for the scmJS plugin API",
5
5
  "license": "MIT",
6
6
  "types": "index.d.ts",