From 4bd1473310366f0ca9dae253f9dbc743e9874c49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Mon, 8 Feb 2021 18:08:52 +0100 Subject: [PATCH] Change ruler color on gridless maps to indecate different speeds (resolves #15) --- CHANGELOG.md | 1 + README.md | 2 +- src/foundry_imports.js | 11 +++++++++-- src/main.js | 2 +- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cdb88ac..f4c36bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ### New features - 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 +- On gridless maps the ruler will now change it's color to indicate the different speed ranges ### Bugfixes - Disabling snap to grid with shift now works as expected diff --git a/README.md b/README.md index 002587b..10b1d92 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/staebchenfisch) # 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 diff --git a/src/foundry_imports.js b/src/foundry_imports.js index 7347fa2..bada795 100644 --- a/src/foundry_imports.js +++ b/src/foundry_imports.js @@ -1,3 +1,5 @@ +import {getColorForDistance} from "./main.js" + // This is a modified version of Ruler.moveToken from foundry 0.7.9 export async function moveTokens(draggedToken, selectedTokens) { let wasPaused = game.paused; @@ -142,12 +144,17 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) { // Draw measured path 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) { const { ray, label, text, last } = s; // Draw line segment 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 if (label) { @@ -164,7 +171,7 @@ export function measure(destination, {gridSpaces=true, snap=false} = {}) { // Draw endpoints 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 diff --git a/src/main.js b/src/main.js index 47debd5..29adb4a 100644 --- a/src/main.js +++ b/src/main.js @@ -206,7 +206,7 @@ function nativeSpeedProvider(token, playercolor) { return [{range: tokenSpeed, color: playercolor}, {range: tokenSpeed * dashMultiplier, color: 0xFFFF00}] } -function getColorForDistance(startDistance, subDistance) { +export function getColorForDistance(startDistance, subDistance=0) { if (!this.isDragRuler) return this.color // Don't apply colors if the current user doesn't have at least observer permissions