RuleDef

ldtk.rules.RuleDef (Class)

All the data of an auto-layer rule needed to compute tiles, plus the pure pattern helpers. The LDtk editor extends this class; other consumers (games, tools) build instances with fromJson. Pattern cell encoding: see RuleConst.

Static Members

readTileMode(v: Dynamic): Anonymous
Name Type
v Dynamic
Returns
Anonymous

readCheckerMode(v: Dynamic): Anonymous
Name Type
v Dynamic
Returns
Anonymous

fromJson(json: ldtk.AutoRuleDef): RuleDef
Name Type
json ldtk.AutoRuleDef
Returns
RuleDef

readJsonInto(r: RuleDef, json: ldtk.AutoRuleDef): Void

Read every field from JSON into an existing rule (tolerant to missing fields and legacy formats)

Name Type
r RuleDef
json ldtk.AutoRuleDef

Instance Members

uid: Int

size: Int

pattern: Array<Int>

First condition of each cell (0 = ignored). Row major, cx + cy*size.


patternAlt: Array<Array<Int>>

Extra conditions of each cell. Invariant: patternAlt[i].length>0 implies pattern[i]!=0


tileRectsIds: Array<Array<Int>>

chance: Float

breakOnMatch: Bool

alpha: Float

outOfBoundsValue: Null<Int>

flipX: Bool

flipY: Bool

tileRandomFlipX: Bool

tileRandomFlipY: Bool

active: Bool

tileMode: Anonymous

checker: Anonymous

pivotX: Float

pivotY: Float

xModulo: Int

yModulo: Int

xOffset: Int

yOffset: Int

tileXOffset: Int

tileYOffset: Int

tileRandomXMin: Int

tileRandomXMax: Int

tileRandomYMin: Int

tileRandomYMax: Int

perlinActive: Bool

perlinSeed: Int

perlinScale: Float

perlinOctaves: Int

explicitlyRequiredValues: Array<Int>

IntGrid values (or group rule values) that must exist for this rule to possibly match. Derived by updateUsedValues().


radius: Int

isValidCoord(cx: Int, cy: Int): Bool
Name Type
cx Int
cy Int
Returns
Bool

updateUsedValues(): Void

Recompute explicitlyRequiredValues. Must be called after any pattern change. Only single-condition cells are hard requirements.


getPattern(cx: Int, cy: Int): Int
Name Type
cx Int
cy Int
Returns
Int

setPattern(cx: Int, cy: Int, v: Int): Int

Set a cell to a single condition (any extra condition of this cell is discarded)

Name Type
cx Int
cy Int
v Int
Returns
Int

getCellConditions(cx: Int, cy: Int): Array<Int>

All the conditions of a cell (first one from pattern, then the extra ones), or an empty array. Allocates: not for hot paths.

Name Type
cx Int
cy Int
Returns
Array<Int>

hasMultiConditions(cx: Int, cy: Int): Bool
Name Type
cx Int
cy Int
Returns
Bool

hasAnyMultiConditionCell(): Bool
Returns
Bool

setCellConditions(cx: Int, cy: Int, conds: Array<Int>): Void

Replace all the conditions of a cell. Zeros are removed, duplicates are removed, and if both +v and -v are present only the last one is kept. A cell matches if (it has no required value, or the cell value is one of the required values) AND (the cell value is none of the forbidden values).

Name Type
cx Int
cy Int
conds Array<Int>

fill(v: Int): Void
Name Type
v Int

resize(newSize: Int): Void

Change the pattern size, keeping the existing cells centered

Name Type
newSize Int

trim(): Void

Shrink the pattern while its borders are empty


isEmpty(): Bool
Returns
Bool

isSymetricX(): Bool
Returns
Bool

isSymetricY(): Bool
Returns
Bool

hasAnyPositionOffset(): Bool
Returns
Bool

hasRandomTileFlip(): Bool
Returns
Bool

hasAnyRandomVariation(): Bool

Any random variation of the rendered tile (position offset or flip). For UI purpose.

Returns
Bool

hasAnyRandomFeature(): Bool

TRUE if this rule uses any random feature (chance, perlin, tile pick, offsets, flips)

Returns
Bool

hasPerlin(): Bool
Returns
Bool

setPerlin(active: Bool): Void
Name Type
active Bool

getPerlin(): RulePerlin
Returns
RulePerlin

passesChance(layerSeed: Int, cx: Int, cy: Int): Bool

Random chance test, shared by the 4 flip variants of a cell

Name Type
layerSeed Int
cx Int
cy Int
Returns
Bool

perlinAccepts(layerSeed: Int, cx: Int, cy: Int): Bool

Perlin filtering test

Name Type
layerSeed Int
cx Int
cy Int
Returns
Bool

passesModulo(cx: Int, cy: Int): Bool

Modulo and checker tests

Name Type
cx Int
cy Int
Returns
Bool

isRelevantIn(source: RuleSource): Bool

Prefilter: FALSE if a required value is absent from the whole source layer

Name Type
source RuleSource
Returns
Bool

isRelevantAt(source: RuleSource, cx: Int, cy: Int): Bool

Prefilter: FALSE if a required value is absent from the areas covered by the pattern around given coord

Name Type
source RuleSource
cx Int
cy Int
Returns
Bool

getRandomTileRectIdsForCoord(seed: Int, cx: Int, cy: Int, flips: Int): Array<Int>

The tile rect to render at given coord (a reference into tileRectsIds, do not modify)

Name Type
seed Int
cx Int
cy Int
flips Int
Returns
Array<Int>

getRandomTileFlipsForCoord(seed: Int, cx: Int, cy: Int, flips: Int): Int

Random render flip bits (bit0=X, bit1=Y) for given coord, based on tileRandomFlipX/Y

Name Type
seed Int
cx Int
cy Int
flips Int
Returns
Int

getXOffsetForCoord(seed: Int, cx: Int, cy: Int, flips: Int): Int
Name Type
seed Int
cx Int
cy Int
flips Int
Returns
Int

getYOffsetForCoord(seed: Int, cx: Int, cy: Int, flips: Int): Int
Name Type
seed Int
cx Int
cy Int
flips Int
Returns
Int

new(uid: Int, ?size: Int = 3): Void
Name Type Default
uid Int
size Int 3

Private Members

EMPTY_TILE_IDS: Array<Int>

readInt(v: Dynamic, def: Int): Int
Name Type
v Dynamic
def Int
Returns
Int

readFloat(v: Dynamic, def: Float): Float
Name Type
v Dynamic
def Float
Returns
Float

readBool(v: Dynamic, def: Bool): Bool
Name Type
v Dynamic
def Bool
Returns
Bool

coordId(cx: Int, cy: Int): Int
Name Type
cx Int
cy Int
Returns
Int

initPattern(): Void

cellEquals(i: Int, j: Int): Bool

Compare all the conditions of 2 cells (order insensitive)

Name Type
i Int
j Int
Returns
Bool