Remove v11 compatibility code
This commit is contained in:
@@ -137,8 +137,8 @@ export function onMouseMove(event) {
|
|||||||
|
|
||||||
// Extract event data
|
// Extract event data
|
||||||
const destination = {
|
const destination = {
|
||||||
x: event.interactionData.destination.x + this.rulerOffset.x,
|
x: event.interactionData.destination.x,
|
||||||
y: event.interactionData.destination.y + this.rulerOffset.y,
|
y: event.interactionData.destination.y,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Hide any existing Token HUD
|
// Hide any existing Token HUD
|
||||||
|
|||||||
+4
-9
@@ -137,11 +137,6 @@ function onEntityLeftDragStart(wrapped, event) {
|
|||||||
const ruler = canvas.controls.ruler;
|
const ruler = canvas.controls.ruler;
|
||||||
ruler.draggedEntity = this;
|
ruler.draggedEntity = this;
|
||||||
const entityCenter = getEntityCenter(this);
|
const entityCenter = getEntityCenter(this);
|
||||||
const isV11 = game.release.generation === 11;
|
|
||||||
ruler.rulerOffset = {
|
|
||||||
x: isV11 ? entityCenter.x - event.interactionData.origin.x : 0,
|
|
||||||
y: isV11 ? entityCenter.y - event.interactionData.origin.y : 0,
|
|
||||||
};
|
|
||||||
if (game.settings.get(settingsKey, "autoStartMeasurement")) {
|
if (game.settings.get(settingsKey, "autoStartMeasurement")) {
|
||||||
let options = {};
|
let options = {};
|
||||||
setSnapParameterOnOptions(ruler, options);
|
setSnapParameterOnOptions(ruler, options);
|
||||||
@@ -218,7 +213,7 @@ function applyGridlessSnapping(event) {
|
|||||||
const rasterWidth = 35 / canvas.stage.scale.x;
|
const rasterWidth = 35 / canvas.stage.scale.x;
|
||||||
const tokenX = event.interactionData.destination.x;
|
const tokenX = event.interactionData.destination.x;
|
||||||
const tokenY = event.interactionData.destination.y;
|
const tokenY = event.interactionData.destination.y;
|
||||||
const destination = {x: tokenX + ruler.rulerOffset.x, y: tokenY + ruler.rulerOffset.y};
|
const destination = {x: tokenX, y: tokenY};
|
||||||
const ranges = getRangesFromSpeedProvider(ruler.draggedEntity);
|
const ranges = getRangesFromSpeedProvider(ruler.draggedEntity);
|
||||||
|
|
||||||
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active;
|
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active;
|
||||||
@@ -242,8 +237,8 @@ function applyGridlessSnapping(event) {
|
|||||||
const deltaY = destination.y - rasterLocation.y;
|
const deltaY = destination.y - rasterLocation.y;
|
||||||
const rasterDistance = Math.hypot(deltaX, deltaY);
|
const rasterDistance = Math.hypot(deltaX, deltaY);
|
||||||
if (rasterDistance < rasterWidth) {
|
if (rasterDistance < rasterWidth) {
|
||||||
event.interactionData.destination.x = rasterLocation.x - ruler.rulerOffset.x;
|
event.interactionData.destination.x = rasterLocation.x;
|
||||||
event.interactionData.destination.y = rasterLocation.y - ruler.rulerOffset.y;
|
event.interactionData.destination.y = rasterLocation.y;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -257,7 +252,7 @@ function applyGridlessSnapping(event) {
|
|||||||
});
|
});
|
||||||
origin = segments.pop().ray.A;
|
origin = segments.pop().ray.A;
|
||||||
waypointDistance = canvas.grid.measureDistances(segments).reduce((a, b) => a + b);
|
waypointDistance = canvas.grid.measureDistances(segments).reduce((a, b) => a + b);
|
||||||
origin = {x: origin.x - ruler.rulerOffset.x, y: origin.y - ruler.rulerOffset.y};
|
origin = {x: origin.x, y: origin.y};
|
||||||
}
|
}
|
||||||
|
|
||||||
const deltaX = tokenX - origin.x;
|
const deltaX = tokenX - origin.x;
|
||||||
|
|||||||
+10
-13
@@ -42,7 +42,10 @@ export function extendRuler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_getMeasurementData() {
|
_getMeasurementData() {
|
||||||
const json = typeof super._getMeasurementData === 'function' ? super._getMeasurementData() : super.toJSON();
|
const json =
|
||||||
|
typeof super._getMeasurementData === "function"
|
||||||
|
? super._getMeasurementData()
|
||||||
|
: super.toJSON();
|
||||||
if (this.draggedEntity) {
|
if (this.draggedEntity) {
|
||||||
const isToken = this.draggedEntity instanceof Token;
|
const isToken = this.draggedEntity instanceof Token;
|
||||||
json.draggedEntityIsToken = isToken;
|
json.draggedEntityIsToken = isToken;
|
||||||
@@ -62,7 +65,7 @@ export function extendRuler() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
update(data) {
|
update(data) {
|
||||||
if ( !data || (data.state === Ruler.STATES.INACTIVE) ) return this.clear();
|
if (!data || data.state === Ruler.STATES.INACTIVE) return this.clear();
|
||||||
// Don't show a GMs drag ruler to non GM players
|
// Don't show a GMs drag ruler to non GM players
|
||||||
if (
|
if (
|
||||||
data.draggedEntity &&
|
data.draggedEntity &&
|
||||||
@@ -111,7 +114,7 @@ export function extendRuler() {
|
|||||||
|
|
||||||
// Compute the measurement destination, segments, and distance
|
// Compute the measurement destination, segments, and distance
|
||||||
const d = this._getMeasurementDestination(destination);
|
const d = this._getMeasurementDestination(destination);
|
||||||
if ( this.destination && (d.x === this.destination.x) && (d.y === this.destination.y)) {
|
if (this.destination && d.x === this.destination.x && d.y === this.destination.y) {
|
||||||
this.performPostPathfindingActions(options);
|
this.performPostPathfindingActions(options);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -289,9 +292,7 @@ export function extendRuler() {
|
|||||||
this.totalDistance += d;
|
this.totalDistance += d;
|
||||||
s.last = i === this.segments.length - 1;
|
s.last = i === this.segments.length - 1;
|
||||||
s.distance = d;
|
s.distance = d;
|
||||||
// V11 and lower use totalDistance as a second arg
|
s.text = this._getSegmentLabel(s);
|
||||||
// V12 ignores the 2nd argument and uses this.totalDistance
|
|
||||||
s.text = this._getSegmentLabel(s, this.totalDistance);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const [i, segment] of this.segments.entries()) {
|
for (const [i, segment] of this.segments.entries()) {
|
||||||
@@ -390,14 +391,10 @@ export function extendRuler() {
|
|||||||
if (this.waypoints.filter(w => !w.isPrevious).length > 1) {
|
if (this.waypoints.filter(w => !w.isPrevious).length > 1) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const mousePosition = getPointer().getLocalPosition(canvas.tokens);
|
const mousePosition = getPointer().getLocalPosition(canvas.tokens);
|
||||||
const rulerOffset = this.rulerOffset;
|
|
||||||
|
|
||||||
// Options are not passed to _removeWaypoint in vanilla Foundry.
|
// Options are not passed to _removeWaypoint in vanilla Foundry.
|
||||||
// Send them in case other modules have overriden that behavior and accept an options parameter (Toggle Snap to Grid)
|
// Send them in case other modules have overriden that behavior and accept an options parameter (Toggle Snap to Grid)
|
||||||
this._removeWaypoint(
|
this._removeWaypoint({x: mousePosition.x, y: mousePosition.y}, options);
|
||||||
{x: mousePosition.x + rulerOffset.x, y: mousePosition.y + rulerOffset.y},
|
|
||||||
options,
|
|
||||||
);
|
|
||||||
this.performPostPathfindingActions(options);
|
this.performPostPathfindingActions(options);
|
||||||
} else {
|
} else {
|
||||||
this.dragRulerAbortDrag(event);
|
this.dragRulerAbortDrag(event);
|
||||||
@@ -493,8 +490,8 @@ export function extendRuler() {
|
|||||||
ruler.dragRulerAddWaypoint(entityCenter, {snap: false});
|
ruler.dragRulerAddWaypoint(entityCenter, {snap: false});
|
||||||
const mousePosition = getPointer().getLocalPosition(canvas.tokens);
|
const mousePosition = getPointer().getLocalPosition(canvas.tokens);
|
||||||
const destination = {
|
const destination = {
|
||||||
x: mousePosition.x + ruler.rulerOffset.x,
|
x: mousePosition.x,
|
||||||
y: mousePosition.y + ruler.rulerOffset.y,
|
y: mousePosition.y,
|
||||||
};
|
};
|
||||||
if (measureImmediately) ruler.measure(destination, options);
|
if (measureImmediately) ruler.measure(destination, options);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-7
@@ -157,8 +157,7 @@ export function getAreaFromPositionAndShape(position, shape) {
|
|||||||
let y = position.y + space.y;
|
let y = position.y + space.y;
|
||||||
if (isCanvasHex()) {
|
if (isCanvasHex()) {
|
||||||
let shiftedRow;
|
let shiftedRow;
|
||||||
// v12 ?? v11
|
if (canvas.grid?.even) shiftedRow = 1;
|
||||||
if (canvas.grid?.even ?? canvas.grid.grid.options.even) shiftedRow = 1;
|
|
||||||
else shiftedRow = 0;
|
else shiftedRow = 0;
|
||||||
if (canvas.grid.grid.columnar) {
|
if (canvas.grid.grid.columnar) {
|
||||||
if (space.x % 2 !== 0 && position.x % 2 !== shiftedRow) {
|
if (space.x % 2 !== 0 && position.x % 2 !== shiftedRow) {
|
||||||
@@ -302,8 +301,7 @@ export function getPointer() {
|
|||||||
|
|
||||||
export function getMeasurePosition() {
|
export function getMeasurePosition() {
|
||||||
const mousePosition = getPointer().getLocalPosition(canvas.tokens);
|
const mousePosition = getPointer().getLocalPosition(canvas.tokens);
|
||||||
const rulerOffset = canvas.controls.ruler.rulerOffset;
|
const measurePosition = {x: mousePosition.x, y: mousePosition.y};
|
||||||
const measurePosition = {x: mousePosition.x + rulerOffset.x, y: mousePosition.y + rulerOffset.y};
|
|
||||||
return measurePosition;
|
return measurePosition;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +325,5 @@ export function isPathfindingEnabled() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isCanvasHex() {
|
function isCanvasHex() {
|
||||||
// isHexagonal is introduced in V12 (undefined in V11)
|
return canvas.grid.isHexagonal;
|
||||||
// isHex is deprecated since V12
|
|
||||||
return canvas.grid.isHexagonal ?? canvas.grid.isHex
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user