Track the path taken by tokens in combat and display it when reactivating DragRuler in the same turn
This commit is contained in:
+34
-3
@@ -4,6 +4,18 @@ import {getSnapPointForToken} from "./util.js";
|
||||
|
||||
export class DragRulerRuler extends Ruler {
|
||||
// Functions below are overridden versions of functions in Ruler
|
||||
constructor(user, {color=null}={}) {
|
||||
super(user, {color});
|
||||
this.previousWaypoints = [];
|
||||
this.previousLabels = this.addChild(new PIXI.Container());
|
||||
}
|
||||
|
||||
clear() {
|
||||
super.clear();
|
||||
this.previousWaypoints = [];
|
||||
this.previousLabels.removeChildren().forEach(c => c.destroy());
|
||||
}
|
||||
|
||||
async moveToken(event) {
|
||||
// This function is invoked by left clicking
|
||||
if (!this.isDragRuler)
|
||||
@@ -57,8 +69,17 @@ export class DragRulerRuler extends Ruler {
|
||||
this.labels.addChild(new PreciseText("", CONFIG.canvasTextStyle));
|
||||
}
|
||||
|
||||
dragRulerDeleteWaypoint() {
|
||||
if (this.waypoints.length > 1) {
|
||||
dragRulerAddWaypointHistory(waypoints) {
|
||||
waypoints = waypoints.map(waypoint => {return {x: waypoint.x, y: waypoint.y, isPrevious: true}});
|
||||
this.waypoints = this.waypoints.concat(waypoints);
|
||||
for (const waypoint of waypoints) {
|
||||
this.labels.addChild(new PreciseText("", CONFIG.canvasTextStyle));
|
||||
}
|
||||
}
|
||||
|
||||
dragRulerDeleteWaypoint(event={preventDefault: () => {return}}) {
|
||||
if (this.waypoints.filter(w => !w.isPrevious).length > 1) {
|
||||
event.preventDefault();
|
||||
const mousePosition = canvas.app.renderer.plugins.interaction.mouse.getLocalPosition(canvas.tokens);
|
||||
const rulerOffset = this.rulerOffset;
|
||||
this._removeWaypoint({x: mousePosition.x + rulerOffset.x, y: mousePosition.y + rulerOffset.y});
|
||||
@@ -74,7 +95,17 @@ export class DragRulerRuler extends Ruler {
|
||||
|
||||
// This will cancel the current drag operation
|
||||
// Pass in a fake event that hopefully is enough to allow other modules to function
|
||||
token._onDragLeftCancel({preventDefault: () => {return}});
|
||||
token._onDragLeftCancel(event);
|
||||
}
|
||||
}
|
||||
|
||||
dragRulerGetRaysFromWaypoints(waypoints, destination) {
|
||||
if ( destination )
|
||||
waypoints = waypoints.concat([destination]);
|
||||
return waypoints.slice(1).map((wp, i) => {
|
||||
const ray = new Ray(waypoints[i], wp);
|
||||
ray.isPrevious = Boolean(waypoints[i].isPrevious);
|
||||
return ray;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user