import { resolveTerrainGraphics } from '@datamoc/mw_games/two-d/render';
const water = new Set(['water']);
const land = new Set(['land']);
const flagsAt = (x: number, y: number) => (x === 0 ? water : land);
const placements = resolveTerrainGraphics(2, 1, [
{ id: 'coast', conditions: [{ dx: 0, dy: 0, hasAll: ['land'] }, { dx: -1, dy: 0, hasAll: ['water'] }], images: [{ image: 'coast.png' }] },
], flagsAt);
console.log(placements); // [{ x: 1, y: 0, ruleId: 'coast', image: 'coast.png', dx: 0, dy: 0, layer: 0 }]
Resolves a
[terrain_graphics]-style rule set over a grid into the flat list of image placements a renderer draws, the generalisationAutotile's 47-shape blob table cannot express: a rule can test flags rather than only "same terrain", key off any offset rather than only the 8 immediate neighbours, place more than one image (so a piece bigger than one cell, overlapping its neighbours, is one rule'simagesrather than somethingTileMap's one-sprite-per-cell grid has to hold), and vary by rotation or probability.At each cell, every rule (at every rotation it declares) is tested; among the rules that match, the most specific (most conditions) wins, and
probabilitybreaks a tie among rules of equal specificity. A cell with no matching rule contributes nothing. The result is plain data - which cell, which rule, which image, at what offset and layer - a caller draws throughTileMap, a customSpritepass, or anything else; this function never touches a renderer itself.