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.

seamStep

seamStep(tileId: number, side: Side, neighbourId: number): number | null;

How much of a step the join is between a tile and the tile on its side: the difference between the two rows of pixels that meet, less what each picture changes by one pixel in from that edge. Around 0 for tiles drawn to meet; over 8, View ▸ Seam Overlay draws the join. Null without the graphics or for a tile with no picture.

seams

seams(cells?: Cells): number;

How many joins View ▸ Seam Overlay draws on cells (on the whole map when omitted); 0 without the graphics.

pinned

pinned(): number[];

The pinned tiles (tx.pin), as flat indices in ascending order.

handLaid

handLaid(rect?: Rect): number[];

The tiles laid by hand, as far as the map can tell: those its isometric data does not account for (a doodad placed as terrain, a blend, another editor's ground), in rect or on the whole map. Empty without ISOM or the graphics.

// Keep everything hand-laid before repainting around it.
api.document.edit("Pin hand-laid ground", (tx) => { tx.pin(api.terrain.handLaid()); });
Try it

symmetryShares

symmetryShares(): Partial<Record<SymmetryMode, number>>;

How alike the map's ground plays to its own image under each symmetry mode that fits its shape, 0..1: the share of small squares (minitiles) that walk, stand and build as their images do. A mirrored map reads 0.98 and up under its own mode. Empty without the graphics.

fairness

fairness(mode?: SymmetryMode): FairnessReport | null;

The map against its own image under mode (the symmetry tool's mode when omitted): how many small squares differ in walking, height and building, the places they are in, a mask for drawing them, and the mineral fields, geysers and start locations with no equal counterpart. Null for "none", for a mode the map's shape does not allow, and without the graphics.

const report = api.terrain.fairness("h");
if (report) api.ui.status(`${report.unlike} small squares differ in ${report.places.length} places`);
Try it

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;
// Arm the Tile brush with a piece the maps lay, as a click in the Pieces view does.
const [piece] = api.terrain.pieces();
if (piece) api.terrain.setActive({ mode: "tile", block: api.terrain.blockOf(piece) });
Try it

sheet

sheet(): TileSheetInfo | null;

The tileset's sheet as the Tile palette lays it out: 16 slots a row, a group a row, and where the groups the data set in use adds to the game's begin (null when it adds none). Null without the tileset graphics.

blockFrom

blockFrom(rect: { group: number; slot: number; cols: number; rows: number; }): TileBlock | null;

A rectangle of the sheet as a block: cols slots from slot across rows groups from group, a slot with no picture a hole. Null when the rectangle runs off the table, when it holds no tile, or without the graphics.

const block = api.terrain.blockFrom({ group: 2900, slot: 0, cols: 4, rows: 3 });
if (block) api.document.edit("Lay it", (tx) => { tx.placeBlock(block, 10, 10); });
Try it

pieces

pieces(): TerrainPiece[];

The list the Tile palette's Pieces view shows for the map in front, unfiltered: the sets plugins provide for its tileset first, then the pieces cut from the map and from what was learned from folders of maps, the same tiles listed once. A cut piece with the same tiles as a provided one is left out. The learned part is read the first time it is asked for, and the "pieces" event fires when it arrives. Empty without a map or the graphics.

const walls = api.terrain.pieces().filter((p) => p.category === "Walls");
api.log(`${walls.length} walls, ${api.terrain.pieces().length} pieces in all`);
Try it

pieceAt

pieceAt(x: number, y: number): TerrainPiece | null;

The piece the map lays at a tile, by the Pieces view's Alt+click rule: the tile is one of a cut piece's, and a neighbour from the same piece is laid beside it as in the sheet. Null otherwise.

blockOf

blockOf(piece: TerrainPiece): TileBlock;

A piece as the block that lays it: its rectangle in the sheet, a hole where it has no tile.

cutPieces

cutPieces(maps: readonly PieceMap[]): TerrainPiece[];

The pieces the rule cuts from maps of your own (each { tiles, width, height }), read against the tileset of the map in front — to mine a folder and keep the result where you like. The same tiles are folded into one piece when the graphics are loaded. Nothing is kept by the editor.

// Maps read with @scm-js/core's openMapBytes, bundled into the plugin.
import { openMapBytes } from "@scm-js/core";
const files = await api.ui.pickFiles({ directory: true });
const maps = [];
for (const f of files.filter((f) => /\.sc[mx]$/i.test(f.path))) {
  const opened = await openMapBytes(new Uint8Array(await f.file.arrayBuffer()), f.path).catch(() => null);
  if (opened) maps.push(opened.scenario);
}
api.log(api.terrain.cutPieces(maps).length, "pieces");

providePieces

providePieces(spec: PieceSetSpec): Disposable;

Named pieces for the Pieces view: listed under label, ahead of the pieces cut from maps, while a map on tileset is in front. A piece with a tile the loaded table lacks is not listed; a cut piece with the same tiles as one of yours is not listed again. The search box finds yours by name and category. Taken back with the plugin, or by disposing.

api.terrain.providePieces({
  id: "walls", label: "Ruined walls", tileset: "badlands",
  pieces: [{ name: "Wall, long", category: "Walls", block: api.terrain.blockFrom({ group: 2900, slot: 0, cols: 6, rows: 3 })! }],
});
Try it

provideTypes

provideTypes(spec: TerrainTypeSpec): Disposable;

Declare flat ground the tileset does not type, for the Rect brush: each group is the even group of a left/right pair, listed under name in the Rect tab and Replace Terrain, laid, filled and replaced as the Rect brush lays any pair. A group that is not such a pair in the loaded table is skipped. types() still lists the game's types alone. Taken back with the plugin, or by disposing.

api.terrain.provideTypes({ id: "ground", tileset: "jungle", types: [{ name: "Swamp", group: 2466 }] });
Try it

borrowed

borrowed(options?: { scan?: boolean; }): Promise<BorrowedTerrainInfo[]>;

The terrains of other tilesets the open map's tileset can lay (its Isometric tab's "From other tilesets"): those whose every tile, and every tile of the ground the brush lays them onto, has a copy here. Found by matching pictures, once per pair of tilesets' files, or given by a plugin (provideBorrowTable). Resolves after reading what was found before and the other tilesets' files, so tx.paintBorrowed can run; with scan: true, works it out first where it never was (seconds, once). Empty without the graphics, and when the editor draws from the game's own data (nothing there is borrowed).

for (const b of await api.terrain.borrowed({ scan: true })) api.log(b.source, b.name, b.id);
Try it

provideBorrowTable

provideBorrowTable(spec: BorrowTableSpec): Disposable;

Hand the editor the table for a pair of tilesets: which tile of tileset to write for each tile of source. The editor's own picture match is then not used for that pair: a mod's author knows which copy is meant, under which flags. borrowed() lists what the table makes paintable. Taken back with the plugin, or by disposing.

api.terrain.provideBorrowTable({ id: "install", tileset: "badlands", source: "install", pairs: [[0x30, 0x9a40], [0x31, 0x9a41]] });
Try it

provideBorderTable

provideBorderTable(spec: BorderTableSpec): Disposable;

Hand the editor the drawn border between a borrowed terrain and a ground of the map's tileset: which tile to lay for each shape of the border. It stands ahead of a data set's terrain file and of what maps taught (Learn from Maps…) for the same pair. borrowed() lists the pairs each terrain has. Taken back with the plugin, or by disposing.

api.terrain.provideBorderTable({ id: "floor-dirt", tileset: "badlands", source: "install", terrain: 3, ground: 2, shapes: { "A,A,B,h53|L": [0x9b20] } });
Try it

copies

copies(options?: { scan?: boolean; }): Promise<CopiedTerrainInfo[]>;

The open map's tileset's copied terrains (its Isometric tab's "Copied terrain"): a terrain held again at another height whose edge pieces the tileset holds there too. Found by the editor from the tileset's files (once per files, by itself when the tileset holds a copy), or given (provideCopies, a mod's terrain file). Resolves after what was found is known, so tx.paintCopy can run; with scan: true works it out first where it never was. Lists only terrains whose pieces walk and build as the terrain does at the copy's height.

for (const c of await api.terrain.copies({ scan: true })) api.log(c.terrain, c.height, c.complete ? "complete" : `${c.missing} shapes missing`);
Try it

provideCopies

provideCopies(spec: CopyBlockSpec): Disposable;

Hand the editor a block of tiles for a copied terrain: which tile stands for each piece of the terrain's edge set at the copy's height, and which ground the pieces are drawn to meet. It takes the place of what the editor found for that terrain and height. Taken back with the plugin, or by disposing.

api.terrain.provideCopies({ id: "mud-mid", tileset: "jungle", terrain: 4, height: 1, ground: { terrain: 3 }, pieces: [[0x2400, 0x9950], [0x2410, 0x9951]] });
Try it

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
label?: string

The name in the user's language, where name is not a string of the catalogue's: a pair terrain's name is put together ("Mud (mid ground)", "Group 3672"). Shown through terrainLabel.

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.

SymmetryModetype

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

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.

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).

FairnessPlaceinterface

interface FairnessPlace
x0: number

The tiles the place covers, on the side nearest the map's top-left; x1 and y1 are past the end.

y0: number
x1: number
y1: number
squares: number

Small squares that differ from an image, and how many of them in each way.

walk: number
height: number
build: number

UnmatchedResourceinterface

interface UnmatchedResource
index: number

Index into scn.units.

unitId: number
x: number
y: number
why: "missing" | "amount"

Nothing of its kind stands at an image of its spot, or what stands there holds another amount.

FairnessReportinterface

interface FairnessReport
mode: SymmetryMode
compared: number

Small squares compared: every square with its images, counted once.

unlike: number

Of those, the ones that differ from an image in any way, and in each way.

walk: number
height: number
build: number
alike: number

The share that plays alike, 0..1.

places: FairnessPlace[]

Where the differences are, largest first.

mask: Uint8Array

A byte per small square (width * 4 across), UNLIKE_* bits, set on a square and on its images.

resources: UnmatchedResource[]

Minerals, geysers and start locations with no equal counterpart.

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.

block: TileBlock | null

The block the Tile brush lays instead of one tile, or null. Setting one arms the brush with it (its first tile becomes tile); setting tile, or null here, goes back to single tiles. The editor drops a block when another map or tileset comes in front.

TerrainPieceinterface

interface TerrainPiece

A piece of the tileset: a part of its sheet that maps lay whole (a wall, a ramp, a ruin), or a named one a plugin provides. tiles are its tile ids, ascending; group, slot, cols and rows its rectangle in the sheet. laid counts how often its tiles are laid in the maps it was cut from (0 for a provided piece). copies is how many other pieces, the same tiles elsewhere in the tileset, it stands for. source is "maps" for a piece cut from maps, else the providing plugin's id.

tiles: number[]
slot: number
group: number
cols: number
rows: number
laid: number
name?: string
category?: string
copies: number
source: string

TileSheetInfointerface

interface TileSheetInfo

The tileset's sheet: 16 slots wide, a group a row. addedFrom is where the groups a data set adds begin, or null.

columns: 16
groups: number
addedFrom: number | null

PieceMapinterface

interface PieceMap

A map's tiles for terrain.cutPieces: MTXM ids row by row, as ReadonlyScenario.tiles holds them.

tiles: ArrayLike<number>
width: number
height: number

PieceSetSpecinterface

interface PieceSetSpec

What terrain.providePieces takes.

id: string

Names the set among the plugin's; the same id again replaces it.

label: string

The heading the Pieces view lists the set under.

tileset: TilesetId

The tileset the tiles are of: the set is listed while a map on it is in front.

pieces: { name?: string; category?: string; block: TileBlock; }[]

BorrowedTerrainInfointerface

interface BorrowedTerrainInfo

A terrain of another tileset the open map's tileset can lay with that tileset's own isometric brush (terrain.borrowed).

id: number

The id the palette selects (setActive({ terrain })) and tx.paintBorrowed takes. Never written to a map.

source: TilesetId

The tileset it is borrowed from.

terrain: number

Its terrain id in that tileset (what isomTypes() lists on a map of it).

name: string

That tileset's name for it.

standIns: number

Tiles laid with the nearest picture this tileset has, where it holds no copy.

from: string

"scan" when the editor matched the pictures, the id of the plugin whose table it is, or @dataset:<id> when the data set's terrain file gave it.

borders?: { ground: number; from: string; }[]

The grounds of the open map's tileset (terrain ids, as isomTypes() lists them) this terrain has drawn borders against, and where each table came from: "maps" (Learn from Maps…), a plugin's id, or @dataset:<id>. Where one is known, tx.paintBorrowed and the brush lay the tileset's own border pieces there (unless the Drawn borders switch is off). Absent in editors older than drawn borders.

CopiedTerrainInfointerface

interface CopiedTerrainInfo

A copied terrain the open map's tileset can lay with the isometric brush (terrain.copies): one of its own terrains held again at another height (the Rect tab's "Mud (mid ground)") together with the edge pieces it holds for it there.

id: number

The id the palette selects (setActive({ terrain })) and tx.paintCopy takes. Never written to a map.

terrain: number

The terrain copied: its terrain id in the tileset (what isomTypes() lists).

height: number

The copy's height: 0 low, 1 mid, 2 high.

group: number

The copy's flat pair, as the Rect tab lists it (types() with the pair's id).

complete: boolean

Whether the tileset has a tile for every edge shape the brush asks for; when not, how many it lacks.

missing: number
blocks: { ground: { terrain: number; } | { pair: number; }; complete: boolean; from: string; }[]

The blocks of tiles it can be laid with (the brush picks the one that joins the ground under a stroke best).

CopyBlockSpecinterface

interface CopyBlockSpec

What terrain.provideCopies takes: one block of tiles standing for a terrain's edge set at a copy's height.

id: string

Names the block among the plugin's; the same id again replaces it.

tileset: TilesetId
terrain: number

The terrain copied (its terrain id) and the copy's height (0 low, 1 mid, 2 high): the tileset must hold such a copy.

height: number
ground: { terrain: number; } | { pair: number; }

The ground the pieces are drawn to meet: a terrain id of the tileset, or an untyped flat pair by its even group.

pieces: readonly (readonly [ piece: number, tile: number ])[]

A piece of the terrain's edge set (group << 4 | slot) → the tile standing for it.

BorderTableSpecinterface

interface BorderTableSpec

What terrain.provideBorderTable takes.

id: string

Names the table among the plugin's; the same id again replaces it.

tileset: TilesetId

The tileset whose tiles are written (the map's).

source: TilesetId

The tileset the borrowed terrain comes from.

terrain: number

The borrowed terrain: its terrain id in source.

ground: number

The ground it meets: its terrain id in tileset.

shapes: Readonly<Record<string, readonly number[]>>

Border shape → the tiles of tileset to lay there, the likeliest first. Shapes are named as the editor reads them (the border's four sides and the tile's side of its rect, e.g. "A,B,B,h53|L"); a terrain file saved from the Pieces view after Learn from Maps… lists the ones maps use.

BorrowTableSpecinterface

interface BorrowTableSpec

What terrain.provideBorrowTable takes.

id: string

Names the table among the plugin's; the same id again replaces it.

tileset: TilesetId

The tileset whose tiles are written (the map's).

source: TilesetId

The tileset whose isometric brush lays the terrain.

pairs: readonly (readonly [ sourceTile: number, tile: number ])[]

Source tile id → the tile of tileset to write for it. A source tile with no pair is not laid.

standIns?: readonly number[]

Source tiles whose tile here is only the nearest picture, not a copy (optional). A terrain is offered only where such tiles are at most a tenth of its tiles, as the editor's own match decides.

TerrainTypeSpecinterface

interface TerrainTypeSpec

What terrain.provideTypes takes.

id: string

Names the declaration among the plugin's; the same id again replaces it.

tileset: TilesetId
types: { name: string; group: number; }[]

Each a name and the even group of a left/right pair of flat ground.

Seen in

scmJS 0.20.0 + main@c323d11 · 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.