Skip to content

Commit

Permalink
Merge branch 'release/v0.6.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Jun 1, 2023
2 parents 0ee5ce8 + 32540f1 commit aecb898
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 0.6.8
- Store the active/inactive status of the "prefer token elevation" toggle so it is consistent when switching scenes or reloading Foundry (issue #19).
- Improvements to the logic for measuring overhead tile elevations and terrain elevations when Elevated Vision module is active (issue #18).

# 0.6.7
- Fix measuring elevation with Elevated Vision enabled (issue #18).
- No longer require reload of the canvas when enabling/disabling prefer token control.
Expand Down
22 changes: 17 additions & 5 deletions scripts/module.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
/* globals
canvas,
game,
Hooks
Hooks,
ui
*/
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
"use strict";

import { registerSettings, registerKeybindings, SETTINGS, getSetting } from "./settings.js";
import { registerSettings, registerKeybindings, SETTINGS, getSetting, setSetting } from "./settings.js";
import { registerRuler } from "./patching.js";
import { MODULE_ID } from "./const.js";

// For Drag Ruler
import { registerDragRuler } from "./patching.js";
import { registerDragRuler } from "./patching.js"; // eslint-disable-line no-duplicate-imports

import { registerGeometry } from "./geometry/registration.js";

Expand Down Expand Up @@ -57,14 +60,23 @@ Hooks.on("dragRuler.ready", function() {

Hooks.on("canvasInit", function(_canvas) {
updatePreferTokenControl();
})
});

Hooks.on("renderSceneControls", async function(controls, _html, _data) {
// Watch for enabling/disabling of the prefer token control
if ( controls.activeControl !== "token" || !getSetting(SETTINGS.PREFER_TOKEN_ELEVATION) ) return;
const toggle = controls.control.tools.find(t => t.name === SETTINGS.PREFER_TOKEN_ELEVATION);
if ( !toggle ) return; // Shouldn't happen, but...
await setSetting(SETTINGS.PREFER_TOKEN_ELEVATION_CURRENT_VALUE, toggle.active);
});

function updatePreferTokenControl(enable) {
enable ??= getSetting(SETTINGS.PREFER_TOKEN_ELEVATION);
const tokenTools = ui.controls.controls.find(c => c.name === "token");
const index = tokenTools.tools.findIndex(b => b.name === SETTINGS.PREFER_TOKEN_CONTROL);
const index = tokenTools.tools.findIndex(b => b.name === SETTINGS.PREFER_TOKEN_ELEVATION);
if ( enable && !~index ) tokenTools.tools.push(PREFER_TOKEN_CONTROL);
else if ( ~index ) tokenTools.tools.splice(index, 1);
PREFER_TOKEN_CONTROL.active = getSetting(SETTINGS.PREFER_TOKEN_ELEVATION_CURRENT_VALUE);
ui.controls.render(true);
}

15 changes: 14 additions & 1 deletion scripts/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const SETTINGS = {
UI_ONLY: "levels-labels-ui",
ALWAYS: "levels-labels-always"
},
NO_MODS: "no-modules-message"
NO_MODS: "no-modules-message",
PREFER_TOKEN_ELEVATION_CURRENT_VALUE: "prefer-token-elevation-current-value"
};

const KEYBINDINGS = {
Expand All @@ -31,6 +32,10 @@ export function getSetting(settingName) {
return game.settings.get(MODULE_ID, settingName);
}

export async function setSetting(settingName, value) {
await game.settings.set(MODULE_ID, settingName, value);
}

export function registerSettings() {
log("Registering settings.");

Expand Down Expand Up @@ -102,6 +107,14 @@ export function registerSettings() {
onChange: reloadTokenControls
});

game.settings.register(MODULE_ID, SETTINGS.PREFER_TOKEN_ELEVATION_CURRENT_VALUE, {
scope: "user",
config: false,
default: false,
type: Boolean,
requiresReload: false
});

log("Done registering settings.");
}

Expand Down
7 changes: 6 additions & 1 deletion scripts/terrain_elevation.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,13 @@ function EVElevationAtPoint(location, measuringToken, startingElevation = 0) {

// Location may or may not be correct, depending on above.
// Use positive infinity for elevation so that all tiles can be found
// MAX_SAFE_INTEGER needed b/c a finite elevation is required.
EVCalc.location = location;
EVCalc.elevation = isFinite(startingElevation) ? startingElevation : Number.POSITIVE_INFINITY;
EVCalc.elevation = isFinite(startingElevation) ? startingElevation : Number.MAX_SAFE_INTEGER;
if ( !measuringToken ) {
EVCalc.options.tileStep = Number.POSITIVE_INFINITY;
EVCalc.options.terrainStep = Number.POSITIVE_INFINITY;
}

return EVCalc.groundElevation();
}
Expand Down

0 comments on commit aecb898

Please sign in to comment.