Added a grid snapping sensitivity accessibility option

This commit is contained in:
Mitchell McCaffrey
2021-02-07 16:42:29 +11:00
parent 905b43a64b
commit 76533852cd
5 changed files with 32 additions and 10 deletions
+10 -3
View File
@@ -9,13 +9,20 @@ import {
getCellCorners,
} from "../helpers/grid";
import useSetting from "./useSetting";
import { useGrid } from "../contexts/GridContext";
/**
* Returns a function that when called will snap a node to the current grid
* @param {number} snappingThreshold 1 = Always snap, 0 = never snap
* @param {number=} snappingSensitivity 1 = Always snap, 0 = never snap if undefined the default user setting will be used
*/
function useGridSnapping(snappingThreshold) {
function useGridSnapping(snappingSensitivity) {
const [defaultSnappingSensitivity] = useSetting(
"map.gridSnappingSensitivity"
);
snappingSensitivity = snappingSensitivity || defaultSnappingSensitivity;
const { grid, gridOffset, gridCellPixelSize } = useGrid();
/**
@@ -57,7 +64,7 @@ function useGridSnapping(snappingThreshold) {
const distanceToSnapPoint = Vector2.distance(offsetPosition, snapPoint);
if (
distanceToSnapPoint <
Vector2.min(gridCellPixelSize) * snappingThreshold
Vector2.min(gridCellPixelSize) * snappingSensitivity
) {
// Reverse grid offset
let offsetSnapPoint = Vector2.add(snapPoint, gridOffset);