From f77990420a224034eeebbb1e9a0ab18e90d128b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Tue, 8 Mar 2022 20:16:53 +0100 Subject: [PATCH] Replace `getSnapPointForMeasuredTemplate` with foundry native function (fixes #181) --- js/util.js | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/js/util.js b/js/util.js index ebcb2a0..eb6e3cb 100644 --- a/js/util.js +++ b/js/util.js @@ -90,35 +90,12 @@ export function getSnapPointForTokenObj(pos, token) { return getSnapPointForToken(pos.x, pos.y, token); } -export function getSnapPointForMeasuredTemplate(x, y) { - if (canvas.grid.type === CONST.GRID_TYPES.GRIDLESS) { - return new PIXI.Point(x, y); - } - let subgridWidth, subgridHeight; - if (canvas.grid.type === CONST.GRID_TYPES.SQUARE) { - subgridWidth = subgridHeight = canvas.dimensions.size / 2; - } - else { - if (canvas.grid.grid.columns) { - subgridWidth = canvas.grid.w / 4; - subgridHeight = canvas.grid.h / 2; - } - else { - subgridWidth = canvas.grid.w / 2; - subgridHeight = canvas.grid.h / 4; - } - } - const snappedX = Math.round(x / subgridWidth) * subgridWidth; - const snappedY = Math.round(y / subgridHeight) * subgridHeight; - return new PIXI.Point(snappedX, snappedY); -} - export function getSnapPointForEntity(x, y, entity) { const isToken = entity instanceof Token; if (isToken) return getSnapPointForToken(x, y, entity); else - return getSnapPointForMeasuredTemplate(x, y); + return canvas.grid.grid.getSnappedPosition(x, y, canvas.templates.gridPosition); } export function highlightTokenShape(position, shape, color, alpha) {