Update foundry for v12

This commit is contained in:
Nils
2024-07-11 02:47:20 +02:00
committed by Manuel Vögele
parent b649dacdb5
commit 0808f17ee3
7 changed files with 51 additions and 23 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
"version": "1.13.8", "version": "1.13.8",
"compatibility": { "compatibility": {
"minimum": "11", "minimum": "11",
"verified": "11" "verified": "12"
}, },
"authors": [ "authors": [
{ {
+2 -2
View File
@@ -15,7 +15,7 @@ export function highlightMeasurementTerrainRuler(
} }
export function measureDistances(segments, entity, shape, options = {}) { export function measureDistances(segments, entity, shape, options = {}) {
const opts = duplicate(options); const opts = foundry.utils.duplicate(options);
if (canvas.grid.diagonalRule === "EUCL") { if (canvas.grid.diagonalRule === "EUCL") {
opts.ignoreGrid = true; opts.ignoreGrid = true;
opts.gridSpaces = false; opts.gridSpaces = false;
@@ -31,7 +31,7 @@ export function measureDistances(segments, entity, shape, options = {}) {
); );
previousSegments.forEach( previousSegments.forEach(
segment => segment =>
(segment.ray.terrainRulerVisitedSpaces = duplicate(segment.ray.dragRulerVisitedSpaces)), (segment.ray.terrainRulerVisitedSpaces = foundry.utils.duplicate(segment.ray.dragRulerVisitedSpaces)),
); );
opts.costFunction = buildCostFunction(entity, shape); opts.costFunction = buildCostFunction(entity, shape);
if (previousSegments.length > 0) if (previousSegments.length > 0)
+5 -1
View File
@@ -36,6 +36,7 @@ export async function moveEntities(draggedEntity, selectedEntities) {
}); });
if (hasCollision) { if (hasCollision) {
ui.notifications.error(game.i18n.localize("RULER.MovementCollision")); ui.notifications.error(game.i18n.localize("RULER.MovementCollision"));
this._state = Ruler.STATES.MEASURING;
this._endMeasurement(); this._endMeasurement();
return true; return true;
} }
@@ -47,7 +48,10 @@ export async function moveEntities(draggedEntity, selectedEntities) {
await animateEntities.call(this, selectedEntities, draggedEntity, rays, wasPaused); await animateEntities.call(this, selectedEntities, draggedEntity, rays, wasPaused);
// Once all animations are complete we can clear the ruler // Once all animations are complete we can clear the ruler
if (this.draggedEntity?.id === draggedEntity.id) this._endMeasurement(); if (this.draggedEntity?.id === draggedEntity.id) {
this._state = Ruler.STATES.MEASURING;
this._endMeasurement();
}
} }
// This is a modified version code extracted from Ruler.moveToken from foundry 0.7.9 // This is a modified version code extracted from Ruler.moveToken from foundry 0.7.9
+30 -12
View File
@@ -41,14 +41,14 @@ export function extendRuler() {
if (!this.isDragRuler) return await super.moveToken(event); if (!this.isDragRuler) return await super.moveToken(event);
} }
toJSON() { _getMeasurementData() {
const json = 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;
json.draggedEntity = this.draggedEntity.id; json.draggedEntity = this.draggedEntity.id;
json.waypoints = json.waypoints.map(old => { json.waypoints = json.waypoints.map(old => {
let w = duplicate(old); let w = foundry.utils.duplicate(old);
w.isPathfinding = undefined; w.isPathfinding = undefined;
return w; return w;
}); });
@@ -56,7 +56,13 @@ export function extendRuler() {
return json; return json;
} }
/** @deprecated since V12 */
toJSON() {
return this._getMeasurementData();
}
update(data) { update(data) {
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 &&
@@ -105,7 +111,10 @@ 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 (d.x === this.destination.x && d.y === this.destination.y) return; if ( this.destination && (d.x === this.destination.x) && (d.y === this.destination.y)) {
this.performPostPathfindingActions(options);
return;
}
this.destination = d; this.destination = d;
// TODO Check if we can reuse the old path // TODO Check if we can reuse the old path
@@ -206,6 +215,7 @@ export function extendRuler() {
} }
} }
} }
this.dragRulerSendState();
return this.segments; return this.segments;
} }
@@ -227,7 +237,7 @@ export function extendRuler() {
const waypoints = const waypoints =
this.draggedEntity instanceof Token this.draggedEntity instanceof Token
? applyTokenSizeOffset(unsnappedWaypoints, this.draggedEntity) ? applyTokenSizeOffset(unsnappedWaypoints, this.draggedEntity)
: duplicate(unsnappedWaypoints); : foundry.utils.duplicate(unsnappedWaypoints);
const unsnappedSegments = []; const unsnappedSegments = [];
const segments = []; const segments = [];
for (const [i, p1] of waypoints.entries()) { for (const [i, p1] of waypoints.entries()) {
@@ -252,6 +262,9 @@ export function extendRuler() {
unsnappedSegments.push({ray: unsnappedRay, label}); unsnappedSegments.push({ray: unsnappedRay, label});
} }
this.dragRulerUnsnappedSegments = unsnappedSegments; this.dragRulerUnsnappedSegments = unsnappedSegments;
if ( this.labels.children.length > segments.length ) {
this.labels.removeChildren(segments.length).forEach(c => c.destroy());
}
return segments; return segments;
} else { } else {
return super._getMeasurementSegments(); return super._getMeasurementSegments();
@@ -269,14 +282,16 @@ export function extendRuler() {
enableTerrainRuler: this.dragRulerEnableTerrainRuler, enableTerrainRuler: this.dragRulerEnableTerrainRuler,
}; };
const distances = measureDistances(this.segments, this.draggedEntity, shape, options); const distances = measureDistances(this.segments, this.draggedEntity, shape, options);
let totalDistance = 0; this.totalDistance = 0;
for (const [i, d] of distances.entries()) { for (const [i, d] of distances.entries()) {
let s = this.segments[i]; let s = this.segments[i];
s.startDistance = totalDistance; s.startDistance = this.totalDistance;
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;
s.text = this._getSegmentLabel(s, totalDistance); // V11 and lower use totalDistance as a second arg
// 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()) {
@@ -383,7 +398,7 @@ export function extendRuler() {
{x: mousePosition.x + rulerOffset.x, y: mousePosition.y + rulerOffset.y}, {x: mousePosition.x + rulerOffset.x, y: mousePosition.y + rulerOffset.y},
options, options,
); );
game.user.broadcastActivity({ruler: this}); this.performPostPathfindingActions(options);
} else { } else {
this.dragRulerAbortDrag(event); this.dragRulerAbortDrag(event);
} }
@@ -428,7 +443,7 @@ export function extendRuler() {
this.dragRulerAddWaypoint(waypoint, {snap: false}); this.dragRulerAddWaypoint(waypoint, {snap: false});
} }
this.measure(this.destination); this.measure(this.destination);
game.user.broadcastActivity({ruler: this}); this.dragRulerSendState();
} }
static dragRulerGetRaysFromWaypoints(waypoints, destination) { static dragRulerGetRaysFromWaypoints(waypoints, destination) {
@@ -485,8 +500,11 @@ export function extendRuler() {
} }
dragRulerSendState() { dragRulerSendState() {
if (this.user !== game.user) {
return;
}
game.user.broadcastActivity({ game.user.broadcastActivity({
ruler: this.toJSON(), ruler: this._getMeasurementData(),
}); });
} }
} }
+1 -1
View File
@@ -298,7 +298,7 @@ function enumerateProviderSettings(provider) {
for (const setting of provider.settings) { for (const setting of provider.settings) {
try { try {
if (setting.scope === "world" && !game.user.isGM) continue; if (setting.scope === "world" && !game.user.isGM) continue;
const s = duplicate(setting); const s = foundry.utils.duplicate(setting);
s.id = `${provider.id}.setting.${s.id}`; s.id = `${provider.id}.setting.${s.id}`;
s.name = game.i18n.localize(s.name); s.name = game.i18n.localize(s.name);
s.hint = game.i18n.localize(s.hint); s.hint = game.i18n.localize(s.hint);
+1 -1
View File
@@ -115,7 +115,7 @@ export class GenericSpeedProvider extends SpeedProvider {
getRanges(token) { getRanges(token) {
const speedAttribute = this.getSetting("speedAttribute"); const speedAttribute = this.getSetting("speedAttribute");
if (!speedAttribute) return []; if (!speedAttribute) return [];
const tokenSpeed = parseFloat(getProperty(token, speedAttribute)); const tokenSpeed = parseFloat(foundry.utils.getProperty(token, speedAttribute));
if (tokenSpeed === undefined) { if (tokenSpeed === undefined) {
console.warn( console.warn(
`Drag Ruler (Generic Speed Provider) | The configured token speed attribute "${speedAttribute}" didn't return a speed value. To use colors based on drag distance set the setting to the correct value (or clear the box to disable this feature).`, `Drag Ruler (Generic Speed Provider) | The configured token speed attribute "${speedAttribute}" didn't return a speed value. To use colors based on drag distance set the setting to the correct value (or clear the box to disable this feature).`,
+11 -5
View File
@@ -37,7 +37,7 @@ export function getHexTokenSize(token) {
} }
export function getEntityCenter(token) { export function getEntityCenter(token) {
if (token instanceof Token && canvas.grid.isHex) { if (token instanceof Token && isCanvasHex()) {
const center = token.center; const center = token.center;
const size = getHexTokenSize(token); const size = getHexTokenSize(token);
if (size % 2 === 0) { if (size % 2 === 0) {
@@ -79,7 +79,7 @@ export function getSnapPointForToken(x, y, token) {
return {x, y}; return {x, y};
} }
if (canvas.grid.isHex) { if (isCanvasHex()) {
const size = getHexTokenSize(token); const size = getHexTokenSize(token);
if (size % 2 === 0) { if (size % 2 === 0) {
return findVertexSnapPoint(x, y, getAltOrientationFlagForToken(token, size)); return findVertexSnapPoint(x, y, getAltOrientationFlagForToken(token, size));
@@ -155,7 +155,7 @@ export function getAreaFromPositionAndShape(position, shape) {
return shape.map(space => { return shape.map(space => {
let x = position.x + space.x; let x = position.x + space.x;
let y = position.y + space.y; let y = position.y + space.y;
if (canvas.grid.isHex) { if (isCanvasHex()) {
let shiftedRow; let shiftedRow;
if (canvas.grid.grid.options.even) shiftedRow = 1; if (canvas.grid.grid.options.even) shiftedRow = 1;
else shiftedRow = 0; else shiftedRow = 0;
@@ -236,7 +236,7 @@ export function getTokenShape(token) {
export function getTokenSize(token) { export function getTokenSize(token) {
let w, h; let w, h;
if (canvas.grid.isHex) { if (isCanvasHex()) {
w = h = getHexTokenSize(token); w = h = getHexTokenSize(token);
} else { } else {
w = token.document.width; w = token.document.width;
@@ -254,7 +254,7 @@ export function applyTokenSizeOffset(waypoints, token) {
const tokenSize = getTokenSize(token); const tokenSize = getTokenSize(token);
const waypointOffset = {x: 0, y: 0}; const waypointOffset = {x: 0, y: 0};
if (canvas.grid.isHex) { if (isCanvasHex()) {
const isAltOrientation = getAltOrientationFlagForToken(token, getHexTokenSize(token)); const isAltOrientation = getAltOrientationFlagForToken(token, getHexTokenSize(token));
if (canvas.grid.grid.columnar) { if (canvas.grid.grid.columnar) {
if (tokenSize.w % 2 === 0) { if (tokenSize.w % 2 === 0) {
@@ -324,3 +324,9 @@ export function isPathfindingEnabled() {
if (moveWithoutAnimation) return false; if (moveWithoutAnimation) return false;
return game.settings.get(settingsKey, "autoPathfinding") != togglePathfinding; return game.settings.get(settingsKey, "autoPathfinding") != togglePathfinding;
} }
function isCanvasHex() {
// isHexagonal is introduced in V12 (undefined in V11)
// isHex is deprecated since V12
return canvas.grid.isHexagonal ?? canvas.grid.isHex
}