Constructor
new Grid()
- Description:
- Creates a new two-dimensional grid.
- Source:
Example
const grid = new Grid();
grid.set(position, data);
grid.traverse(aabb, handler);
Methods
clear() → {this}
- Description:
- Clears the grid.
- Source:
Returns:
- Type
- this
clone() → {Grid.<TypeGeneric>}
- Description:
- Clones the grid.
- Source:
Returns:
- Type
- Grid.<TypeGeneric>
delete($position) → {this}
- Description:
- Deletes the data from the given position.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$position |
Vector2 | The position to delete the data from. |
Returns:
- Type
- this
get($position) → {TypeGeneric}
- Description:
- Gets the data from the given position.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$position |
Vector2 | The position to get the data from. |
Returns:
- Type
- TypeGeneric
has($position) → {boolean}
- Description:
- Checks if the given position stores any data.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$position |
Vector2 | The given position to check. |
Returns:
- Type
- boolean
iterate($handler) → {this}
- Description:
- Iterates through the grid applying the given handler.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$handler |
TypeHandlerTraverse | The handler to apply to each cell in the sector. |
Returns:
- Type
- this
map($handler) → {Grid.<TypeGenericMapped>}
- Description:
- Maps this grid data stored to other data (a new grid is created).
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$handler |
TypeHandlerMap.<TypeGenericMapped> | The handler to execute when mapping this grid. |
Returns:
- Type
- Grid.<TypeGenericMapped>
set($position, $data) → {this}
- Description:
- Sets the given data to the given position.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$position |
Vector2 | The position to set the data to (with integer values). |
$data |
TypeGeneric | The data to set. |
Returns:
- Type
- this
traverse($aabb, $handler) → {this}
- Description:
- Traverses the given sector applying the given handler.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$aabb |
AABB | The sector to traverse (with integer boundaries). |
$handler |
TypeHandlerTraverse | The handler to apply to each cell in the sector. |
Returns:
- Type
- this
unwatch($handler, $position) → {this}
- Description:
- Removes a watcher of the given cell.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$handler |
TypeWatcherCell | The cell changing handler to detach. |
$position |
Vector2 | The position of the cell to unwatch. |
Returns:
- Type
- this
unwatchAll() → {this}
- Description:
- Removes all watchers of the cells.
- Source:
Returns:
- Type
- this
watch($handler, $position) → {this}
- Description:
- Adds a watcher for the given cell.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$handler |
TypeWatcherCell | The cell changing handler to attach. |
$position |
Vector2 | The position of the cell to watch. |
Returns:
- Type
- this
(static) from($grid) → {Grid.<TypeGeneric>}
- Description:
- Creates a new grid from the given grid.
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$grid |
Grid.<TypeGeneric> | The given grid. |
Returns:
- Type
- Grid.<TypeGeneric>
Type Definitions
(protected) TypeHandlerMap($parameters) → {TypeGenericMapped}
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$parameters |
object | The given parameters. |
$parameters.$data |
TypeGeneric | The data of the cell. |
$parameters.$grid |
Grid.<TypeGenericMapped> | The reference grid. |
$parameters.$position |
Vector2 | The position of the cell. |
Returns:
- Type
- TypeGenericMapped
(protected) TypeHandlerTraverse($parameters) → {void}
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$parameters |
object | The given parameters. |
$parameters.$data |
TypeGeneric | The data of the cell. |
$parameters.$grid |
Grid.<TypeGeneric> | The reference grid. |
$parameters.$position |
Vector2 | The position of the cell. |
$parameters.$terminate |
TypeHandlerTraverseTerminate | Terminates the traversal of the grid. |
Returns:
- Type
- void
(protected) TypeHandlerTraverseTerminate() → {void}
- Source:
Returns:
- Type
- void
(protected) TypeWatcherCell($parameters) → {void}
- Source:
Parameters:
| Name | Type | Description |
|---|---|---|
$parameters |
object | The given parameters. |
$parameters.$current |
TypeGeneric | The current data of the cell. |
$parameters.$grid |
Grid.<TypeGeneric> | The reference grid. |
$parameters.$position |
Vector2 | The position of the cell. |
$parameters.$previous |
TypeGeneric | The previous data of the cell. |
Returns:
- Type
- void