scmJS docs

Melee Wizard

scm-js/plugin-melee-wizard, installed from Browse Plugins, is the worked example for placeUnit / canPlaceUnit / updateUnits inside one document.edit, and for a map tool whose press-and-drag is previewed with draw: Tools ▸ Melee Wizard… (Ctrl+Shift+M). layout.ts there is the pure geometry with its tests: ringPositions enumerates the tile positions of a footprint at exactly the game's three-tile gap from the 4 × 3 hall (Chebyshev, the rule the game applies to resource depots), layoutBase grows the mineral line along that ring from the position nearest the pointed direction, wrapping round the hall's corner, and puts the geyser on its own ring past the end of the line; symmetryImages gives the point maps of the nine layouts (identity first, the across-the-map image second, so a 2-of-4 game still faces players), rectImages maps a footprint and snaps it back, and baseImages lays a base out again for an image that swaps the axes (a rotation by 90° or a diagonal mirror), since a 2 × 1 patch cannot turn on its side. symmetryGaps and summarizeBases are the checks.

plugin.ts runs three tools on api.ui.mapTool: start locations (hover shows the hall and its images with player labels, a click places them, replacing the players' old ones when the option says so), base (press for the hall spot — inside an existing start location's footprint snaps to it — drag for the direction, every footprint of every image previewed with api.query.placement colouring the refused ones red, release to place through placeUnit with updateUnits setting the amount), and the blocking patch. Bases at every start location mirrors one layout when the starts follow the symmetry (api.query.startLocations() against the images, within a tile) and lays each out otherwise. Mirror selected units maps api.selection.units() through the images, resolving each image's player by composing the maps, and Check symmetry selects what symmetryGaps reports through api.selection.setUnits.