From f10be469a29beab597b2476128a656d3c4608927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Wed, 9 Mar 2022 20:57:18 +0100 Subject: [PATCH] Fix remainging errors from merge --- js/pathfinding.js | 4 ++-- js/util.js | 22 +++++++++++++--------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/js/pathfinding.js b/js/pathfinding.js index 044eee3..14bbb9f 100644 --- a/js/pathfinding.js +++ b/js/pathfinding.js @@ -2,7 +2,7 @@ import {getCenterFromGridPositionObj, getGridPositionFromPixelsObj, getPixelsFro import {moveWithoutAnimation, togglePathfinding} from "./keybindings.js"; import {debugGraphics} from "./main.js"; import {settingsKey} from "./settings.js"; -import {buildSnapPointTokenData, getSnapPointForTokenDataObj, isModuleActive, iterPairs} from "./util.js"; +import {buildSnapPointTokenData, getSnapPointForTokenDataObj, getTokenShape, getTokenShapeForTokenData, isModuleActive, iterPairs} from "./util.js"; import * as GridlessPathfinding from "../wasm/gridless_pathfinding.js"; import {PriorityQueueSet, ProcessOnceQueue} from "./data_structures.js"; @@ -322,7 +322,7 @@ function getNode(pos, cacheLayer, initialize = true) { let edgeCost; if (window.terrainRuler) { let ray = new Ray(getCenterFromGridPositionObj(neighborPos), getCenterFromGridPositionObj(pos)); - let measuredDistance = terrainRuler.measureDistances([{ray}], {costFunction: buildCostFunction(token, getTokenShape(token))})[0]; + let measuredDistance = terrainRuler.measureDistances([{ray}], {costFunction: buildCostFunction(cacheLayer.tokenData, getTokenShapeForTokenData(cacheLayer.tokenData))})[0]; edgeCost = Math.round(measuredDistance / canvas.dimensions.distance); if (ray.terrainRulerFinalState?.noDiagonals === 1) { edgeCost = 1.5; diff --git a/js/util.js b/js/util.js index 48f48d4..ff46aea 100644 --- a/js/util.js +++ b/js/util.js @@ -167,15 +167,19 @@ export function getAreaFromPositionAndShape(position, shape) { } export function getTokenShape(token) { - if (token.scene.data.gridType === CONST.GRID_TYPES.GRIDLESS) { + return getTokenShapeForTokenData(buildSnapPointTokenData(token), token.scene); +} + +export function getTokenShapeForTokenData(tokenData, scene=canvas.scene) { + if (scene.data.gridType === CONST.GRID_TYPES.GRIDLESS) { return [{x: 0, y: 0}] } - else if (token.scene.data.gridType === CONST.GRID_TYPES.SQUARE) { - const topOffset = -Math.floor(token.data.height / 2) - const leftOffset = -Math.floor(token.data.width / 2) + else if (scene.data.gridType === CONST.GRID_TYPES.SQUARE) { + const topOffset = -Math.floor(tokenData.height / 2) + const leftOffset = -Math.floor(tokenData.width / 2) const shape = [] - for (let y = 0;y < token.data.height;y++) { - for (let x = 0;x < token.data.width;x++) { + for (let y = 0;y < tokenData.height;y++) { + for (let x = 0;x < tokenData.width;x++) { shape.push({x: x + leftOffset, y: y + topOffset}) } } @@ -183,8 +187,8 @@ export function getTokenShape(token) { } else { // Hex grids - if (game.modules.get("hex-size-support")?.active && CONFIG.hexSizeSupport.getAltSnappingFlag(token)) { - const borderSize = token.data.flags["hex-size-support"].borderSize; + if (game.modules.get("hex-size-support")?.active && tokenData.hexSizeSupport.altSnappingFlag) { + const borderSize = tokenData.hexSizeSupport.borderSize; let shape = [{x: 0, y: 0}]; if (borderSize >= 2) shape = shape.concat([{x: 0, y: -1}, {x: -1, y: -1}]); @@ -193,7 +197,7 @@ export function getTokenShape(token) { if (borderSize >= 4) shape = shape.concat([{x: -2, y: -1}, {x: 1, y: -1}, {x: -1, y: -2}, {x: 0, y: -2}, {x: 1, y: -2}]) - if (Boolean(CONFIG.hexSizeSupport.getAltOrientationFlag(token)) !== canvas.grid.grid.options.columns) + if (Boolean(tokenData.hexSizeSupport.altOrientationFlag) !== canvas.grid.grid.options.columns) shape.forEach(space => space.y *= -1); if (canvas.grid.grid.options.columns) shape = shape.map(space => {return {x: space.y, y: space.x}});