@scm-js/plugin-api 1.0.0 → 1.2.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 +103 -0
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1669,6 +1669,8 @@ export interface PluginApi {
1669
1669
  readonly text: TextApi;
1670
1670
  readonly query: QueryApi;
1671
1671
  readonly data: DataApi;
1672
+ /** Bit masks, special unit ids and the pixels-per-tile every record is written in. */
1673
+ readonly consts: ConstsApi;
1672
1674
  readonly graphics: GraphicsApi;
1673
1675
  readonly view: ViewApi;
1674
1676
  readonly ui: UiApi;
@@ -1773,6 +1775,12 @@ export interface NewDocumentOptions {
1773
1775
  description?: string;
1774
1776
  /** ISOM id of the terrain to fill with; the tileset's default ground when omitted. */
1775
1777
  terrainId?: number;
1778
+ /**
1779
+ * Start locations to lay down for players 1..N, as `tx.placeStartLocations` would.
1780
+ * Part of making the map, so a fresh scenario has no history to undo them from.
1781
+ */
1782
+ startLocations?: number;
1783
+ startLayout?: StartLayout;
1776
1784
  }
1777
1785
  export interface DocumentApi {
1778
1786
  isOpen(): boolean;
@@ -2570,6 +2578,101 @@ export interface DataApi {
2570
2578
  /** The GRP path an image id draws from, relative to `unit\`. */
2571
2579
  imagePath(imageId: number): string | null;
2572
2580
  }
2581
+ /**
2582
+ * The constants a plugin needs to *write* a record rather than read one: the bit masks in
2583
+ * a UNIT / THG2 / MRGN record, the few unit ids the game itself treats specially, and the
2584
+ * one conversion — 32 pixels to a tile — every object position goes through.
2585
+ *
2586
+ * They are the editor's own (`sections/objects.ts`, `editor/units.ts`) and they arrive
2587
+ * here at run time rather than in the typings on purpose: `@scm-js/plugin-api` is erased
2588
+ * before the loader ever sees the specifier, so a *value* imported from that package
2589
+ * type-checks and is then undefined. Anything a plugin needs while it runs has to come
2590
+ * off `api`. Without this a plugin writes the hex itself, which is how a sprite's kind
2591
+ * came to be read as `flags & 0x1000` in three places.
2592
+ */
2593
+ export interface ConstsApi {
2594
+ /** Map pixels to a tile. UNIT and THG2 store pixels; MTXM, MRGN and the brushes count tiles. */
2595
+ readonly tile: 32;
2596
+ readonly unit: UnitConsts;
2597
+ readonly sprite: SpriteConsts;
2598
+ readonly location: LocationConsts;
2599
+ /** Whether a unit type is a mineral field or a vespene geyser. */
2600
+ isResource(unitId: number): boolean;
2601
+ }
2602
+ export interface UnitConsts {
2603
+ /** The units.dat id of the Start Location marker. */
2604
+ readonly startLocation: 214;
2605
+ /** The three mineral field types — a mineral line uses all three so it is not one sprite repeated. */
2606
+ readonly mineralFields: readonly [
2607
+ 176,
2608
+ 177,
2609
+ 178
2610
+ ];
2611
+ readonly vespeneGeyser: 188;
2612
+ /** What a fresh resource is worth, as StarEdit writes it. */
2613
+ readonly defaultMinerals: 1500;
2614
+ readonly defaultGas: 5000;
2615
+ /** `validProperties` (offset 0x0C): which special-property fields the game reads. */
2616
+ readonly valid: {
2617
+ readonly Cloak: 1;
2618
+ readonly Burrow: 2;
2619
+ readonly InTransit: 4;
2620
+ readonly Hallucinated: 8;
2621
+ readonly Invincible: 16;
2622
+ };
2623
+ /** `validStates` (offset 0x0E): which of the record's fields are set at all. */
2624
+ readonly used: {
2625
+ readonly Owner: 1;
2626
+ readonly HitPoints: 2;
2627
+ readonly Shields: 4;
2628
+ readonly Energy: 8;
2629
+ readonly Resources: 16;
2630
+ readonly Hangar: 32;
2631
+ readonly State: 64;
2632
+ };
2633
+ /** `stateFlags` (offset 0x18): the special properties themselves. */
2634
+ readonly state: {
2635
+ readonly Cloaked: 1;
2636
+ readonly Burrowed: 2;
2637
+ readonly InTransit: 4;
2638
+ readonly Hallucinated: 8;
2639
+ readonly Invincible: 16;
2640
+ };
2641
+ /** `relationType` (offset 0x0A): how `relatedSerial` is linked. */
2642
+ readonly relation: {
2643
+ readonly NydusLink: 512;
2644
+ readonly Addon: 1024;
2645
+ };
2646
+ }
2647
+ export interface SpriteConsts {
2648
+ /**
2649
+ * THG2 `flags`. `PureSprite` is what `spriteKind` reads: with it the id is a sprites.dat
2650
+ * one and the game only draws it, without it the id is a units.dat one and the game
2651
+ * creates the unit (Installation doors and traps).
2652
+ */
2653
+ readonly flags: {
2654
+ readonly PureSprite: 4096;
2655
+ readonly Flipped: 16384;
2656
+ readonly Disabled: 32768;
2657
+ };
2658
+ }
2659
+ export interface LocationConsts {
2660
+ /** The MRGN slot that is Anywhere. The editor protects it; nothing else may write it. */
2661
+ readonly anywhere: 63;
2662
+ /**
2663
+ * `elevationFlags`. A *set* bit **excludes** that elevation — the game tests a unit
2664
+ * against the location only on the elevations whose bit is clear — so 0 means
2665
+ * everywhere, and StarEdit's ticked "Low ground" box is bit 0 clear.
2666
+ */
2667
+ readonly elevation: {
2668
+ readonly LowGround: 1;
2669
+ readonly MediumGround: 2;
2670
+ readonly HighGround: 4;
2671
+ readonly LowAir: 8;
2672
+ readonly MediumAir: 16;
2673
+ readonly HighAir: 32;
2674
+ };
2675
+ }
2573
2676
  export interface ActiveBrush {
2574
2677
  mode: TerrainMode;
2575
2678
  /** The Rect / isometric brush's terrain id. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scm-js/plugin-api",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "Type declarations for the scmJS plugin API",
5
5
  "license": "MIT",
6
6
  "types": "index.d.ts",