diff --git a/Changelog.md b/Changelog.md index 1f67f94..f640ce7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,10 @@ -## 0.7.7 +## 0.7.8 +Catch when a template shape is undefined or incorrectly defined such that it does not have a `getBounds` method. Avoids `getBounds` undefined error that may be related to TokenMagic module. +When unhiding a template, set template alpha to the TokenMagic alpha setting for the template if that module is active and the flag is present. Closes #110. +When checking if a template should be hidden, hide the template if TokenMagic is active and the template is set to observe global defaults and TokenMagic setting is set to hide the template. +The template shape is now set to top/bottom elevation of the template elevation, so that Wall Height walls not within the elevation of the template do not block. Closes in part #100. +## 0.7.7 Provide `MeasuredTemplate.prototype.targetsWithinShape` method at all times, not just when autotargeting is enabled. Closes #104. Don't refresh targeting on a template not owned by the current user, to avoid refreshing targets incorrectly. Closes #105. diff --git a/scripts/ClockwiseSweepLightWall.js b/scripts/ClockwiseSweepLightWall.js index ea847bc..bec0eee 100644 --- a/scripts/ClockwiseSweepLightWall.js +++ b/scripts/ClockwiseSweepLightWall.js @@ -162,7 +162,7 @@ export class LightWallSweep extends ClockwiseSweepShape { if ( Math.sign(foundry.utils.orient2dFast(a, b, wall.A)) === exclusionarySide && Math.sign(foundry.utils.orient2dFast(a, b, wall.B)) === exclusionarySide ) return false; - if ( (lightWall.id && wall.id === lightWall.id)|| !super._testWallInclusion(wall, bounds) ) return false; + if ( (lightWall.id && wall.id === lightWall.id) || !super._testWallInclusion(wall, bounds) ) return false; return !exclusionaryTriangle.lineSegmentIntersects(wall.A, wall.B, { inside: true }); } } diff --git a/scripts/MeasuredTemplate.js b/scripts/MeasuredTemplate.js index 4d83d30..78c1052 100644 --- a/scripts/MeasuredTemplate.js +++ b/scripts/MeasuredTemplate.js @@ -11,7 +11,7 @@ PIXI import { WalledTemplateShape } from "./template_shapes/WalledTemplateShape.js"; import { log, gridShapeForTopLeft, tokenBounds } from "./util.js"; -import { MODULE_ID, FLAGS } from "./const.js"; +import { MODULE_ID, FLAGS, MODULES } from "./const.js"; import { Settings } from "./settings.js"; import { Square } from "./geometry/RegularPolygon/Square.js"; import { UserCloneTargets } from "./UserCloneTargets.js"; @@ -54,7 +54,10 @@ function canHideTemplateComponent(template, hideFlag) { // Check for per-template setting. const TYPES = HIDE.TYPES; const local = template.document.getFlag(MODULE_ID, HIDE[hideFlag]); - if ( !local || local === TYPES.GLOBAL_DEFAULT ) return Settings.get(Settings.KEYS.HIDE[hideFlag]); + if ( !local || local === TYPES.GLOBAL_DEFAULT ) { + if ( MODULES.TOKEN_MAGIC.ACTIVE ) return game.settings.get('tokenmagic', 'autohideTemplateElements'); + return Settings.get(Settings.KEYS.HIDE[hideFlag]); + } return (local === TYPES.ALWAYS); } @@ -72,12 +75,13 @@ function refreshMeasuredTemplate(template, flags) { // Control the border visibility including border text. if ( flags.refreshTemplate || flags.refreshState ) { + log(`refreshMeasuredTemplate|template alpha ${template.template.alpha}`); if ( canHide && canHideTemplateComponent(template, "BORDER") ) { template.template.alpha = 0; // Don't mess with visible to fool automated animations into displaying. // This doesn't work: template.template.visible = false; template.ruler.visible = false; } else { - template.template.alpha = 1; + template.template.alpha = MODULES.TOKEN_MAGIC.ACTIVE ? (template.document.getFlag(MODULES.TOKEN_MAGIC.ID, "templateData")?.opacity ?? 1) : 1; // This doesn't work: template.template.visible = true; template.ruler.visible = true; } @@ -86,6 +90,7 @@ function refreshMeasuredTemplate(template, flags) { // Control the highlight visibility by changing its alpha. if ( flags.refreshGrid || flags.refreshState ) { const hl = canvas.grid.getHighlightLayer(template.highlightId); + log(`refreshMeasuredTemplate|highlight layer alpha ${hl.alpha}`); if ( canHide && canHideTemplateComponent(template, "HIGHLIGHTING") ) hl.alpha = 0; else hl.alpha = template.document.hidden ? 0.5 : 1; } @@ -472,6 +477,8 @@ PATCHES.BASIC.WRAPS = { * @return {Boolean} */ function boundsOverlap(bounds) { + if ( !this.shape?.getBounds ) return false; // Issue #110. + const tBounds = bounds.translate(-this.x, -this.y); if ( Settings.autotargetMethod(this.document.t) === Settings.KEYS.AUTOTARGET.METHODS.CENTER ) { diff --git a/scripts/const.js b/scripts/const.js index 7ac6c7f..b60ee68 100644 --- a/scripts/const.js +++ b/scripts/const.js @@ -108,11 +108,13 @@ export const ACTIVE_EFFECT_ICON = `modules/${MODULE_ID}/assets/ruler-combined-so export const SHAPE_KEYS = ["circle", "cone", "ray", "rect"]; -export const MODULES_ACTIVE = { - DRAG_RULER: false +export const MODULES = { + DRAG_RULER: { ACTIVE: false, ID: "drag-ruler" }, + TOKEN_MAGIC: { ACTIVE: false, ID: "tokenmagic" } }; // Hook init b/c game.modules is not initialized at start. Hooks.once("init", function () { - MODULES_ACTIVE.DRAG_RULER = game.modules.get("drag-ruler")?.active; + MODULES.DRAG_RULER.ACTIVE = game.modules.get(MODULES.DRAG_RULER.ID)?.active; + MODULES.TOKEN_MAGIC.ACTIVE = game.modules.get(MODULES.TOKEN_MAGIC.ID)?.active; }); diff --git a/scripts/template_shapes/WalledTemplateShape.js b/scripts/template_shapes/WalledTemplateShape.js index 3b9555a..2d8b2a4 100644 --- a/scripts/template_shapes/WalledTemplateShape.js +++ b/scripts/template_shapes/WalledTemplateShape.js @@ -244,12 +244,12 @@ export class WalledTemplateShape { // Default to treating template as infinite in vertical directions // Do this after initialization b/c something is flipping them around. Likely Wall Height. cfg.source.object ??= {}; - cfg.source.object.b ??= Number.POSITIVE_INFINITY; - cfg.source.object.t ??= Number.NEGATIVE_INFINITY; + cfg.source.object.b = this.template.elevationE; + cfg.source.object.t = this.template.elevationE; // Need to also set origin, for reasons. - this.origin.b = Number.POSITIVE_INFINITY; - this.origin.t = Number.NEGATIVE_INFINITY; + this.origin.b = this.template.elevationE; + this.origin.t = this.template.elevationE; let sweepClass = this.sweepClass; if ( sweepClass === LightWallSweep && !this.options.lastReflectedEdge) sweepClass = ClockwiseSweepShape;