Give a patch its own grass
A patch is a style painted on cells. To make one, add a value to the layer with its own rules (foliage) and its own look (styles), then paint that value where you want the patch.
ts
// in src/rules.ts
import { defineCellLayer, foliagePack, type Rules } from '@v12-engine/engine'
import { rules } from './rules'
export const grassRules: Rules = {
...rules,
cellLayers: [
defineCellLayer({
id: 'grass',
name: 'Grass',
values: [
{ value: 1, name: 'Meadow', foliage: { flammable: 0.6 } },
{ value: 2, name: 'Dry field', color: [0.8, 0.7, 0.3], foliage: { flammable: 1, burns: 4, fuel: 1.5 } }
]
})
],
packs: [...(rules.packs ?? []), foliagePack({ layer: 'grass' })]
}ts
// in src/view.ts
import { foliage } from '@v12-engine/client'
// value 2 is shorter and straw-coloured; anything it leaves out is the meadow's
export const grass = foliage({ density: 4, styles: { 2: { height: 0.9, colors: { foot: [0.4, 0.35, 0.18], tip: [0.85, 0.75, 0.45] } } } })ts
// as the game starts, or during play: the patch
import { setFoliage, type World } from '@v12-engine/engine'
export function dryField(world: World): number[] {
return setFoliage(world, 'grass', { kind: 'rect', x: 40, z: 24, width: 12, depth: 8 }, 2)
}Done: a straw-coloured field sits inside the meadow, and it burns faster and hotter than the grass around it.
Change a patch while the game runs
To change it for every player, set its look from the rules through the map's environment, eased in over time:
ts
import type { World } from '@v12-engine/engine'
export function autumn(world: World): void {
world.setEnvironment({ bushes: { grass: { styles: { 1: { colors: { tip: [0.85, 0.65, 0.3] } } } } } }, { over: 20 })
}To change it on one screen only, call client.foliage('grass')?.setStyle(2, { height: 1.2 }).
In the editor
- In the Terrain panel, under your layer's name (Grass), pick the Patch tool's Wand and click the patch, or drag a Rectangle.
- Press Its own settings. A new style is painted on the cells and its settings open.
- Give it a Name and Colour, set its look, and set its Gameplay.
- Under Set for, pick This map or Every map (the game's).
See Grass and bushes in the editor.
Reference
| Where | What |
|---|---|
CellLayerDef.values[n].foliage | The style's rules (FoliageStyleDef), laid over the pack's style |
FoliageLook.styles[n] | The style's look, laid over the layer's; false draws nothing |
setFoliage(world, layer, where, n) | Paints the style, checked |
data.json cellLayers, GameMap.definitions | The same rules, as the editor sets them |
A layer holds up to 255 styles.