Change ruler color on gridless maps to indecate different speeds (resolves #15)

This commit is contained in:
Manuel Vögele
2021-02-08 18:08:52 +01:00
parent 24620bd604
commit 4bd1473310
4 changed files with 12 additions and 4 deletions
+1
View File
@@ -2,6 +2,7 @@
### New features ### New features
- Right click and spacebar can now be swapped, allowing to place waypoints with right click and removing them with spacebar - Right click and spacebar can now be swapped, allowing to place waypoints with right click and removing them with spacebar
- The module can now be configured use a fixed color instead of the player color for the first speed range - The module can now be configured use a fixed color instead of the player color for the first speed range
- On gridless maps the ruler will now change it's color to indicate the different speed ranges
### Bugfixes ### Bugfixes
- Disabling snap to grid with shift now works as expected - Disabling snap to grid with shift now works as expected
+1 -1
View File
@@ -1,7 +1,7 @@
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/staebchenfisch) [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](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. 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.
## Path color ## Path color
+9 -2
View File
@@ -1,3 +1,5 @@
import {getColorForDistance} from "./main.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 moveTokens(draggedToken, selectedTokens) { export async function moveTokens(draggedToken, selectedTokens) {
let wasPaused = game.paused; let wasPaused = game.paused;
@@ -142,12 +144,17 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) {
// Draw measured path // Draw measured path
r.clear(); r.clear();
let rulerColor
if (canvas.grid.type === CONST.GRID_TYPES.GRIDLESS)
rulerColor = getColorForDistance.call(this, totalDistance)
else
rulerColor = this.color
for (let s of segments) { for (let s of segments) {
const { ray, label, text, last } = s; const { ray, label, text, last } = s;
// Draw line segment // Draw line segment
r.lineStyle(6, 0x000000, 0.5).moveTo(ray.A.x, ray.A.y).lineTo(ray.B.x, ray.B.y) r.lineStyle(6, 0x000000, 0.5).moveTo(ray.A.x, ray.A.y).lineTo(ray.B.x, ray.B.y)
.lineStyle(4, this.color, 0.25).moveTo(ray.A.x, ray.A.y).lineTo(ray.B.x, ray.B.y); .lineStyle(4, rulerColor, 0.25).moveTo(ray.A.x, ray.A.y).lineTo(ray.B.x, ray.B.y);
// Draw the distance label just after the endpoint of the segment // Draw the distance label just after the endpoint of the segment
if (label) { if (label) {
@@ -164,7 +171,7 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) {
// Draw endpoints // Draw endpoints
for (let p of waypoints) { for (let p of waypoints) {
r.lineStyle(2, 0x000000, 0.5).beginFill(this.color, 0.25).drawCircle(p.x, p.y, 8); r.lineStyle(2, 0x000000, 0.5).beginFill(rulerColor, 0.25).drawCircle(p.x, p.y, 8);
} }
// Return the measured segments // Return the measured segments
+1 -1
View File
@@ -206,7 +206,7 @@ function nativeSpeedProvider(token, playercolor) {
return [{range: tokenSpeed, color: playercolor}, {range: tokenSpeed * dashMultiplier, color: 0xFFFF00}] return [{range: tokenSpeed, color: playercolor}, {range: tokenSpeed * dashMultiplier, color: 0xFFFF00}]
} }
function getColorForDistance(startDistance, subDistance) { export function getColorForDistance(startDistance, subDistance=0) {
if (!this.isDragRuler) if (!this.isDragRuler)
return this.color return this.color
// Don't apply colors if the current user doesn't have at least observer permissions // Don't apply colors if the current user doesn't have at least observer permissions