Hex support
This commit is contained in:
+3
-12
@@ -8,7 +8,7 @@ let cachedNodes = undefined;
|
|||||||
let use5105 = false;
|
let use5105 = false;
|
||||||
|
|
||||||
export function isPathfindingEnabled() {
|
export function isPathfindingEnabled() {
|
||||||
if (canvas.grid.type !== CONST.GRID_TYPES.SQUARE)
|
if (canvas.grid.type === CONST.GRID_TYPES.GRIDLESS)
|
||||||
return false;
|
return false;
|
||||||
if (!game.settings.get(settingsKey, "allowPathfinding"))
|
if (!game.settings.get(settingsKey, "allowPathfinding"))
|
||||||
return false;
|
return false;
|
||||||
@@ -53,12 +53,12 @@ function getNode(pos, initialize=true) {
|
|||||||
const node = cachedNodes[pos.layer][pos.y][pos.x];
|
const node = cachedNodes[pos.layer][pos.y][pos.x];
|
||||||
if (initialize && !node.edges) {
|
if (initialize && !node.edges) {
|
||||||
node.edges = [];
|
node.edges = [];
|
||||||
for (const neighborPos of neighbors(pos)) {
|
for (const neighborPos of canvas.grid.grid.getNeighbors(pos.y, pos.x).map(([y, x]) => {return {x, y};})) {
|
||||||
if (neighborPos.x < 0 || neighborPos.y < 0)
|
if (neighborPos.x < 0 || neighborPos.y < 0)
|
||||||
continue;
|
continue;
|
||||||
// TODO Work with pixels instead of grid locations
|
// TODO Work with pixels instead of grid locations
|
||||||
if (!canvas.walls.checkCollision(new Ray(getCenterFromGridPositionObj(pos), getCenterFromGridPositionObj(neighborPos)))) {
|
if (!canvas.walls.checkCollision(new Ray(getCenterFromGridPositionObj(pos), getCenterFromGridPositionObj(neighborPos)))) {
|
||||||
const isDiagonal = node.x !== neighborPos.x && node.y !== neighborPos.y;
|
const isDiagonal = node.x !== neighborPos.x && node.y !== neighborPos.y && canvas.grid.type === CONST.GRID_TYPES.SQUARE;
|
||||||
let targetLayer = pos.layer;
|
let targetLayer = pos.layer;
|
||||||
if (use5105 && isDiagonal)
|
if (use5105 && isDiagonal)
|
||||||
targetLayer = 1 - targetLayer;
|
targetLayer = 1 - targetLayer;
|
||||||
@@ -77,15 +77,6 @@ function getNode(pos, initialize=true) {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
function* neighbors(pos) {
|
|
||||||
for (let y = -1;y < 2;y++) {
|
|
||||||
for (let x = -1;x < 2;x++) {
|
|
||||||
if (x != 0 || y != 0)
|
|
||||||
yield {x: pos.x + x, y: pos.y + y};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculatePath(from, to, previousWaypoints) {
|
function calculatePath(from, to, previousWaypoints) {
|
||||||
if (game.system.id === "pf2e")
|
if (game.system.id === "pf2e")
|
||||||
use5105 = true;
|
use5105 = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user