Skip to content

Grow grass on ground tiles ​

Give the layer's look on: { tiles } and grass grows on every cell painted with those tiles. It follows the paint as you change it, in the editor and in play.

ts
// in src/view.ts
import { foliage, type GameView } from '@v12-engine/client'

export const view: GameView = {
	units: { looks: {} },
	ground: { cellLayers: { grass: foliage({ on: { tiles: ['grass', 'darkGrass'] } }) } }
}

Done: a short, thin sward covers every grass and dark grass tile of the map. The layer's own cells still need to be in your rules (defineCellLayer({ id: 'grass', … })).

By default it is a style of its own: one tuft a cell at 0.7 of the layer's height, cheap over a whole map. It is the screen's alone: it hides nobody, slows nobody and never burns.

Grass from tiles that hides and burns ​

Draw the grown cells as a style, and paint them into the layer once as the world begins so the rules see them:

ts
import { createGame, defineCellLayer, foliagePack, growOnTiles, presetFoliageStyles } from '@v12-engine/engine'
import { foliage, presetFoliage } from '@v12-engine/client'

export const game = createGame({
	id: 'my-game',
	name: 'My game',
	cellLayers: [defineCellLayer({ id: 'grass', name: 'Grass', values: [{ value: 1, name: 'Tall grass', foliage: presetFoliageStyles.tallGrass }] })],
	packs: [foliagePack({ layer: 'grass' })]
})
game.onStart((world) => {
	growOnTiles(world, 'grass', ['darkGrass'], 1)
})

export const look = foliage({ ...presetFoliage.tallGrass, on: { tiles: ['darkGrass'], style: 1 } })

From then on those cells are painted like any others: saved, sent to the screens, and remembered through the fog. Tiles painted later grow grass on the screen, but nothing in the rules, until growOnTiles is called again.

A look for the grown grass ​

ts
import { FOLIAGE_TILE_STYLE, foliage } from '@v12-engine/client'

export const look = foliage({ on: { tiles: ['grass'], density: 2 }, styles: { [FOLIAGE_TILE_STYLE]: { height: 0.5, colors: { tip: [0.5, 0.65, 0.3] } } } })

In the editor ​

There is no row for on in the Grass and bushes panel yet. Set it in code or in the game's cellLayers.json; the panel keeps it. Painting the tiles with Paint (B) grows the grass live.

Reference ​

onDefaultWhat it does
tilesThe tile ids it grows on
style255 (FOLIAGE_TILE_STYLE)The style it is drawn as
density1Tufts a cell, where style is left out
height0.7 of the layer'sWhere style is left out

A cell painted with the layer wins over its tile, and a style drawn as false keeps a cell bare. A cell's tile is the one painted on it, not the blend drawn at its corners. placing.tiles and notTiles still filter every cell: on.tiles adds cells, placing.tiles takes them away. on belongs to the layer, never to a style.