The pack
fog
function fog(): Pack<{ fog: FogApi }>
The fog-of-war pack: a factory for FogGrids. Headless, no columns, no passes.
Classes
FogGrid
class FogGrid
A fog-of-war grid: recursive shadowcasting over opaque cells from any number of lights, a brightness per
cell, and a memory of what has been seen. Headless; the game draws it (a dark tile per cell by state(),
or an alpha from lightAt()).
readonly cols: number— Columns.readonly rows: number— Rows.falloff: FogFalloff— Default falloff for lights without their own.memory: boolean— Remember explored cells.readonly opaque: Uint8Array— 1 where a cell blocks light; cols × rows, row-major.readonly light: Float32Array— Brightness 0..1 per cell aftercompute().readonly explored: Uint8Array— 1 where a cell has ever been lit (whenmemory).readonly lights: FogLight[]— The lights.addLightappends; mutate andcompute().constructor(opts: FogGridOptions)— Build an empty, dark grid. Sizes are floored and at least 1.index(col: number, row: number): number— Row-major index of a cell.inBounds(col: number, row: number): boolean— True inside the grid.cellAt(x: number, y: number, cellSize = 1, originX = 0, originY = 0): Cell | null— The cell under a world point, given the cell size and the grid's origin; null outside.isOpaque(col: number, row: number): boolean— True when the cell blocks light (outside the grid counts as opaque).setOpaque(col: number, row: number, on: boolean): void— Make a cell a wall or not.clearOpaque(): void— Every cell open.blockFrom(grid: ReadonlyArray<ReadonlyArray<number>>, wallValue = 1): void— Set the walls from a 2D array (rows of values), treatingwallValueas opaque.addLight(col: number, row: number, radius: number, opts: { intensity?: number; falloff?: FogFalloff } = {}): FogLight— Add a light; returns it to move later. Intensity default 1.removeLight(src: FogLight): void— Remove one light; unknown lights are ignored.clearLights(): void— Remove every light.compute(): void— Recomputelightfrom every light (the max where they overlap) and extendexplored. Call after anything moved.lightAt(col: number, row: number): number— Brightness 0..1 at a cell; 0 outside.isVisible(col: number, row: number): boolean— True when lit now.isExplored(col: number, row: number): boolean— True when lit at some point (withmemory).state(col: number, row: number): FogState— The three-way state of a cell.canSee(fromCol: number, fromRow: number, toCol: number, toRow: number, range = Infinity): boolean— Bresenham line of sight between two cells through open cells, withinrangecells.reveal(col: number, row: number, radius: number): void— Mark everything a light at (col, row) withradiuswould reach as explored, without changinglight.revealAll(): void— Everything explored (a map reveal).resetMemory(): void— Nothing explored.
Types
Cell
interface Cell
A grid cell.
col: number— Column.row: number— Row.
FogApi
interface FogApi
game.fog.
create(opts: FogGridOptions): FogGrid— A fresh grid. Not scene-scoped: the game holds it.
FogFalloff
type FogFalloff = 'none' | 'linear' | 'smooth' | 'quadratic'
How a light's brightness falls with distance, as a fraction 0..1 of its radius.
FogGridOptions
interface FogGridOptions
What create takes.
cols: number— Columns.rows: number— Rows.falloff?: FogFalloff— Default falloff. Default 'smooth'.memory?: boolean— Remember lit cells as 'explored' once the light moves on. Default true.
FogLight
interface FogLight
A light source on the grid. Mutate col/row to move it, then compute().
col: number— Cell column.row: number— Cell row.radius: number— Reach in cells.intensity: number— Brightness at the source, 0..1.falloff?: FogFalloff— This light's falloff; the grid's when omitted.
FogState
type FogState = 'unseen' | 'explored' | 'visible'
A cell's state: never lit, lit once and remembered, or lit now.


