Constructor
new CellGridSimulation(widthOrOptionsopt, heightopt, optionsopt)
Creates a new CellGridSimulation instance.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
widthOrOptions | number | | <optional> | 16 | Grid width or options object. |
height | number | <optional> | 16 | Grid height if first argument was width. |
options | object | <optional> | {} | Configuration options. |
- Source
Classes
Methods
clear()
Resets all cells to default material and temperature.
- Source
countCells(predicate) → {number}
Counts the number of cells matching a predicate function.
| Name | Type | Description |
|---|---|---|
predicate | function | (cell, x, y) => boolean. |
- Source
- Type:
- number
extinguish(x, y) → {boolean}
Manually extinguishes a cell at (x, y).
| Name | Type | Description |
|---|---|---|
x | number | |
y | number |
- Source
True if cell was extinguished.
- Type:
- boolean
findCells(predicate) → {Array.<object>}
Finds coordinates of all cells matching a predicate function.
| Name | Type | Description |
|---|---|---|
predicate | function | (cell, x, y) => boolean. |
- Source
Array of { x, y, cell }.
- Type:
- Array.<object>
getCell(x, y) → {object|null}
Queries a cell safely. Returns null if coordinates are out of bounds.
| Name | Type | Description |
|---|---|---|
x | number | Column index. |
y | number | Row index. |
- Source
The cell object, or null if out of bounds.
- Type:
- object |
null
getCoordinates(index) → {object}
Converts a 1D flat array index to { x, y } coordinates.
| Name | Type | Description |
|---|---|---|
index | number |
- Source
{ x, y } coordinates.
- Type:
- object
getIgnitionThreshold(materialId) → {number}
Computes the effective ignition threshold temperature for a material. Non-flammable materials (flammability === 0) return Infinity.
| Name | Type | Description |
|---|---|---|
materialId | string |
- Source
Threshold temperature.
- Type:
- number
getIndex(x, y) → {number}
Gets 1D flat array index for (x, y) coordinates.
| Name | Type | Description |
|---|---|---|
x | number | |
y | number |
- Source
Index, or -1 if out of bounds.
- Type:
- number
getNeighbors(x, y) → {Array.<object>}
Queries the 4-cardinal in-bounds neighbors of a cell. Out-of-bounds coordinates are filtered out safely.
| Name | Type | Description |
|---|---|---|
x | number | |
y | number |
- Source
Array of { x, y, index, cell }.
- Type:
- Array.<object>
ignite(x, y) → {boolean}
Manually ignites a cell at (x, y) if the material is flammable and not charred.
| Name | Type | Description |
|---|---|---|
x | number | |
y | number |
- Source
True if cell successfully ignited.
- Type:
- boolean
isInBounds(x, y) → {boolean}
Checks if coordinates are within the grid bounds. Coordinates outside the grid boundary are safely identified.
| Name | Type | Description |
|---|---|---|
x | number | Column index. |
y | number | Row index. |
- Source
- Type:
- boolean
restore(snapshot) → {CellGridSimulation}
Restores cell grid state from a snapshot.
| Name | Type | Description |
|---|---|---|
snapshot | object | Saved snapshot object. |
- Source
this instance.
- Type:
- CellGridSimulation
setCell(x, y, data) → {object|null}
Sets or updates cell data safely. Safely ignores out-of-bounds coordinates.
| Name | Type | Description |
|---|---|---|
x | number | Column index. |
y | number | Row index. |
data | string | | Material ID or partial cell properties. |
- Source
The updated cell object or null if out of bounds.
- Type:
- object |
null
setMaterial(x, y, materialId, stateopt) → {object|null}
Convenience helper to set material ID and optional state on a cell.
| Name | Type | Attributes | Description |
|---|---|---|---|
x | number | Column index. | |
y | number | Row index. | |
materialId | string | Material ID. | |
state | string | <optional> | Material interaction state. |
- Source
- Type:
- object |
null
snapshot() → {object}
Serializes the cell grid state for save games.
- Source
Serializable snapshot object.
- Type:
- object
step(dtopt, optionsopt) → {object}
Advances the simulation by one step (dt). Handles:
- Local fire spread & heat transfer to 4-cardinal neighbors.
- Burning progression and burnout transition to charred.
- Water flow & extinguishing (extinguishing takes precedence).
- Out-of-bounds boundary safety.
- Update budget capping via maxCellUpdatesPerTick.
- Typed event dispatching.
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
dt | number | <optional> | 1 | Time step delta. |
options | object | <optional> | {} | Override step options. |
- Source
Step summary statistics.
- Type:
- object