From 6adb69829e651b24f68d062fbfec8d11b86e362e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Thu, 11 Feb 2021 01:24:33 +0100 Subject: [PATCH] Make compatible with Hex Token Size Support (resolves #12) --- CHANGELOG.md | 4 ++++ src/compatibility.js | 19 +++++++++++++++++++ src/main.js | 7 ++++++- 3 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 src/compatibility.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 3483f3d..2ef8c18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## In development +### Compatiblity +- Drag Ruler is now compatible with Hex Token Size Support. For compatibility Hex Token Size Support Version 0.5.4 or higher is required. Thanks to Ourobor for helping making this possible. + ## 1.2.0 ### New features - Right click and spacebar can now be swapped, allowing to place waypoints with right click and removing them with spacebar diff --git a/src/compatibility.js b/src/compatibility.js new file mode 100644 index 0000000..e61ac85 --- /dev/null +++ b/src/compatibility.js @@ -0,0 +1,19 @@ +export function getHexSizeSupportTokenGridCenter(token) { + const tokenCenterOffset = CONFIG.hexSizeSupport.getCenterOffset(token) + const tokenCenter = {x: token.x + tokenCenterOffset.x, y: token.y + tokenCenterOffset.y} + if (token.getFlag("hex-size-support", "borderSize") % 2 === 1) + return tokenCenter + if (canvas.grid.grid.columns) { + let hexOffset = canvas.grid.w / 2 + if (!CONFIG.hexSizeSupport.getAltOrientationFlag(token)) + hexOffset *= -1 + tokenCenter.x += hexOffset + } + else { + let hexOffset = canvas.grid.h / 2 + if (CONFIG.hexSizeSupport.getAltOrientationFlag(token)) + hexOffset *= -1 + tokenCenter.y += hexOffset + } + return tokenCenter +} diff --git a/src/main.js b/src/main.js index bdaf874..afd208a 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,7 @@ "use strict" import {availableSpeedProviders, currentSpeedProvider, registerModule, registerSystem, setCurrentSpeedProvider} from "./api.js" +import {getHexSizeSupportTokenGridCenter} from "./compatibility.js" import {measure, moveTokens, onMouseMove} from "./foundry_imports.js" import {registerSettings, settingsKey} from "./settings.js" @@ -143,7 +144,11 @@ function onKeyShift(up) { function onTokenLeftDragStart(event) { const ruler = canvas.controls.ruler ruler.draggedToken = this - const tokenCenter = {x: this.x + canvas.grid.grid.w / 2, y: this.y + canvas.grid.grid.h / 2} + let tokenCenter + if (canvas.grid.isHex && game.modules.get("hex-size-support")?.active && CONFIG.hexSizeSupport.getAltSnappingFlag(this)) + tokenCenter = getHexSizeSupportTokenGridCenter(this) + else + tokenCenter = {x: this.x + canvas.grid.grid.w / 2, y: this.y + canvas.grid.grid.h / 2} ruler.clear(); ruler._state = Ruler.STATES.STARTING; ruler.rulerOffset = {x: tokenCenter.x - event.data.origin.x, y: tokenCenter.y - event.data.origin.y}