Skip to content

Commit

Permalink
Merge branch 'release/0.7.8' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Apr 28, 2024
2 parents c0a9d63 + 167faa6 commit d300b4a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 12 deletions.
7 changes: 6 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
2 changes: 1 addition & 1 deletion scripts/ClockwiseSweepLightWall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
}
}
13 changes: 10 additions & 3 deletions scripts/MeasuredTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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 ) {
Expand Down
8 changes: 5 additions & 3 deletions scripts/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
8 changes: 4 additions & 4 deletions scripts/template_shapes/WalledTemplateShape.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit d300b4a

Please sign in to comment.