Skip to content

Commit

Permalink
2.1.5 - Now cancels ruler and movement if you drag token back to star…
Browse files Browse the repository at this point in the history
…ting point. Holding shift will now let you place token off grid, as it should. Pressing escape while dragging will now cancel drag.
  • Loading branch information
wsaunders1014 committed Sep 24, 2020
1 parent f6b242f commit afed750
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ New Settings:
You can now point to where the speed or movement attribute is located on the actor sheet. For instance, for DnD5e it is `actor.data.data.attributes.speed.value`. You can also point to a bonus movement attribute if your system has one. In addition you can use token.setFlag('ShowDragDistance','speed',{normal:0,dash:0}) to add any one time speed boosts via macro. The DragRuler also calls Hook.call('moveToken', token, dragRuler) when the token moves. Drag colors are configurable in client side settings if they are too close to player's color.

# Changelog
2.1.5 - Now cancels ruler and movement if you drag token back to starting point. Holding shift will now let you place token off grid, as it should. Pressing escape while dragging will now cancel drag.

2.1.4 - Fixed conflict with Pick-Up-Stix.

2.1.3 - Fixed user broadcasting.
Expand Down
36 changes: 32 additions & 4 deletions showdragdistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ let handleDragCancel;
let rangeFinder = false;
let ctrlPressed = false;
let altPressed = false;
let dragShift = false;
const TokenSpeedAttributes = {base:"",bonus:""};
class DragRuler extends Ruler{
constructor(user, {color=null}={}) {
Expand Down Expand Up @@ -76,7 +77,10 @@ class DragRuler extends Ruler{
}
measure(destination, {gridSpaces=true}={}) {

destination = new PIXI.Point(...canvas.grid.getCenter(destination.x, destination.y));
if(!dragShift)
destination = new PIXI.Point(...canvas.grid.getCenter(destination.x, destination.y));
//else

const waypoints = this.waypoints.concat([destination]);
const r = this.dragRuler;
this.destination = destination;
Expand Down Expand Up @@ -148,7 +152,7 @@ class DragRuler extends Ruler{
dashSpeed = 0;
}
}
if(dist > 0){
if(dist > 0 && newSegments.length > 0){
newRay = {ray:new Ray(newSegments[newSegments.length -1].ray.B,ray.B)}
newRay.exceeded = true;
newRay.dash = false;
Expand Down Expand Up @@ -555,9 +559,12 @@ class DragRuler extends Ruler{

if(canvas.controls.dragRuler.active && typeof this.data.flags['pick-up-stix'] == 'undefined'){
const dragruler = (canvas.controls.dragRuler._state > 0) ? canvas.controls.dragRuler.toJSON() : null;
canvas.controls.dragRuler.moveToken()

//canvas.controls.dragRuler.moveToken()
canvas.controls.dragRuler._onMouseUp(event)
canvas.controls.dragRuler._endMeasurement();
canvas.controls.dragRuler._state = 0;
}else{

oldOnDragLeftCancel.apply(this,[event])
}
}else{
Expand Down Expand Up @@ -646,6 +653,24 @@ Hooks.on('ready',()=>{
canvas.controls.dragRuler._addWaypoint(canvas.app.renderer.plugins.interaction.mouse.getLocalPosition(canvas.tokens))
}
break;
case 27:
for ( let c of canvas.tokens.controlled[0].layer.preview.children ) {
const o = c._original;
if ( o ) {
o.data.locked = false;
o.alpha = 1.0;
}
}
canvas.tokens.controlled[0].layer.preview.removeChildren();
canvas.controls.dragRuler._onMouseUp(e)
canvas.mouseInteractionManager.state = 1;
canvas.tokens.controlled[0].mouseInteractionManager.state = 0
canvas.tokens.controlled[0]._onDragLeftCancel(e);
canvas.tokens.controlled[0].release()
break;
case 16:
dragShift= true;
break;
default:
break;
}
Expand All @@ -668,6 +693,9 @@ Hooks.on('ready',()=>{
game.user.broadcastActivity({dragruler:null})
}
break;
case 16:
dragShift= false;
break;
default:
break;
}
Expand Down

0 comments on commit afed750

Please sign in to comment.