Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| eef05553c0 | |||
| 7ba89e4229 | |||
| d11d6385e2 | |||
| 4d2e4b7715 | |||
| 3cbe41e2be | |||
| 732802c579 | |||
| 8bbb11ddaa | |||
| e6cee3477a | |||
| 7cee1e7af0 |
@@ -1,3 +1,19 @@
|
|||||||
|
## 1.7.3
|
||||||
|
### Compatibility
|
||||||
|
- Drag Ruler is now compatible with Foundry 0.8.5
|
||||||
|
|
||||||
|
|
||||||
|
## 1.7.2
|
||||||
|
### Bugfixes
|
||||||
|
- Fixed a bug that prevented waypoints for measurement templates from snapping to any other point than a grid cell corner (or grid cell center on hex)
|
||||||
|
- Fixed a bug that could cause the ruler to not end up at the token's center (especially if the token is being moved very quickly and then stopped abruptly)
|
||||||
|
|
||||||
|
|
||||||
|
## 1.7.1
|
||||||
|
### Bugfixes
|
||||||
|
- Fixed a bug that prevented players from moving their tokens ([#74](https://github.com/manuelVo/foundryvtt-drag-ruler/issues/74))
|
||||||
|
|
||||||
|
|
||||||
## 1.7.0
|
## 1.7.0
|
||||||
**BREAKING** This update is incompatible with previous Terrain Ruler versions. If you're using Terrain Ruler, make sure you update Terrain Ruler to at least version 1.3.0.
|
**BREAKING** This update is incompatible with previous Terrain Ruler versions. If you're using Terrain Ruler, make sure you update Terrain Ruler to at least version 1.3.0.
|
||||||
|
|
||||||
|
|||||||
@@ -1,32 +1,35 @@
|
|||||||
[](https://ko-fi.com/staebchenfisch)
|
[](https://ko-fi.com/staebchenfisch)
|
||||||
|
|
||||||
# Drag Ruler
|
# Drag Ruler
|
||||||
This module shows a ruler when you drag a token to infrom you how far you've dragged the token from it's start point. Additionally, if you're using a grid, the spaces the token will travel though will be colored depending on your tokens speed. If you're using a gridless map the ruler color will change to convey this information.
|
This module shows a ruler when you drag a token or measurement template to infrom you how far you've dragged it from it's start point. Additionally, if you're using a grid, the spaces the token will travel though will be colored depending on your tokens speed. By default three colors are being used: green for spaces that your token can reach by walking normally are colored green, spaces that can only be reached by dashing will be colored red and spaces that cannot be reached with the token's speed will be colored red. If you're using a gridless map the ruler color will change to convey this information.
|
||||||
|
|
||||||
|

|
||||||
|

|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
## Path color
|
## Supports Tokens of all sizes
|
||||||

|
Terrain ruler has excellent support for tokens of all sizes. The Ruler will always originate from the token's center and will always highlight all the squares that tokens move over. If the [Hex Token Size Support](https://foundryvtt.com/packages/hex-size-support) is installed this is also true for large tokens on hex scenes.
|
||||||
|
|
||||||
The token has a speed of 30ft. All squares on the path within that range are colored in the players color. If the token is running it can cover double that range (this can be changed in the settings). All Squares on the path that can only be reached while running are colored in yellow. Squares on the path that the token cannot possibly reached at regular speeds are colored red. This coloring behavior can be tweaked in the settings and can be overridden by modules and game systems to provide more granular, game system specific control. For more information on how to do this see the [API](#api) section of this document.
|

|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
## Waypoints
|
## Difficult Terrain support
|
||||||
You can add waypoints to the path by pressing spacebar while you drag the token. To remove a placed waypoint press the right mouse button.
|
**To use support for difficult terrain you must install the [Terrain Ruler](https://foundryvtt.com/packages/terrain-ruler) module**
|
||||||
|
|
||||||

|
With the Terrain Ruler module installed, Drag Ruler is able to take difficult terrain that was placed down using the [Enhanced Terrain Layer](https://foundryvtt.com/packages/enhanced-terrain-layer) or [TerrainLayer](https://foundryvtt.com/packages/TerrainLayer) module into account.
|
||||||
|
|
||||||
## Difficult Terrain
|

|
||||||
**To use support for difficult terrain you must install the [Terrain Ruler module](https://foundryvtt.com/packages/terrain-ruler)**
|

|
||||||
|
|
||||||
With the Terrain Ruler module installed, Drag Ruler is able to take difficult terrain that was placed with the [TerrainLayer module](https://foundryvtt.com/packages/TerrainLayer/) into account when measuring distances.
|
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
|
|
||||||
## Why would I want to use this instead of ShowDragDistance?
|
## Movement history (optional)
|
||||||
ShowDragDistance isn't maintained anymore. This means that it is at risk to stop working with every foundry update. In fact this process has already begun. As of Foundry Version 0.7.9 ShowDragDistance doesn't work anymore on gridless maps. Drag Ruler on the other hand is fully compatible with the current Foundry release and I'll continue updating it for future foundry releases for the forseeable future.
|
*This feature can be disabled in the settings if you don't like it*
|
||||||
|
|
||||||
In addition Drag Ruler provides more flexibility for game systems and modules via it's api to provide an experience that fits the rules of the game system that you are playing best.
|
During combat, Drag Ruler will remember the path a token has taken during it's turn. When the token is being picked up again, Drag Ruler will continue measuring where it has left off. The path of the previous movement will be dipslayed in a faded color.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
## Game systems with Drag Ruler integration
|
## Game systems with Drag Ruler integration
|
||||||
|
|||||||
+4
-4
@@ -2,9 +2,9 @@
|
|||||||
"name": "drag-ruler",
|
"name": "drag-ruler",
|
||||||
"title": "Drag Ruler",
|
"title": "Drag Ruler",
|
||||||
"description": "When dragging a token displays a ruler showing how far you've moved that token.",
|
"description": "When dragging a token displays a ruler showing how far you've moved that token.",
|
||||||
"version": "1.7.0",
|
"version": "1.7.3",
|
||||||
"minimumCoreVersion" : "0.7.9",
|
"minimumCoreVersion" : "0.8.5",
|
||||||
"compatibleCoreVersion" : "0.7.9",
|
"compatibleCoreVersion" : "0.8.5",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
"name": "Manuel Vögele",
|
"name": "Manuel Vögele",
|
||||||
@@ -49,7 +49,7 @@
|
|||||||
],
|
],
|
||||||
"socket": true,
|
"socket": true,
|
||||||
"url": "https://github.com/manuelVo/foundryvtt-drag-ruler",
|
"url": "https://github.com/manuelVo/foundryvtt-drag-ruler",
|
||||||
"download": "https://github.com/manuelVo/foundryvtt-drag-ruler/archive/v1.7.0.zip",
|
"download": "https://github.com/manuelVo/foundryvtt-drag-ruler/archive/v1.7.3.zip",
|
||||||
"manifest": "https://raw.githubusercontent.com/manuelVo/foundryvtt-drag-ruler/master/module.json",
|
"manifest": "https://raw.githubusercontent.com/manuelVo/foundryvtt-drag-ruler/master/module.json",
|
||||||
"readme": "https://github.com/manuelVo/foundryvtt-drag-ruler/blob/master/README.md",
|
"readme": "https://github.com/manuelVo/foundryvtt-drag-ruler/blob/master/README.md",
|
||||||
"changelog": "https://github.com/manuelVo/foundryvtt-drag-ruler/blob/master/CHANGELOG.md",
|
"changelog": "https://github.com/manuelVo/foundryvtt-drag-ruler/blob/master/CHANGELOG.md",
|
||||||
|
|||||||
+25
-10
@@ -4,7 +4,7 @@ import {Line} from "./geometry.js";
|
|||||||
import {getColorForDistance} from "./main.js"
|
import {getColorForDistance} from "./main.js"
|
||||||
import {trackRays} from "./movement_tracking.js"
|
import {trackRays} from "./movement_tracking.js"
|
||||||
import {recalculate} from "./socket.js";
|
import {recalculate} from "./socket.js";
|
||||||
import {applyTokenSizeOffset, getSnapPointForMeasuredTemplate, getSnapPointForToken, getTokenShape, highlightTokenShape, zip} from "./util.js";
|
import {applyTokenSizeOffset, getSnapPointForEntity, getSnapPointForToken, getTokenShape, highlightTokenShape, zip} from "./util.js";
|
||||||
|
|
||||||
// This is a modified version of Ruler.moveToken from foundry 0.7.9
|
// This is a modified version of Ruler.moveToken from foundry 0.7.9
|
||||||
export async function moveEntities(draggedEntity, selectedEntities) {
|
export async function moveEntities(draggedEntity, selectedEntities) {
|
||||||
@@ -16,12 +16,15 @@ export async function moveEntities(draggedEntity, selectedEntities) {
|
|||||||
if (!this.visible || !this.destination) return false;
|
if (!this.visible || !this.destination) return false;
|
||||||
if (!draggedEntity) return;
|
if (!draggedEntity) return;
|
||||||
|
|
||||||
|
// Wait until all scheduled measurements are done
|
||||||
|
await this.deferredMeasurementPromise;
|
||||||
|
|
||||||
// Get the movement rays and check collision along each Ray
|
// Get the movement rays and check collision along each Ray
|
||||||
// These rays are center-to-center for the purposes of collision checking
|
// These rays are center-to-center for the purposes of collision checking
|
||||||
const rays = this.constructor.dragRulerGetRaysFromWaypoints(this.waypoints, this.destination);
|
const rays = this.constructor.dragRulerGetRaysFromWaypoints(this.waypoints, this.destination);
|
||||||
if (!game.user.isGM && draggedEntity instanceof Token) {
|
if (!game.user.isGM && draggedEntity instanceof Token) {
|
||||||
const hasCollision = selectedEntities.some(token => {
|
const hasCollision = selectedEntities.some(token => {
|
||||||
const offset = calculateTokenOffset(token, draggedEntity);
|
const offset = calculateEntityOffset(token, draggedEntity);
|
||||||
const offsetRays = rays.filter(ray => !ray.isPrevious).map(ray => applyOffsetToRay(ray, offset))
|
const offsetRays = rays.filter(ray => !ray.isPrevious).map(ray => applyOffsetToRay(ray, offset))
|
||||||
return offsetRays.some(r => canvas.walls.checkCollision(r));
|
return offsetRays.some(r => canvas.walls.checkCollision(r));
|
||||||
})
|
})
|
||||||
@@ -80,7 +83,7 @@ async function animateEntities(entities, draggedEntity, draggedRays, wasPaused)
|
|||||||
const updates = entityPaths.map(({entity, path}) => {
|
const updates = entityPaths.map(({entity, path}) => {
|
||||||
return {x: path.B.x, y: path.B.y, _id: entity.id};
|
return {x: path.B.x, y: path.B.y, _id: entity.id};
|
||||||
});
|
});
|
||||||
await draggedEntity.scene.updateEmbeddedEntity(draggedEntity.constructor.embeddedName, updates, {animate});
|
await draggedEntity.scene.updateEmbeddedDocuments(draggedEntity.constructor.embeddedName, updates, {animate});
|
||||||
if (animate)
|
if (animate)
|
||||||
await Promise.all(entityPaths.map(({entity, path}) => entity.animateMovement(path)));
|
await Promise.all(entityPaths.map(({entity, path}) => entity.animateMovement(path)));
|
||||||
}
|
}
|
||||||
@@ -103,8 +106,6 @@ export function onMouseMove(event) {
|
|||||||
if (this._state === Ruler.STATES.MOVING) return;
|
if (this._state === Ruler.STATES.MOVING) return;
|
||||||
|
|
||||||
// Extract event data
|
// Extract event data
|
||||||
const mt = event._measureTime || 0;
|
|
||||||
const originalEvent = event.data.originalEvent;
|
|
||||||
const destination = {x: event.data.destination.x + this.rulerOffset.x, y: event.data.destination.y + this.rulerOffset.y}
|
const destination = {x: event.data.destination.x + this.rulerOffset.x, y: event.data.destination.y + this.rulerOffset.y}
|
||||||
|
|
||||||
// Hide any existing Token HUD
|
// Hide any existing Token HUD
|
||||||
@@ -112,10 +113,27 @@ export function onMouseMove(event) {
|
|||||||
delete event.data.hudState;
|
delete event.data.hudState;
|
||||||
|
|
||||||
// Draw measurement updates
|
// Draw measurement updates
|
||||||
if (Date.now() - mt > 50) {
|
scheduleMeasurement.call(this, destination, event);
|
||||||
|
}
|
||||||
|
|
||||||
|
function scheduleMeasurement(destination, event) {
|
||||||
|
const measurementInterval = 50;
|
||||||
|
const mt = event._measureTime || 0;
|
||||||
|
const originalEvent = event.data.originalEvent;
|
||||||
|
if (Date.now() - mt > measurementInterval) {
|
||||||
this.measure(destination, {snap: !originalEvent.shiftKey});
|
this.measure(destination, {snap: !originalEvent.shiftKey});
|
||||||
event._measureTime = Date.now();
|
event._measureTime = Date.now();
|
||||||
this._state = Ruler.STATES.MEASURING;
|
this._state = Ruler.STATES.MEASURING;
|
||||||
|
window.clearTimeout(this.deferredMeasurementTimeout);
|
||||||
|
this.deferredMeasurementTimeout = undefined;
|
||||||
|
this.deferredMeasurementResolve?.();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.deferredMeasurementData = {destination, event};
|
||||||
|
if (!this.deferredMeasurementTimeout) {
|
||||||
|
this.deferredMeasurementPromise = new Promise((resolve, reject) => this.deferredMeasurementResolve = resolve);
|
||||||
|
this.deferredMeasurementTimeout = window.setTimeout(() => scheduleMeasurement.call(this, this.deferredMeasurementData.destination, this.deferredMeasurementData.event), measurementInterval);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,10 +144,7 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) {
|
|||||||
return []
|
return []
|
||||||
|
|
||||||
if (snap) {
|
if (snap) {
|
||||||
if (isToken)
|
destination = getSnapPointForEntity(destination.x, destination.y, this.draggedEntity);
|
||||||
destination = getSnapPointForToken(destination.x, destination.y, this.draggedEntity);
|
|
||||||
else
|
|
||||||
destination = getSnapPointForMeasuredTemplate(destination.x, destination.y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const terrainRulerAvailable = isToken && game.modules.get("terrain-ruler")?.active && (!game.modules.get("TerrainLayer")?.active || canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS);
|
const terrainRulerAvailable = isToken && game.modules.get("terrain-ruler")?.active && (!game.modules.get("TerrainLayer")?.active || canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS);
|
||||||
|
|||||||
+1
-2
@@ -50,7 +50,7 @@ Hooks.on("getCombatTrackerEntryContext", function (html, menu) {
|
|||||||
const entry = {
|
const entry = {
|
||||||
name: "drag-ruler.resetMovementHistory",
|
name: "drag-ruler.resetMovementHistory",
|
||||||
icon: '<i class="fas fa-undo-alt"></i>',
|
icon: '<i class="fas fa-undo-alt"></i>',
|
||||||
callback: li => resetMovementHistory(ui.combat.combat, li.data('combatant-id')),
|
callback: li => resetMovementHistory(ui.combat.viewed, li.data('combatant-id')),
|
||||||
};
|
};
|
||||||
menu.splice(1, 0, entry);
|
menu.splice(1, 0, entry);
|
||||||
});
|
});
|
||||||
@@ -154,7 +154,6 @@ function onEntityDragLeftDrop(event) {
|
|||||||
const ruler = canvas.controls.ruler
|
const ruler = canvas.controls.ruler
|
||||||
if (!ruler.isDragRuler)
|
if (!ruler.isDragRuler)
|
||||||
return false
|
return false
|
||||||
onMouseMove.call(ruler, event);
|
|
||||||
// When we're dragging a measured template no token will ever be selected,
|
// When we're dragging a measured template no token will ever be selected,
|
||||||
// resulting in only the dragged template to be moved as would be expected
|
// resulting in only the dragged template to be moved as would be expected
|
||||||
const selectedTokens = canvas.tokens.controlled
|
const selectedTokens = canvas.tokens.controlled
|
||||||
|
|||||||
+12
-12
@@ -4,19 +4,19 @@ import {getTokenShape, zip} from "./util.js";
|
|||||||
|
|
||||||
function initTrackingFlag(combatant) {
|
function initTrackingFlag(combatant) {
|
||||||
const initialFlag = {passedWaypoints: [], trackedRound: 0};
|
const initialFlag = {passedWaypoints: [], trackedRound: 0};
|
||||||
let dragRulerFlag = combatant.flags?.dragRuler;
|
let dragRulerFlag = combatant.data.flags.dragRuler;
|
||||||
if (dragRulerFlag) {
|
if (dragRulerFlag) {
|
||||||
if (isNaN(dragRulerFlag.trackedRound)) {
|
if (isNaN(dragRulerFlag.trackedRound)) {
|
||||||
mergeObject(dragRulerFlag, initialFlag);
|
mergeObject(dragRulerFlag, initialFlag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
combatant.flags.dragRuler = initialFlag;
|
combatant.data.flags.dragRuler = initialFlag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInitializedCombatant(token, combat) {
|
function getInitializedCombatant(token, combat) {
|
||||||
const combatant = combat.getCombatantByToken(token.data._id);
|
const combatant = combat.getCombatantByToken(token.id);
|
||||||
if (!combatant)
|
if (!combatant)
|
||||||
return undefined;
|
return undefined;
|
||||||
initTrackingFlag(combatant);
|
initTrackingFlag(combatant);
|
||||||
@@ -43,14 +43,14 @@ function calculateUpdate(combat, token, rays) {
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Check if we have entered a new round. If so, remove the currently stored path
|
// Check if we have entered a new round. If so, remove the currently stored path
|
||||||
if (combat.data.round > combatant.flags.dragRuler.trackedRound) {
|
if (combat.data.round > combatant.data.flags.dragRuler.trackedRound) {
|
||||||
combatant.flags.dragRuler.passedWaypoints = [];
|
combatant.data.flags.dragRuler.passedWaypoints = [];
|
||||||
combatant.flags.dragRuler.trackedRound = combat.data.round;
|
combatant.data.flags.dragRuler.trackedRound = combat.data.round;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the passed waypoints to the combatant
|
// Add the passed waypoints to the combatant
|
||||||
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && (!game.modules.get("TerrainLayer")?.active || canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS);
|
const terrainRulerAvailable = game.modules.get("terrain-ruler")?.active && (!game.modules.get("TerrainLayer")?.active || canvas.grid.type !== CONST.GRID_TYPES.GRIDLESS);
|
||||||
const dragRulerFlags = combatant.flags.dragRuler;
|
const dragRulerFlags = combatant.data.flags.dragRuler;
|
||||||
const waypoints = dragRulerFlags.passedWaypoints;
|
const waypoints = dragRulerFlags.passedWaypoints;
|
||||||
for (const ray of rays) {
|
for (const ray of rays) {
|
||||||
// Ignore rays that have the same start and end coordinates
|
// Ignore rays that have the same start and end coordinates
|
||||||
@@ -63,17 +63,17 @@ function calculateUpdate(combat, token, rays) {
|
|||||||
waypoints.push(ray.A);
|
waypoints.push(ray.A);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {_id: combatant._id, dragRulerFlags};
|
return {_id: combatant.id, dragRulerFlags};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getMovementHistory(token) {
|
export function getMovementHistory(token) {
|
||||||
const combat = game.combat;
|
const combat = game.combat;
|
||||||
if (!combat)
|
if (!combat)
|
||||||
return [];
|
return [];
|
||||||
const combatant = combat.getCombatantByToken(token.data._id);
|
const combatant = combat.getCombatantByToken(token.id);
|
||||||
if (!combatant)
|
if (!combatant)
|
||||||
return [];
|
return [];
|
||||||
const dragRulerFlags = combatant.flags.dragRuler;
|
const dragRulerFlags = combatant.data.flags.dragRuler;
|
||||||
if (!dragRulerFlags)
|
if (!dragRulerFlags)
|
||||||
return [];
|
return [];
|
||||||
if (combat.data.round > dragRulerFlags.trackedRound)
|
if (combat.data.round > dragRulerFlags.trackedRound)
|
||||||
@@ -82,8 +82,8 @@ export function getMovementHistory(token) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function resetMovementHistory(combat, combatantId) {
|
export async function resetMovementHistory(combat, combatantId) {
|
||||||
const combatant = combat.getCombatant(combatantId);
|
const combatant = combat.combatants.get(combatantId);
|
||||||
const dragRulerFlags = combatant.flags.dragRuler;
|
const dragRulerFlags = combatant.data.flags.dragRuler;
|
||||||
if (!dragRulerFlags)
|
if (!dragRulerFlags)
|
||||||
return;
|
return;
|
||||||
dragRulerFlags.passedWaypoints = null;
|
dragRulerFlags.passedWaypoints = null;
|
||||||
|
|||||||
+5
-4
@@ -1,7 +1,7 @@
|
|||||||
import {measure} from "./foundry_imports.js"
|
import {measure} from "./foundry_imports.js"
|
||||||
import {getMovementHistory} from "./movement_tracking.js";
|
import {getMovementHistory} from "./movement_tracking.js";
|
||||||
import {settingsKey} from "./settings.js";
|
import {settingsKey} from "./settings.js";
|
||||||
import {getSnapPointForToken} from "./util.js";
|
import {getSnapPointForEntity} from "./util.js";
|
||||||
|
|
||||||
export class DragRulerRuler extends Ruler {
|
export class DragRulerRuler extends Ruler {
|
||||||
// Functions below are overridden versions of functions in Ruler
|
// Functions below are overridden versions of functions in Ruler
|
||||||
@@ -34,7 +34,7 @@ export class DragRulerRuler extends Ruler {
|
|||||||
toJSON() {
|
toJSON() {
|
||||||
const json = super.toJSON();
|
const json = super.toJSON();
|
||||||
if (this.draggedEntity)
|
if (this.draggedEntity)
|
||||||
json["draggedEntity"] = this.draggedEntity.data._id;
|
json["draggedEntity"] = this.draggedEntity.id;
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,8 +65,9 @@ export class DragRulerRuler extends Ruler {
|
|||||||
|
|
||||||
// The functions below aren't present in the orignal Ruler class and are added by Drag Ruler
|
// The functions below aren't present in the orignal Ruler class and are added by Drag Ruler
|
||||||
dragRulerAddWaypoint(point, snap=true) {
|
dragRulerAddWaypoint(point, snap=true) {
|
||||||
if (snap)
|
if (snap) {
|
||||||
point = getSnapPointForToken(point.x, point.y, this.draggedEntity);
|
point = getSnapPointForEntity(point.x, point.y, this.draggedEntity);
|
||||||
|
}
|
||||||
this.waypoints.push(new PIXI.Point(point.x, point.y));
|
this.waypoints.push(new PIXI.Point(point.x, point.y));
|
||||||
this.labels.addChild(new PreciseText("", CONFIG.canvasTextStyle));
|
this.labels.addChild(new PreciseText("", CONFIG.canvasTextStyle));
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -12,7 +12,7 @@ export function updateCombatantDragRulerFlags(combat, updates) {
|
|||||||
const combatId = combat.id;
|
const combatId = combat.id;
|
||||||
// TODO Check if canvas.tokens.get is still neccessary in future foundry versions
|
// TODO Check if canvas.tokens.get is still neccessary in future foundry versions
|
||||||
return socket.executeAsGM(_socketUpdateCombatantDragRulerFlags, combatId, updates)
|
return socket.executeAsGM(_socketUpdateCombatantDragRulerFlags, combatId, updates)
|
||||||
.then(() => currentSpeedProvider.onMovementHistoryUpdate(updates.map(update => canvas.tokens.get(combat.getCombatant(update._id).token._id))));
|
.then(() => currentSpeedProvider.onMovementHistoryUpdate(updates.map(update => canvas.tokens.get(combat.combatants.get(update._id).token.id))));
|
||||||
}
|
}
|
||||||
|
|
||||||
async function _socketUpdateCombatantDragRulerFlags(combatId, updates) {
|
async function _socketUpdateCombatantDragRulerFlags(combatId, updates) {
|
||||||
@@ -20,10 +20,10 @@ async function _socketUpdateCombatantDragRulerFlags(combatId, updates) {
|
|||||||
const combat = game.combats.get(combatId);
|
const combat = game.combats.get(combatId);
|
||||||
const requestedUpdates = updates.length;
|
const requestedUpdates = updates.length;
|
||||||
updates = updates.filter(update => {
|
updates = updates.filter(update => {
|
||||||
const actor = combat.getCombatant(update._id).actor;
|
const actor = combat.combatants.get(update._id).actor;
|
||||||
if (!actor)
|
if (!actor)
|
||||||
return false;
|
return false;
|
||||||
return actor.hasPerm(user, "OWNER");
|
return actor.testUserPermission(user, "OWNER");
|
||||||
});
|
});
|
||||||
if (updates.length !== requestedUpdates) {
|
if (updates.length !== requestedUpdates) {
|
||||||
console.warn(`Some of the movement history updates requested by user '${game.users.get(this.socketdata.userId).name}' were not performed because the user lacks owner permissions for those tokens`);
|
console.warn(`Some of the movement history updates requested by user '${game.users.get(this.socketdata.userId).name}' were not performed because the user lacks owner permissions for those tokens`);
|
||||||
@@ -31,7 +31,7 @@ async function _socketUpdateCombatantDragRulerFlags(combatId, updates) {
|
|||||||
updates = updates.map(update => {
|
updates = updates.map(update => {
|
||||||
return {_id: update._id, flags: {dragRuler: update.dragRulerFlags}};
|
return {_id: update._id, flags: {dragRuler: update.dragRulerFlags}};
|
||||||
});
|
});
|
||||||
await combat.updateEmbeddedEntity("Combatant", updates, {diff: false});
|
await combat.updateEmbeddedDocuments("Combatant", updates, {diff: false});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function recalculate(tokens) {
|
export function recalculate(tokens) {
|
||||||
|
|||||||
@@ -62,6 +62,14 @@ export function getSnapPointForMeasuredTemplate(x, y) {
|
|||||||
return new PIXI.Point(snappedX, snappedY);
|
return new PIXI.Point(snappedX, snappedY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getSnapPointForEntity(x, y, entity) {
|
||||||
|
const isToken = entity instanceof Token;
|
||||||
|
if (isToken)
|
||||||
|
return getSnapPointForToken(x, y, entity);
|
||||||
|
else
|
||||||
|
return getSnapPointForMeasuredTemplate(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
export function highlightTokenShape(position, shape, color, alpha) {
|
export function highlightTokenShape(position, shape, color, alpha) {
|
||||||
const layer = canvas.grid.highlightLayers[this.name];
|
const layer = canvas.grid.highlightLayers[this.name];
|
||||||
if ( !layer )
|
if ( !layer )
|
||||||
|
|||||||
Reference in New Issue
Block a user