Changed min token and note scale to 0.5 and fix grid snapping for non integer values

This commit is contained in:
Mitchell McCaffrey
2020-11-06 15:48:35 +11:00
parent 088466ea07
commit cb2c432d0a
5 changed files with 72 additions and 66 deletions

View File

@@ -6,7 +6,7 @@ import useImage from "use-image";
import useDataSource from "../../helpers/useDataSource";
import useDebounce from "../../helpers/useDebounce";
import usePrevious from "../../helpers/usePrevious";
import * as Vector2 from "../../helpers/vector2";
import { snapNodeToMap } from "../../helpers/map";
import AuthContext from "../../contexts/AuthContext";
import MapInteractionContext from "../../contexts/MapInteractionContext";
@@ -82,35 +82,7 @@ function MapToken({
const tokenGroup = event.target;
// Snap to corners of grid
if (map.snapToGrid) {
const offset = Vector2.multiply(map.grid.inset.topLeft, {
x: mapWidth,
y: mapHeight,
});
const position = {
x: tokenGroup.x() + tokenGroup.width() / 2,
y: tokenGroup.y() + tokenGroup.height() / 2,
};
const gridSize = {
x:
(mapWidth *
(map.grid.inset.bottomRight.x - map.grid.inset.topLeft.x)) /
map.grid.size.x,
y:
(mapHeight *
(map.grid.inset.bottomRight.y - map.grid.inset.topLeft.y)) /
map.grid.size.y,
};
// Transform into offset space, round, then transform back
const gridSnap = Vector2.add(
Vector2.roundTo(Vector2.subtract(position, offset), gridSize),
offset
);
const gridDistance = Vector2.length(Vector2.subtract(gridSnap, position));
const minGrid = Vector2.min(gridSize);
if (gridDistance < minGrid * snappingThreshold) {
tokenGroup.x(gridSnap.x - tokenGroup.width() / 2);
tokenGroup.y(gridSnap.y - tokenGroup.height() / 2);
}
snapNodeToMap(map, mapWidth, mapHeight, tokenGroup, snappingThreshold);
}
}