Separated fog snapping and drawing snapping, added square edge snapping

This commit is contained in:
Mitchell McCaffrey
2021-01-22 15:00:31 +11:00
parent 3abf9c62fa
commit 5219815a1f
5 changed files with 160 additions and 126 deletions
+13 -16
View File
@@ -7,13 +7,12 @@ import MapStageContext from "../../contexts/MapStageContext";
import { compare as comparePoints } from "../../helpers/vector2";
import {
getBrushPositionForTool,
getBrushPosition,
getDefaultShapeData,
getUpdatedShapeData,
simplifyPoints,
getStrokeWidth,
} from "../../helpers/drawing";
import { getRelativePointerPositionNormalized } from "../../helpers/konva";
import colors from "../../helpers/colors";
@@ -49,20 +48,13 @@ function MapDrawing({
}
const mapStage = mapStageRef.current;
function getBrushPosition() {
const mapImage = mapStage.findOne("#mapImage");
return getBrushPositionForTool(
map,
getRelativePointerPositionNormalized(mapImage),
map.snapToGrid && isShape,
false,
gridSize,
shapes
);
}
function handleBrushDown() {
const brushPosition = getBrushPosition();
const brushPosition = getBrushPosition(
map,
mapStage,
map.snapToGrid && isShape,
gridSize
);
const commonShapeData = {
color: toolSettings.color,
blend: toolSettings.useBlending,
@@ -89,7 +81,12 @@ function MapDrawing({
}
function handleBrushMove() {
const brushPosition = getBrushPosition();
const brushPosition = getBrushPosition(
map,
mapStage,
map.snapToGrid && isShape,
gridSize
);
if (isBrushDown && drawingShape) {
if (isBrush) {
setDrawingShape((prevShape) => {