import React from "react";
import { Line, Group, RegularPolygon } from "react-konva";
import { getCellLocation } from "../helpers/grid";
import Vector2 from "../helpers/Vector2";
import { useGrid } from "../contexts/GridContext";
function Grid({ strokeWidth, stroke }) {
const {
grid,
gridStrokeWidth,
gridPixelSize,
gridOffset,
gridCellPixelSize,
} = useGrid();
if (!grid?.size.x || !grid?.size.y) {
return null;
}
const negativeGridOffset = Vector2.multiply(gridOffset, -1);
const finalStrokeWidth = gridStrokeWidth * strokeWidth;
const shapes = [];
if (grid.type === "square") {
for (let x = 1; x < grid.size.x; x++) {
shapes.push(
);
}
for (let y = 1; y < grid.size.y; y++) {
shapes.push(
);
}
} else if (grid.type === "hexVertical" || grid.type === "hexHorizontal") {
// End at grid size + 1 to overshoot the bounds of the grid to ensure all lines are drawn
for (let x = 0; x < grid.size.x + 1; x++) {
for (let y = 0; y < grid.size.y + 1; y++) {
const cellLocation = getCellLocation(grid, x, y, gridCellPixelSize);
shapes.push(
{/* Offset the hex tile to align to top left of grid */}
);
}
}
}
return (
{
context.rect(
gridOffset.x - finalStrokeWidth / 2,
gridOffset.y - finalStrokeWidth / 2,
gridPixelSize.width + finalStrokeWidth,
gridPixelSize.height + finalStrokeWidth
);
}}
>
{shapes}
);
}
Grid.defaultProps = {
strokeWidth: 0.1,
stroke: "white",
};
export default Grid;