@scm-js/plugin-api 1.10.0 → 1.12.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 +41 -4
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -1639,6 +1639,13 @@ export interface DoodadPlacementOptions {
1639
1639
  /** Keep the left column on an even tile, as StarEdit always does. */
1640
1640
  snapToGrid: boolean;
1641
1641
  }
1642
+ export interface DoodadVerdict {
1643
+ ok: boolean;
1644
+ /** The footprint leaves the map (never allowed). */
1645
+ outOfBounds: boolean;
1646
+ /** Cell indices (row-major) whose ground fails the check, for the ghost to mark red. */
1647
+ bad: number[];
1648
+ }
1642
1649
  export type StartLayout = "ring" | "corners";
1643
1650
  export interface StartPlacementResult {
1644
1651
  changes: UnitChange[];
@@ -1840,8 +1847,9 @@ export interface Disposable {
1840
1847
  * builders (`document.edit` and `document.update`) are the exception, and deliberately
1841
1848
  * so: their operations apply as they are called and one commit closes the transaction
1842
1849
  * when the builder returns, so an `async` builder would commit the part of its work that
1843
- * ran before the first `await` and leave the rest to land outside the entry, breaking
1844
- * undo without an error. Do the awaiting *before* the call:
1850
+ * ran before the first `await` and leave the rest with nowhere to land: the transaction
1851
+ * is closed once the builder returns, and every call on it throws from then on. Do the
1852
+ * awaiting *before* the call:
1845
1853
  *
1846
1854
  * ```ts
1847
1855
  * await api.tileset.load(); // the async part, first
@@ -2091,7 +2099,11 @@ export interface DocumentApi {
2091
2099
  * Returns an all-zero result with `changed: false` when no map is open.
2092
2100
  *
2093
2101
  * `build` is synchronous — see `Sync`. Await what you need (graphics, a pick, a
2094
- * fetch) before the call, then write in one go.
2102
+ * fetch) before the call, then write in one go. The transaction is closed when
2103
+ * `build` returns; a call on it after that throws.
2104
+ *
2105
+ * A builder that throws is rolled back: what it had applied is taken off the map
2106
+ * again, nothing reaches the history or the modified flag, and the error reaches you.
2095
2107
  *
2096
2108
  * @example
2097
2109
  * // One undo entry called "Fill", however many operations it takes.
@@ -2108,7 +2120,11 @@ export interface DocumentApi {
2108
2120
  * transaction, the way a settings dialog's OK applies its whole form at once.
2109
2121
  * Operations apply as they are called; the commit marks the map modified and bumps
2110
2122
  * what the chrome reads. There is no undo entry: keep your own if you need one.
2111
- * `build` is synchronous, as `edit`'s is.
2123
+ * `build` is synchronous, as `edit`'s is, and closed when it returns.
2124
+ *
2125
+ * There is nothing to roll an update back with, so a builder that throws leaves what
2126
+ * it wrote: the sections it touched are committed — the map is modified and the
2127
+ * chrome re-reads — and the error reaches you.
2112
2128
  *
2113
2129
  * @example
2114
2130
  * api.document.update("Rename", (tx) => {
@@ -2724,6 +2740,14 @@ export interface QueryApi {
2724
2740
  startLocations(): StartLocation[];
2725
2741
  /** Whether a unit type may be placed centred there, and what stops it; null with no map. */
2726
2742
  placement(unitId: number, x: number, y: number): PlacementVerdict | null;
2743
+ /**
2744
+ * StarEdit's ground check for a doodad with its top-left tile at (tx, ty): `ok`, or the
2745
+ * cells (row-major) whose ground is not what `DoodadInfo.required` asks for. It reads the
2746
+ * map as it is right now — inside a `document.edit` that is the map with the transaction's
2747
+ * earlier changes in — so a plugin can paint a cliff and then look for where a ramp fits.
2748
+ * Null with no map or without the tileset graphics.
2749
+ */
2750
+ doodadPlacement(doodadId: number, tx: number, ty: number): DoodadVerdict | null;
2727
2751
  /** The MASK bits at a tile: bit n set = player n + 1 starts fogged there (every bit when the map has no MASK). */
2728
2752
  fogAt(tx: number, ty: number): number;
2729
2753
  /** The string table as it stands (index 0 is nothing); empty with no map. */
@@ -3376,6 +3400,19 @@ export interface DoodadInfo {
3376
3400
  /** Footprint in tiles. */
3377
3401
  width: number;
3378
3402
  height: number;
3403
+ /**
3404
+ * A ramp: a doodad with the VF4 ramp bit, filed under a cliff category with no name of
3405
+ * its own. Ramps fit only on the cliff shape they were drawn for (see `required`), and
3406
+ * a tileset has them for a few terrain pairs only.
3407
+ */
3408
+ ramp: boolean;
3409
+ /**
3410
+ * Per cell (row-major, `width` × `height`): the CV5 tile group that must already lie
3411
+ * under it for StarEdit to allow the placement, or 0 for "anything". A flat terrain's
3412
+ * pair is its `TerrainType.group` (even) and `group + 1`; the other numbers are cliff
3413
+ * and shore pieces. `query.doodadPlacement` applies the rule.
3414
+ */
3415
+ required: number[];
3379
3416
  }
3380
3417
  export interface PaletteApi {
3381
3418
  active(): PaletteChoice;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scm-js/plugin-api",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "description": "Type declarations for the scmJS plugin API",
5
5
  "license": "MIT",
6
6
  "types": "index.d.ts",