scmJS docs

api.terrain

TerrainApi

Reading the terrain: the tileset's paintable types, the ISOM lattice, flood regions, blend candidates and the symmetry mode. Painting goes through document.edit.

Members

types

types(): TerrainType[];

Paintable flat terrains of the open map's tileset (empty without the graphics).

await api.tileset.load();
for (const t of api.terrain.types()) api.log(t.id, t.name, `height ${t.height}`, t.buildable ? "buildable" : "");
Try it

isomTypes

isomTypes(): number[];

Terrain ids the isometric brush can paint on this tileset.

hasIsom

hasIsom(): boolean;

Whether the open map carries an ISOM section the isometric brush can work on.

checkIsom

checkIsom(): Promise<IsomReport | null>;

How well the ISOM describes the tiles, and what rebuilding it would do about that: rects measured, mismatched among them, inherent of those a rebuild would leave behind (terrain no lattice describes — hand-placed tiles, blends, another editor's ground), and stale when a rebuild would bring more than the palette's threshold back in step. Null when the map has no ISOM (hasIsom) or no map is open. Waits for the tileset graphics to load and rejects when they are missing.

Offer tx.rebuildIsom on stale, not on mismatched: the two measure opposite directions, a rebuild converges in one pass, and inherent never goes away.

const r = await api.terrain.checkIsom();
if (r?.stale) api.document.edit("Rebuild ISOM", (tx) => { tx.rebuildIsom(); });
Try it

tileInfo

tileInfo(id: number): TileInfo | null;

terrainAt

terrainAt(tx: number, ty: number): number | null;

The terrain a tile belongs to, as the id types() lists (a flat pair's CV5 index): the tile's own group when it is flat ground, else — under a cliff, a shore or a doodad — what the ISOM lattice says the diamond there is. Null off the map, without the tileset graphics, or when neither tells.

// Name the terrain under the pointer.
const { x, y } = api.view.cursorTile();
const id = api.terrain.terrainAt(x, y);
api.ui.status(api.terrain.types().find((t) => t.id === id)?.name ?? "unknown terrain");
Try it

color

color(tileId: number): number | null;

The atlas average of a tile, packed 0xRRGGBB, or null without graphics.

terrainColor

terrainColor(terrainId: number): number | null;

The mean colour of a terrain's common flat variations, packed 0xRRGGBB.

heightOf

heightOf(terrainId: number): 0 | 1 | 2 | null;

A flat terrain's height level (0 low, 1 high, 2 higher), or null when it is not one.

diamondAt

diamondAt(px: number, py: number): Diamond;

The lattice diamond under a map pixel.

isDiamond

isDiamond(d: Diamond): boolean;

diamondsIn

diamondsIn(rect: Rect): Diamond[];

Every in-bounds diamond whose centre tile lies in rect, row by row.

floodRegion

floodRegion(x: number, y: number, match?: "terrain" | "tile"): number[];

The 4-connected area around a tile of the same terrain type ("terrain", the Rect fill's reading) or the same exact tile ("tile"), as flat indices.

blendCandidates

blendCandidates(anchorTileId: number, side: Side, options?: Partial<BlendOptions>): BlendCandidate[];

The Blend brush's list: drawable tiles whose opposite edge meets the anchor tile's side, nearest first, with the pixel distance (0..255, designed pairs 0.2–8). Empty without the graphics.

flatGroupOf

flatGroupOf(terrainId: number): number;

The Rect brush's terrain, in the tileset's own terms: the even CV5 group of a flat pair, or -1.

symmetry

symmetry(): SymmetryMode;

Tools ▸ Symmetry…: the mode the brushes paint and the palettes place under.

setSymmetry

setSymmetry(mode: SymmetryMode): void;
if (api.terrain.symmetryAvailable("rot180")) api.terrain.setSymmetry("rot180");
Try it

symmetryAvailable

symmetryAvailable(mode: SymmetryMode): boolean;

Whether a mode can run on the open map (the rotations and diagonals need a square one).

mirror

mirror(cells: Rect | Iterable<number>): number[];

Flat indices of cells and their images under the symmetry mode, each once.

mirrorPoint

mirrorPoint(px: number, py: number): { x: number; y: number; }[];

A map pixel and its images under the symmetry mode, the original first.

active

active(): ActiveBrush;

setActive

setActive(brush: Partial<ActiveBrush>): void;

Types

Declarations only this group names.

TerrainTypeinterface

interface TerrainType
group: number

Even CV5 group of the flat pair; odd columns use group + 1.

height: 0 | 1 | 2
buildable: boolean

GroupKindtype

type GroupKind = "terrain" | "edge" | "doodad" | "other";

TileInfointerface

interface TileInfo
id: number
group: number
slot: number
megatile: number

VX4 megatile, or -1 when the id points at nothing drawable.

kind: GroupKind
label: string
height: 0 | 1 | 2
buildable: boolean
walkable: number

Walkable minitiles out of 16, from VF4.

IsomReportinterface

interface IsomReport

checkIsom with what a rebuild would do about it — the verdict the palette, Check Map and the Repair plugin draw from.

The two numbers measure opposite directions and are not inverses: mismatched is the lattice failing to reproduce the tiles, while a rebuild votes a lattice out of the tiles. A rebuild converges in one pass and leaves inherent behind for good, because hand-placed tiles, blends and another editor's ground are not terrain any lattice describes. Reporting mismatched alone therefore recommended a repair that could not move the number, on every map with terrain like that.

inherent: number

Of mismatched, the rects a rebuild would leave: terrain no lattice describes.

stale: boolean

A rebuild would bring more than STALE_ISOM_SHARE of the rects back in step.

SymmetryModetype

type SymmetryMode = "none" | "h" | "v" | "hv" | "rot180" | "rot90" | "diag" | "adiag";

BlendCandidateinterface

interface BlendCandidate
id: number

MTXM tile id to place.

megatile: number
distance: number

edgeDistance between the anchor's side and this tile's opposite side.

BlendOptionsinterface

interface BlendOptions
maxDistance: number

Largest distance still listed.

limit: number

Most candidates listed per side.

include?: (id: number) => boolean

Optional filter over tile ids (the palette's group-kind dropdown).

ActiveBrushinterface

interface ActiveBrush
mode: TerrainMode
terrain: number

The Rect / isometric brush's terrain id.

tile: number

The Tile brush's MTXM id.

brushSize: number
variation: number

The Rect brush's variation slot, or -1 for a random one per pair.

Seen in

scmJS 0.7.3 + main@e2d8ba5 · Generated from the repository. The source is under the MIT license, which does not cover what ATTRIBUTION.md lists. StarCraft and Brood War are trademarks of Blizzard Entertainment; this project ships none of their data.