WrappingGrid

WrappingGrid

And "endless" wrapping grid for example with a size 16x16 grid, accessing x:17 y:3 will reference x:1 y:3

Constructor

new WrappingGrid()

Source:

Extends

Methods

coords(i) → {object}

Source:
Inherited From:

get the two-dimensional coordinates of the cell at this index

Parameters:
Name Type Description
i number
Returns:

the coordinates

Type
object

delete(x, y, prop)

Source:
Inherited From:

deletes the contents of an object key for the cell at x,y

Example
grid.delete(4,7,"key");
Parameters:
Name Type Description
x number
y number
prop string

property key

directNeighbours(x, y, propopt) → {Array}

Source:
Inherited From:

get the direct neighbours cells of a cell, cells outside the grid are the default

Parameters:
Name Type Attributes Default Description
x number
y number
prop string <optional>
null
Returns:
Type
Array

each(cb)

Source:
Inherited From:

loop over each cell (call cb for each cell)

Parameters:
Name Type Description
cb function

loop callback

floodfill(begin, cellCallback, neighbourCallback) → {Array}

Source:
Inherited From:

Start a flood fill from the given begin cell

Parameters:
Name Type Default Description
begin Object

x and y

cellCallback function

return true if the neighbours of the cell should be checked

neighbourCallback function null

return true if the neighbour should be checked (is the same as cellCallback by default)

Returns:

flooded cells

Type
Array

get(x, y, prop) → {*}

Source:
Inherited From:

get the contents of the cell at x,y if the coordinates are outside the grid, the default element is returned

Parameters:
Name Type Default Description
x number
y number
prop string null
Returns:

the cell content

Type
*

getDefault() → {*}

Source:
Inherited From:
See:

internal function used to fill each cell initially, each cell value is a clone, not a reference

Returns:
Type
*

index(x, y) → {number}

Source:
Overrides:

get the one-dimensional index of the cell -1 if outside the grid

Parameters:
Name Type Description
x number
y number
Returns:
Type
number

map(cb)

Source:
Inherited From:

loop over each cell (call cb for each cell) and replace it the new array is replaced after the callback has been called for each cell

Parameters:
Name Type Description
cb function

loop callback

neighbours(x, y, propopt) → {Array}

Source:
Inherited From:

get the neighbours cells of a cell

Parameters:
Name Type Attributes Default Description
x number
y number
prop string <optional>
null
Returns:
Type
Array

serialize() → {object}

Source:
Inherited From:

Serialize the grid into a compact object structure requires each cell to be an object the return value is ready to be send over network or further serialized with JSON.stringify

Returns:
Type
object

set(x, y, a, b)

Source:
Inherited From:

set the contents of the cell at x,y a fourth parameter can be passed to set the value of an object key instead

Example
grid.set(4,7,true);
grid.set(4,7,"key", true);
Parameters:
Name Type Description
x number
y number
a string | *

value

b *

slice(x, y, w, h) → {Grid}

Source:
Inherited From:

Get a copy of a part of the grid

Parameters:
Name Type Description
x Number

offset on the x-axis

y Number

offset on the y-axis

w Number

width of the slice

h Number

height of the slice

Returns:
Type
Grid

strictDirectNeighbours(x, y, propopt) → {Array}

Source:
Inherited From:

get the direct neighbours cells of a cell, ignore those outside the grid

Parameters:
Name Type Attributes Default Description
x number
y number
prop string <optional>
null
Returns:
Type
Array

unserialize(data)

Source:
Inherited From:

unserialize a data structure generated by serialize

Parameters:
Name Type Description
data object

wrapCoords(v)

Source:

Wrap the coordinates of a vector in the grid

Parameters:
Name Type Description
v Vector