Move grid snapping to hook and added math for hex snapping

This commit is contained in:
Mitchell McCaffrey
2021-02-06 19:29:24 +11:00
parent f20173de35
commit fbea8bd7a7
7 changed files with 293 additions and 151 deletions
+7 -7
View File
@@ -19,14 +19,14 @@ import { getGridPixelSize, getCellPixelSize, Grid } from "../helpers/grid";
*/
const defaultValue = {
grid: {
size: { x: 0, y: 0 },
inset: { topLeft: { x: 0, y: 0 }, bottomRight: { x: 1, y: 1 } },
size: new Vector2(0, 0),
inset: { topLeft: new Vector2(0, 0), bottomRight: new Vector2(1, 1) },
type: "square",
},
gridPixelSize: new Size(0, 0),
gridCellPixelSize: new Size(0, 0, 0),
gridCellNormalizedSize: new Size(0, 0, 0),
gridOffset: { x: 0, y: 0 },
gridOffset: new Vector2(0, 0),
gridStrokeWidth: 0,
};
@@ -53,10 +53,10 @@ export function GridProvider({ grid, width, height, children }) {
gridCellPixelSize.width / gridPixelSize.width,
gridCellPixelSize.height / gridPixelSize.height
);
const gridOffset = {
x: grid.inset.topLeft.x * width * -1,
y: grid.inset.topLeft.y * height * -1,
};
const gridOffset = Vector2.multiply(grid.inset.topLeft, {
x: width,
y: height,
});
const gridStrokeWidth =
(gridCellPixelSize.width < gridCellPixelSize.height
? gridCellPixelSize.width