Lua library with class for handling 2d grids like in tile-based games.
Creates new grid with chosen dimensions.
Creates new grid copying all elements from src
.
Apply f
function to all cells in the selected rectangle. Changes grid inplace.
Put cells from src
in the rectangle (srcx,srcy,srcw,srch)
into the grid with offset (destx,desty)
.
Crop result if out of bounds. Changes grid inplace.
Create a slice from the original grid. Original grid is not changed.
Returns grid's width.
Returns grid's height.
Clones current grid.
Returns the grid with cells flipped horizontally.
123.. ..321
..4.. -> ..4..
..5.. ..5..
Returns the grid with cells flipped vertically.
123.. ..3..
..4.. -> ..4..
..5.. 125..
Returns the grid with cells rotated clockwise on 90 degrees.
123.. ..1
..4.. -> ..2
..5.. 543
...
...
Returns the grid with cells rotated counter clockwise on 90 degrees.
123.. ...
..4.. -> ...
..5.. 345
2..
1..
Returns the grid with cells rotated on 180 degrees.
123.. ..5..
..4.. -> ..4..
..5.. ..321
Transposes the grid copy, i.e. swaps rows and columns.
123.. ...
..4.. -> ...
..5.. 543
..2
..1
Encodes grid into string. Encoder can be either mapping table or encoding function.
Creates grid from string str
using decoder
. Decoder can be either mapping table or encoding function.