Reformat with prettier
This commit is contained in:
+72
-76
@@ -1,10 +1,10 @@
|
||||
import {getPixelsFromGridPosition} from "./foundry_fixes.js"
|
||||
import {getPixelsFromGridPosition} from "./foundry_fixes.js";
|
||||
import {findVertexSnapPoint} from "./hex_support.js";
|
||||
import {disableSnap} from "./keybindings.js";
|
||||
|
||||
export function* zip(it1, it2) {
|
||||
for (let i = 0;i < Math.min(it1.length, it2.length);i++) {
|
||||
yield [it1[i], it2[i]]
|
||||
for (let i = 0; i < Math.min(it1.length, it2.length); i++) {
|
||||
yield [it1[i], it2[i]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ export function* enumeratedZip(it1, it2) {
|
||||
}
|
||||
|
||||
export function* iterPairs(l) {
|
||||
for (let i = 1;i < l.length;i++) {
|
||||
for (let i = 1; i < l.length; i++) {
|
||||
yield [l[i - 1], l[i]];
|
||||
}
|
||||
}
|
||||
@@ -29,13 +29,14 @@ export function sum(arr) {
|
||||
export function buildSnapPointTokenData(token) {
|
||||
const tokenData = {
|
||||
width: token.data.width,
|
||||
height: token.data.height
|
||||
height: token.data.height,
|
||||
};
|
||||
|
||||
if (isModuleActive("hex-size-support")) {
|
||||
tokenData.hexSizeSupport = {};
|
||||
tokenData.hexSizeSupport.altSnappingFlag = CONFIG.hexSizeSupport.getAltSnappingFlag(token);
|
||||
tokenData.hexSizeSupport.altOrientationFlag = CONFIG.hexSizeSupport.getAltOrientationFlag(token);
|
||||
tokenData.hexSizeSupport.altOrientationFlag =
|
||||
CONFIG.hexSizeSupport.getAltOrientationFlag(token);
|
||||
tokenData.hexSizeSupport.borderSize = token.document.getFlag("hex-size-support", "borderSize");
|
||||
}
|
||||
|
||||
@@ -58,27 +59,21 @@ function getSnapPointForTokenData(x, y, tokenData) {
|
||||
if (tokenData.hexSizeSupport?.altSnappingFlag) {
|
||||
if (tokenData.hexSizeSupport.borderSize % 2 === 0) {
|
||||
const snapPoint = findVertexSnapPoint(x, y, tokenData.hexSizeSupport.altOrientationFlag);
|
||||
return new PIXI.Point(snapPoint.x, snapPoint.y)
|
||||
return new PIXI.Point(snapPoint.x, snapPoint.y);
|
||||
} else {
|
||||
return new PIXI.Point(...canvas.grid.getCenter(x, y));
|
||||
}
|
||||
else {
|
||||
return new PIXI.Point(...canvas.grid.getCenter(x, y))
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return new PIXI.Point(...canvas.grid.getCenter(x, y));
|
||||
}
|
||||
}
|
||||
|
||||
const [topLeftX, topLeftY] = canvas.grid.getTopLeft(x, y);
|
||||
let cellX, cellY;
|
||||
if (tokenData.width % 2 === 0)
|
||||
cellX = x - canvas.grid.h / 2;
|
||||
else
|
||||
cellX = x;
|
||||
if (tokenData.height % 2 === 0)
|
||||
cellY = y - canvas.grid.h / 2;
|
||||
else
|
||||
cellY = y;
|
||||
if (tokenData.width % 2 === 0) cellX = x - canvas.grid.h / 2;
|
||||
else cellX = x;
|
||||
if (tokenData.height % 2 === 0) cellY = y - canvas.grid.h / 2;
|
||||
else cellY = y;
|
||||
const [centerX, centerY] = canvas.grid.getCenter(cellX, cellY);
|
||||
let snapX, snapY;
|
||||
// Tiny tokens can snap to the cells corners
|
||||
@@ -101,11 +96,9 @@ function getSnapPointForTokenData(x, y, tokenData) {
|
||||
const subGridHeight = Math.floor(canvas.grid.h / 2);
|
||||
const subGridPosY = Math.floor(offsetY / subGridHeight);
|
||||
snapY = topLeftY + (subGridPosY + 0.5) * subGridHeight;
|
||||
}
|
||||
else if (Math.round(tokenData.height) % 2 === 1 || tokenData.height < 1) {
|
||||
} else if (Math.round(tokenData.height) % 2 === 1 || tokenData.height < 1) {
|
||||
snapY = centerY;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
snapY = centerY + canvas.grid.h / 2;
|
||||
}
|
||||
return new PIXI.Point(snapX, snapY);
|
||||
@@ -124,16 +117,13 @@ export function getSnapPointForMeasuredTemplate(x, y) {
|
||||
|
||||
export function getSnapPointForEntity(x, y, entity) {
|
||||
const isToken = entity instanceof Token;
|
||||
if (isToken)
|
||||
return getSnapPointForToken(x, y, entity);
|
||||
else
|
||||
return getSnapPointForMeasuredTemplate(x, y);
|
||||
if (isToken) return getSnapPointForToken(x, y, entity);
|
||||
else return getSnapPointForMeasuredTemplate(x, y);
|
||||
}
|
||||
|
||||
export function highlightTokenShape(position, shape, color, alpha) {
|
||||
const layer = canvas.grid.highlightLayers[this.name];
|
||||
if ( !layer )
|
||||
return false;
|
||||
if (!layer) return false;
|
||||
const area = getAreaFromPositionAndShape(position, shape);
|
||||
for (const space of area) {
|
||||
const [x, y] = getPixelsFromGridPosition(space.x, space.y);
|
||||
@@ -147,22 +137,19 @@ export function getAreaFromPositionAndShape(position, shape) {
|
||||
let y = position.y + space.y;
|
||||
if (canvas.grid.isHex) {
|
||||
let shiftedRow;
|
||||
if (canvas.grid.grid.options.even)
|
||||
shiftedRow = 1
|
||||
else
|
||||
shiftedRow = 0
|
||||
if (canvas.grid.grid.options.even) shiftedRow = 1;
|
||||
else shiftedRow = 0;
|
||||
if (canvas.grid.grid.options.columns) {
|
||||
if (space.x % 2 !== 0 && position.x % 2 !== shiftedRow) {
|
||||
y += 1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (space.y % 2 !== 0 && position.y % 2 !== shiftedRow) {
|
||||
x += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return {x, y}
|
||||
return {x, y};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -170,40 +157,53 @@ export function getTokenShape(token) {
|
||||
return getTokenShapeForTokenData(buildSnapPointTokenData(token), token.scene);
|
||||
}
|
||||
|
||||
export function getTokenShapeForTokenData(tokenData, scene=canvas.scene) {
|
||||
export function getTokenShapeForTokenData(tokenData, scene = canvas.scene) {
|
||||
if (scene.data.gridType === CONST.GRID_TYPES.GRIDLESS) {
|
||||
return [{x: 0, y: 0}]
|
||||
}
|
||||
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 < tokenData.height;y++) {
|
||||
for (let x = 0;x < tokenData.width;x++) {
|
||||
shape.push({x: x + leftOffset, y: y + topOffset})
|
||||
return [{x: 0, y: 0}];
|
||||
} 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 < tokenData.height; y++) {
|
||||
for (let x = 0; x < tokenData.width; x++) {
|
||||
shape.push({x: x + leftOffset, y: y + topOffset});
|
||||
}
|
||||
}
|
||||
return shape
|
||||
}
|
||||
else {
|
||||
return shape;
|
||||
} else {
|
||||
// Hex grids
|
||||
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}]);
|
||||
shape = shape.concat([
|
||||
{x: 0, y: -1},
|
||||
{x: -1, y: -1},
|
||||
]);
|
||||
if (borderSize >= 3)
|
||||
shape = shape.concat([{x: 0, y: 1}, {x: -1, y: 1}, {x: -1, y: 0}, {x: 1, y: 0}]);
|
||||
shape = shape.concat([
|
||||
{x: 0, y: 1},
|
||||
{x: -1, y: 1},
|
||||
{x: -1, y: 0},
|
||||
{x: 1, y: 0},
|
||||
]);
|
||||
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}])
|
||||
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(tokenData.hexSizeSupport.altOrientationFlag) !== canvas.grid.grid.options.columns)
|
||||
shape.forEach(space => space.y *= -1);
|
||||
shape.forEach(space => (space.y *= -1));
|
||||
if (canvas.grid.grid.options.columns)
|
||||
shape = shape.map(space => {return {x: space.y, y: space.x}});
|
||||
shape = shape.map(space => {
|
||||
return {x: space.y, y: space.x};
|
||||
});
|
||||
return shape;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
return [{x: 0, y: 0}];
|
||||
}
|
||||
}
|
||||
@@ -213,11 +213,10 @@ export function getTokenSize(token) {
|
||||
let w, h;
|
||||
const hexSizeSupportBorderSize = token.data.flags["hex-size-support"]?.borderSize;
|
||||
if (hexSizeSupportBorderSize > 0) {
|
||||
w = h = hexSizeSupportBorderSize
|
||||
}
|
||||
else {
|
||||
w = token.data.width
|
||||
h = token.data.height
|
||||
w = h = hexSizeSupportBorderSize;
|
||||
} else {
|
||||
w = token.data.width;
|
||||
h = token.data.height;
|
||||
}
|
||||
return {w, h};
|
||||
}
|
||||
@@ -226,7 +225,7 @@ export function getTokenSize(token) {
|
||||
// This function applies an offset to to the waypoints that will move the ruler from the edge to the center of the cell
|
||||
export function applyTokenSizeOffset(waypoints, token) {
|
||||
if (canvas.grid.type === CONST.GRID_TYPES.GRIDLESS) {
|
||||
return waypoints
|
||||
return waypoints;
|
||||
}
|
||||
|
||||
const tokenSize = getTokenSize(token);
|
||||
@@ -237,21 +236,17 @@ export function applyTokenSizeOffset(waypoints, token) {
|
||||
if (canvas.grid.grid.options.columns) {
|
||||
if (tokenSize.w % 2 === 0) {
|
||||
waypointOffset.x = canvas.grid.w / 2;
|
||||
if (!isAltOrientation)
|
||||
waypointOffset.x *= -1;
|
||||
if (!isAltOrientation) waypointOffset.x *= -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (tokenSize.h % 2 === 0) {
|
||||
waypointOffset.y = canvas.grid.h / 2;
|
||||
if (isAltOrientation)
|
||||
waypointOffset.y *= -1;
|
||||
if (isAltOrientation) waypointOffset.y *= -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
// If hex size support isn't active leave the waypoints like they are
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
if (tokenSize.w % 2 === 0) {
|
||||
waypointOffset.x = canvas.grid.w / 2;
|
||||
}
|
||||
@@ -260,7 +255,7 @@ export function applyTokenSizeOffset(waypoints, token) {
|
||||
}
|
||||
}
|
||||
|
||||
return waypoints.map(w => new PIXI.Point(w.x + waypointOffset.x, w.y + waypointOffset.y))
|
||||
return waypoints.map(w => new PIXI.Point(w.x + waypointOffset.x, w.y + waypointOffset.y));
|
||||
}
|
||||
|
||||
export function setSnapParameterOnOptions(sourceObject, options) {
|
||||
@@ -269,8 +264,7 @@ export function setSnapParameterOnOptions(sourceObject, options) {
|
||||
options.snapOverrideActive = true;
|
||||
options.snap = sourceObject.snapOverride.snap;
|
||||
sourceObject.snapOverride = undefined; // remove it to prevent any lingering data issues
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
options.snap = !disableSnap;
|
||||
}
|
||||
}
|
||||
@@ -280,7 +274,9 @@ export function isClose(a, b, delta) {
|
||||
}
|
||||
|
||||
export function getMeasurePosition() {
|
||||
const mousePosition = canvas.app.renderer.plugins.interaction.mouse.getLocalPosition(canvas.tokens);
|
||||
const mousePosition = canvas.app.renderer.plugins.interaction.mouse.getLocalPosition(
|
||||
canvas.tokens,
|
||||
);
|
||||
const rulerOffset = canvas.controls.ruler.rulerOffset;
|
||||
const measurePosition = {x: mousePosition.x + rulerOffset.x, y: mousePosition.y + rulerOffset.y};
|
||||
return measurePosition;
|
||||
@@ -294,5 +290,5 @@ export function early_isGM() {
|
||||
}
|
||||
|
||||
export function isModuleActive(moduleName) {
|
||||
return game.modules.get(moduleName)?.active
|
||||
return game.modules.get(moduleName)?.active;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user