@scm-js/plugin-api 1.31.0 → 1.33.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 +210 -145
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -816,74 +816,6 @@ export type TerrainPick = {
816
816
  kind: "tile";
817
817
  id: number;
818
818
  };
819
- export interface Diamond {
820
- x: number;
821
- y: number;
822
- }
823
- export interface IsomCheck {
824
- /** Rects that have tiles under them. */
825
- rects: number;
826
- /** Rects whose tiles are not what their ISOM resolves to (doodad tiles are excused). */
827
- mismatched: number;
828
- }
829
- /**
830
- * `checkIsom` with what a rebuild would do about it — the verdict the palette, Check Map
831
- * and the Repair plugin draw from.
832
- *
833
- * The two numbers measure opposite directions and are not inverses: `mismatched` is the
834
- * lattice failing to reproduce the tiles, while a rebuild votes a lattice out of the
835
- * tiles. A rebuild converges in one pass and leaves `inherent` behind for good, because
836
- * hand-placed tiles, blends and another editor's ground are not terrain any lattice
837
- * describes. Reporting `mismatched` alone therefore recommended a repair that could not
838
- * move the number, on every map with terrain like that.
839
- */
840
- export interface IsomReport extends IsomCheck {
841
- /** Of `mismatched`, the rects a rebuild would leave: terrain no lattice describes. */
842
- inherent: number;
843
- /** A rebuild would bring more than `STALE_ISOM_SHARE` of the rects back in step. */
844
- stale: boolean;
845
- }
846
- export interface LocationStringChange {
847
- index: number;
848
- before: string | null;
849
- after: string | null;
850
- }
851
- export interface LocationChange {
852
- index: number;
853
- before: LocationRecord;
854
- after: LocationRecord;
855
- /** A string slot the edit adds (a name no existing string matched); removed again on undo. */
856
- string?: LocationStringChange;
857
- }
858
- export interface Bounds {
859
- left: number;
860
- top: number;
861
- right: number;
862
- bottom: number;
863
- }
864
- export interface LocationPatch {
865
- name?: string;
866
- left?: number;
867
- top?: number;
868
- right?: number;
869
- bottom?: number;
870
- elevationFlags?: number;
871
- }
872
- export type FogMode = "fog" | "clear";
873
- export interface SpriteChange {
874
- index: number;
875
- before: SpriteRecord | null;
876
- after: SpriteRecord | null;
877
- }
878
- export type SpriteKind = "pure" | "unit";
879
- /** Unit type catalogue: StarEdit names by units.dat id, and the palette's grouping of them. */
880
- export type RaceKey = "terran" | "zerg" | "protoss" | "neutral";
881
- export interface UnitGroup {
882
- race: RaceKey;
883
- label: string;
884
- /** units.dat ids, in palette order. */
885
- units: number[];
886
- }
887
819
  export interface UnitsDat {
888
820
  /** flingy.dat index. */
889
821
  flingy: Uint8Array;
@@ -975,6 +907,164 @@ export interface TechdataDat {
975
907
  /** The technology's name: a 1-based `stat_txt.tbl` index, 0 for none. */
976
908
  label: Uint16Array;
977
909
  }
910
+ /**
911
+ * Unit edits as invertible change lists, in the same spirit as terrain's `TileChange`.
912
+ * `before`/`after` are whole records: null `before` is an insertion at `index`, null
913
+ * `after` a removal, both set a replacement. Removals are listed highest index first so
914
+ * that applying them in order keeps the remaining indices valid; undo walks the list
915
+ * backwards and so re-inserts lowest first.
916
+ */
917
+ export interface UnitChange {
918
+ index: number;
919
+ before: UnitRecord | null;
920
+ after: UnitRecord | null;
921
+ }
922
+ export interface SpriteChange {
923
+ index: number;
924
+ before: SpriteRecord | null;
925
+ after: SpriteRecord | null;
926
+ }
927
+ export type SpriteKind = "pure" | "unit";
928
+ export interface DoodadChange {
929
+ index: number;
930
+ before: DoodadRecord | null;
931
+ after: DoodadRecord | null;
932
+ }
933
+ export interface DoodadPlacementOptions {
934
+ /** Skip StarEdit's ground check: any doodad goes on any terrain, even over another doodad. */
935
+ placeAnywhere: boolean;
936
+ /** Keep the left column on an even tile, as StarEdit always does. */
937
+ snapToGrid: boolean;
938
+ /** Place as plain terrain: the tiles (both sections) and any overlay sprite, no DD2 record — a placement and a conversion in one. */
939
+ asTerrain: boolean;
940
+ }
941
+ export interface DoodadVerdict {
942
+ ok: boolean;
943
+ /** The footprint leaves the map (never allowed). */
944
+ outOfBounds: boolean;
945
+ /** Cell indices (row-major) whose ground fails the check, for the ghost to mark red. */
946
+ bad: number[];
947
+ }
948
+ export interface LocationStringChange {
949
+ index: number;
950
+ before: string | null;
951
+ after: string | null;
952
+ }
953
+ export interface LocationChange {
954
+ index: number;
955
+ before: LocationRecord;
956
+ after: LocationRecord;
957
+ /** A string slot the edit adds (a name no existing string matched); removed again on undo. */
958
+ string?: LocationStringChange;
959
+ }
960
+ export interface Bounds {
961
+ left: number;
962
+ top: number;
963
+ right: number;
964
+ bottom: number;
965
+ }
966
+ export interface LocationPatch {
967
+ name?: string;
968
+ left?: number;
969
+ top?: number;
970
+ right?: number;
971
+ bottom?: number;
972
+ elevationFlags?: number;
973
+ }
974
+ /** The change lists of one edit; `HistoryEntry` adds the label. */
975
+ export interface HistoryEdit {
976
+ changes: TileChange[];
977
+ /** The isometric brush's changes to `scenario.isom`, undone together with the tiles. */
978
+ isom?: TileChange[];
979
+ /**
980
+ * Set when the edit gave a map an ISOM section it did not have (Rebuild ISOM). Undo
981
+ * removes the section again rather than leaving an all-zero one behind.
982
+ */
983
+ createdIsom?: Uint16Array;
984
+ /**
985
+ * Set when the edit rebuilt an existing lattice from the tiles, which is the one edit
986
+ * to `isom` the ISOM health is re-measured after: a brush stroke keeps the two in step
987
+ * by construction and is deliberately not measured (`useIsomStatus`), and measuring
988
+ * costs a second rebuild.
989
+ */
990
+ rebuiltIsom?: boolean;
991
+ /** Unit placements, moves and deletions (see editor/units.ts). */
992
+ units?: UnitChange[];
993
+ /**
994
+ * Doodad tiles stamped into or lifted off MTXM alone — TILE keeps the ground beneath
995
+ * (see editor/doodads.ts). Applied after `changes`, so a terrain stroke that removes
996
+ * the doodads it painted over restores their remaining cells on top of its own edit.
997
+ */
998
+ doodadTiles?: TileChange[];
999
+ /** DD2 record insertions, removals and replacements. */
1000
+ doodads?: DoodadChange[];
1001
+ /** THG2 record changes: the Sprites layer's edits, and a doodad's overlay sprite coming and going with it. */
1002
+ sprites?: SpriteChange[];
1003
+ /** MRGN slot replacements — create, move, resize, rename, delete (see editor/locations.ts); a rename may carry a string. */
1004
+ locations?: LocationChange[];
1005
+ /** Fog of war edits to `scenario.mask` (see editor/fog.ts); `at` indexes the MASK byte. */
1006
+ fog?: TileChange[];
1007
+ /**
1008
+ * Set when the edit gave a map a MASK section it did not have (the first fog stroke
1009
+ * on such a map). Undo removes the section again.
1010
+ */
1011
+ createdMask?: Uint8Array;
1012
+ }
1013
+ /**
1014
+ * Why the map changed: an edit recorded in the history, an undo or redo of one, a dialog
1015
+ * writing its tables (settings, triggers, strings — outside the history), a change to the
1016
+ * whole document (resize, tileset change, raw section edit), or other people's edits on a
1017
+ * shared map.
1018
+ */
1019
+ export type CommitReason = "edit" | "undo" | "redo" | "tables" | "whole" | "remote";
1020
+ /** Which parts of the map one commit touched. */
1021
+ export interface CommitParts {
1022
+ terrain: boolean;
1023
+ isom: boolean;
1024
+ units: boolean;
1025
+ doodads: boolean;
1026
+ sprites: boolean;
1027
+ locations: boolean;
1028
+ fog: boolean;
1029
+ settings: boolean;
1030
+ triggers: boolean;
1031
+ }
1032
+ export interface Diamond {
1033
+ x: number;
1034
+ y: number;
1035
+ }
1036
+ export interface IsomCheck {
1037
+ /** Rects that have tiles under them. */
1038
+ rects: number;
1039
+ /** Rects whose tiles are not what their ISOM resolves to (doodad tiles are excused). */
1040
+ mismatched: number;
1041
+ }
1042
+ /**
1043
+ * `checkIsom` with what a rebuild would do about it — the verdict the palette, Check Map
1044
+ * and the Repair plugin draw from.
1045
+ *
1046
+ * The two numbers measure opposite directions and are not inverses: `mismatched` is the
1047
+ * lattice failing to reproduce the tiles, while a rebuild votes a lattice out of the
1048
+ * tiles. A rebuild converges in one pass and leaves `inherent` behind for good, because
1049
+ * hand-placed tiles, blends and another editor's ground are not terrain any lattice
1050
+ * describes. Reporting `mismatched` alone therefore recommended a repair that could not
1051
+ * move the number, on every map with terrain like that.
1052
+ */
1053
+ export interface IsomReport extends IsomCheck {
1054
+ /** Of `mismatched`, the rects a rebuild would leave: terrain no lattice describes. */
1055
+ inherent: number;
1056
+ /** A rebuild would bring more than `STALE_ISOM_SHARE` of the rects back in step. */
1057
+ stale: boolean;
1058
+ }
1059
+ export type FogMode = "fog" | "clear";
1060
+ /** Unit type catalogue: StarEdit names by units.dat id, and the palette's grouping of them. */
1061
+ export type RaceKey = "terran" | "zerg" | "protoss" | "neutral";
1062
+ export interface UnitGroup {
1063
+ race: RaceKey;
1064
+ label: string;
1065
+ /** units.dat ids, in palette order. */
1066
+ units: number[];
1067
+ }
978
1068
  export interface SpriteGroup {
979
1069
  label: string;
980
1070
  ids: number[];
@@ -1349,18 +1439,6 @@ export interface StringUsage {
1349
1439
  ref: number;
1350
1440
  label: string;
1351
1441
  }
1352
- /**
1353
- * Unit edits as invertible change lists, in the same spirit as terrain's `TileChange`.
1354
- * `before`/`after` are whole records: null `before` is an insertion at `index`, null
1355
- * `after` a removal, both set a replacement. Removals are listed highest index first so
1356
- * that applying them in order keeps the remaining indices valid; undo walks the list
1357
- * backwards and so re-inserts lowest first.
1358
- */
1359
- export interface UnitChange {
1360
- index: number;
1361
- before: UnitRecord | null;
1362
- after: UnitRecord | null;
1363
- }
1364
1442
  export interface PlacementOptions {
1365
1443
  /** Refuse to put a unit on top of another (ground units and buildings only). */
1366
1444
  checkCollision: boolean;
@@ -1694,65 +1772,6 @@ export interface ChangeTilesetResult {
1694
1772
  spritesDropped: number;
1695
1773
  refilled: boolean;
1696
1774
  }
1697
- export interface DoodadChange {
1698
- index: number;
1699
- before: DoodadRecord | null;
1700
- after: DoodadRecord | null;
1701
- }
1702
- export interface DoodadPlacementOptions {
1703
- /** Skip StarEdit's ground check: any doodad goes on any terrain, even over another doodad. */
1704
- placeAnywhere: boolean;
1705
- /** Keep the left column on an even tile, as StarEdit always does. */
1706
- snapToGrid: boolean;
1707
- /** Place as plain terrain: the tiles (both sections) and any overlay sprite, no DD2 record — a placement and a conversion in one. */
1708
- asTerrain: boolean;
1709
- }
1710
- export interface DoodadVerdict {
1711
- ok: boolean;
1712
- /** The footprint leaves the map (never allowed). */
1713
- outOfBounds: boolean;
1714
- /** Cell indices (row-major) whose ground fails the check, for the ghost to mark red. */
1715
- bad: number[];
1716
- }
1717
- /** The change lists of one edit; `HistoryEntry` adds the label. */
1718
- export interface HistoryEdit {
1719
- changes: TileChange[];
1720
- /** The isometric brush's changes to `scenario.isom`, undone together with the tiles. */
1721
- isom?: TileChange[];
1722
- /**
1723
- * Set when the edit gave a map an ISOM section it did not have (Rebuild ISOM). Undo
1724
- * removes the section again rather than leaving an all-zero one behind.
1725
- */
1726
- createdIsom?: Uint16Array;
1727
- /**
1728
- * Set when the edit rebuilt an existing lattice from the tiles, which is the one edit
1729
- * to `isom` the ISOM health is re-measured after: a brush stroke keeps the two in step
1730
- * by construction and is deliberately not measured (`useIsomStatus`), and measuring
1731
- * costs a second rebuild.
1732
- */
1733
- rebuiltIsom?: boolean;
1734
- /** Unit placements, moves and deletions (see editor/units.ts). */
1735
- units?: UnitChange[];
1736
- /**
1737
- * Doodad tiles stamped into or lifted off MTXM alone — TILE keeps the ground beneath
1738
- * (see editor/doodads.ts). Applied after `changes`, so a terrain stroke that removes
1739
- * the doodads it painted over restores their remaining cells on top of its own edit.
1740
- */
1741
- doodadTiles?: TileChange[];
1742
- /** DD2 record insertions, removals and replacements. */
1743
- doodads?: DoodadChange[];
1744
- /** THG2 record changes: the Sprites layer's edits, and a doodad's overlay sprite coming and going with it. */
1745
- sprites?: SpriteChange[];
1746
- /** MRGN slot replacements — create, move, resize, rename, delete (see editor/locations.ts); a rename may carry a string. */
1747
- locations?: LocationChange[];
1748
- /** Fog of war edits to `scenario.mask` (see editor/fog.ts); `at` indexes the MASK byte. */
1749
- fog?: TileChange[];
1750
- /**
1751
- * Set when the edit gave a map a MASK section it did not have (the first fog stroke
1752
- * on such a map). Undo removes the section again.
1753
- */
1754
- createdMask?: Uint8Array;
1755
- }
1756
1775
  export interface WireListChange<T> {
1757
1776
  index: number;
1758
1777
  before: T | null;
@@ -2393,8 +2412,8 @@ export interface ResizeDocumentOptions {
2393
2412
  /**
2394
2413
  * Where a map opened or created goes. `"new"` opens it beside the open one, which stays
2395
2414
  * open behind it; `"current"` opens it in place of the open one, through the unsaved-changes
2396
- * gate. Omitted, the editor follows its preference (several maps at once, on by default),
2397
- * except that the untouched blank map it started on is always replaced.
2415
+ * gate. Omitted, the editor follows its preference (several maps at once, on by default).
2416
+ * Either way the untouched blank map the editor started on is replaced, not kept.
2398
2417
  */
2399
2418
  export type OpenInto = "new" | "current";
2400
2419
  export interface OpenDocumentOptions {
@@ -3410,8 +3429,9 @@ export interface GraphicsApi {
3410
3429
  * overlays with the viewport's own graphics, then location boxes — a thumbnail for a
3411
3430
  * list of clips, or the ghost under the pointer while a plugin stamps one. It is drawn
3412
3431
  * with the graphics of the clip's *own* tileset (`clip.era`), which are in memory for
3413
- * the open map once loaded and otherwise not, so a clip from another tileset answers
3414
- * null; so does a missing tileset or a page with no canvas. Synchronous and uncached:
3432
+ * the open map once loaded; a clip from another tileset answers null until
3433
+ * `tileset.load(id)` has fetched that one. So does a missing tileset or a page with no
3434
+ * canvas. Synchronous and uncached:
3415
3435
  * keep the result while the clip and the tileset stay the same.
3416
3436
  */
3417
3437
  renderClip(clip: Clip, options?: RenderClipOptions): PluginImage | null;
@@ -3772,8 +3792,14 @@ export interface TilesetApi {
3772
3792
  id(): TilesetId | null;
3773
3793
  name(): string;
3774
3794
  isLoaded(): boolean;
3775
- /** Fetch and decode the graphics; resolves false when they were never extracted. */
3776
- load(): Promise<boolean>;
3795
+ /**
3796
+ * Fetch and decode the graphics — the open map's tileset's, or `tileset`'s — and keep
3797
+ * them in memory; resolves false when they were never extracted. Loading another
3798
+ * tileset changes nothing about the map: it is for `graphics.renderClip` drawing a clip
3799
+ * that came from a map on that tileset (a stamp, a recording), which answers null until
3800
+ * its tileset's graphics are loaded.
3801
+ */
3802
+ load(tileset?: TilesetId): Promise<boolean>;
3777
3803
  raw(): LoadedTileset | null;
3778
3804
  }
3779
3805
  export interface SelectionApi {
@@ -4947,6 +4973,8 @@ export interface HotkeyApi {
4947
4973
  export type PluginEvent =
4948
4974
  /** A map was opened, closed or replaced. */
4949
4975
  "document"
4976
+ /** A change was committed to the map in front; the listener gets a `CommitEvent` saying what and where. */
4977
+ | "commit"
4950
4978
  /** The editor's language changed (Preferences ▸ Display): re-label what is showing through `api.i18n.t`. */
4951
4979
  | "language"
4952
4980
  /** Any committed edit (every `document.edit`, stroke, undo and redo bumps it, terrain or not), and a fog edit. */
@@ -4975,6 +5003,41 @@ export type PluginEvent =
4975
5003
  | "dialogs"
4976
5004
  /** The game data source changed: installed, switched to another data set, or a copy removed. `gameData.source()` says what it is now. */
4977
5005
  | "gameData";
5006
+ /**
5007
+ * What the `"commit"` event hands its listeners: one change to the map in front, after it
5008
+ * is in the scenario. Every stroke, `document.edit`, undo and redo is one commit; so is a
5009
+ * dialog's OK or a `document.update` (reason `"tables"`), a resize, tileset change or raw
5010
+ * section edit (`"whole"`), and a batch of other people's edits on a shared map
5011
+ * (`"remote"`). A dialog that writes both settings and triggers may send two. Opening,
5012
+ * closing and switching maps are not commits — the `"document"` event says those.
5013
+ *
5014
+ * @example
5015
+ * api.events.on("commit", (e) => {
5016
+ * if (e.parts.terrain && e.area) redrawTiles(e.area);
5017
+ * else if (e.reason === "whole" || e.reason === "remote") redrawAll();
5018
+ * });
5019
+ */
5020
+ export interface CommitEvent {
5021
+ /** `document.id()` of the map it happened to (always the one in front). */
5022
+ id: number | null;
5023
+ reason: CommitReason;
5024
+ /**
5025
+ * The history label — the words Edit ▸ Undo shows, in the editor's language; for an undo
5026
+ * or redo, the label of the entry taken back or put back. The update's label for a
5027
+ * `document.update`, the operation's name for `"whole"`, and "" for a built-in dialog's
5028
+ * OK and for other people's edits.
5029
+ */
5030
+ label: string;
5031
+ /**
5032
+ * The tiles the change fell on, far edges exclusive: every changed tile, and the tile
5033
+ * under each moved, placed or removed object's position (its picture reaches further —
5034
+ * widen the rect by the largest picture you draw). Null when the change has no place on
5035
+ * the map (`"tables"`) or may have touched all of it (`"whole"`, `"remote"`).
5036
+ */
5037
+ area: Rect | null;
5038
+ /** Which parts changed. All of them for `"whole"` and `"remote"`, which do not say. */
5039
+ parts: CommitParts;
5040
+ }
4978
5041
  /** Why other people's changes are waiting: a stroke under way on the map, a dialog that edits the map open, another map in front. */
4979
5042
  export type SyncHold = "stroke" | "dialog" | "behind";
4980
5043
  export interface SyncReport {
@@ -5101,8 +5164,10 @@ export interface EventsApi {
5101
5164
  * if (e.reason === "open") check(e.fileName);
5102
5165
  * });
5103
5166
  * api.events.on("terrain", () => redraw());
5167
+ * api.events.on("commit", (e) => console.log(e.reason, e.label, e.area));
5104
5168
  */
5105
5169
  on(event: "document", listener: (event: DocumentEvent) => void): Disposable;
5170
+ on(event: "commit", listener: (event: CommitEvent) => void): Disposable;
5106
5171
  on(event: PluginEvent, listener: () => void): Disposable;
5107
5172
  }
5108
5173
  export interface StorageApi {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scm-js/plugin-api",
3
- "version": "1.31.0",
3
+ "version": "1.33.0",
4
4
  "description": "Type declarations for the scmJS plugin API",
5
5
  "license": "MIT",
6
6
  "types": "index.d.ts",