Skip to content

Commit

Permalink
Merge branch 'release/0.6.6' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
caewok committed Aug 21, 2023
2 parents 81f1caf + 8548d2d commit 8c386c7
Show file tree
Hide file tree
Showing 10 changed files with 144 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.6
Add setting to hide template border or highlighting. Closes issue #43.
Fix for sequencer animations of rectangle shapes. Closes issue #44.

## 0.6.5
Fix for template attaching not working in SWADE, possibly other systems. Closes issue #35.
Fix for midi no-targe flag. Closes issue #37.
Expand Down
6 changes: 6 additions & 0 deletions languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,12 @@
"walledtemplates.settings.diagonal-scaling-rect.Name": "Unused: Diagonal Scaling Rect",
"walledtemplates.settings.diagonal-scaling-rect.Hint": "Unused",

"walledtemplates.settings.hideBorder.Name": "Hide template border",
"walledtemplates.settings.hideBorder.Hint": "Unless hovering over the template control icon, do not show the outline of the template shape.",

"walledtemplates.settings.hideHighlighting.Name": "Hide template highlighting",
"walledtemplates.settings.hideHighlighting.Hint": "Unless hovering over the template control icon, do not show the highlighted grid for the template.",

"walledtemplates.controls.autotarget.Title": "Autotarget tokens with template",

"walledtemplates.notifications.attach-last-selected-token": "Please select a token to attach.",
Expand Down
57 changes: 55 additions & 2 deletions scripts/MeasuredTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,23 @@ async function destroyMeasuredTemplateHook(template) {
await template.detachToken();
}

/**
* Hook hoverMeasuredTemplate to trigger template hiding
* @param {MeasuredTemplate} template
* @param {boolean} hovering
*/
function hoverMeasuredTemplateHook(template, hovering) {
if ( getSetting(SETTINGS.HIDE.BORDER) ) template.renderFlags.set({ refreshTemplate: true });
if ( getSetting(SETTINGS.HIDE.HIGHLIGHTING) ) template.renderFlags.set({ refreshGrid: true });
}


PATCHES.BASIC.HOOKS = {
refreshMeasuredTemplate: refreshMeasuredTemplateHook,
preCreateMeasuredTemplate: preCreateMeasuredTemplateHook,
updateMeasuredTemplate: updateMeasuredTemplateHook,
destroyMeasuredTemplate: destroyMeasuredTemplateHook
destroyMeasuredTemplate: destroyMeasuredTemplateHook,
hoverMeasuredTemplate: hoverMeasuredTemplateHook
};

// ----- NOTE: Wraps ----- //
Expand Down Expand Up @@ -175,8 +187,48 @@ function clone(wrapped) {
return clone;
}

/**
* Mixed wrap of MeasuredTemplate.prototype.highlightGrid
* If the setting is set to hide, don't highlight grid unless hovering.
*/
function highlightGrid(wrapped) {
const interactionState = this._original?.mouseInteractionManager?.state ?? this.mouseInteractionManager?.state;
if ( !this.visible
|| this.hover
|| typeof interactionState === "undefined"
|| interactionState === MouseInteractionManager.INTERACTION_STATES.DRAG
|| !getSetting(SETTINGS.HIDE.HIGHLIGHTING) ) return wrapped();

// Clear the existing highlight layer
const grid = canvas.grid;
const hl = grid.getHighlightLayer(this.highlightId);
hl.clear();
return;
}

/**
* Mixed wrap of MeasuredTemplate.prototype._refreshTemplate
* If the setting is set to hide, don't draw the border.
*/
function _refreshTemplate(wrapped) {
const interactionState = this._original?.mouseInteractionManager?.state ?? this.mouseInteractionManager?.state;
if ( this.hover
|| typeof interactionState === "undefined"
|| interactionState === MouseInteractionManager.INTERACTION_STATES.DRAG
|| !getSetting(SETTINGS.HIDE.BORDER) ) return wrapped();

// Clear the existing layer and draw the texture but not the outline or origin/destination points.
const t = this.template.clear();

// Fill Color or Texture
if ( this.texture ) t.beginTextureFill({texture: this.texture});
else t.beginFill(0x000000, 0.0);

// Draw the shape
t.drawShape(this.shape);
}

PATCHES.BASIC.MIXES = { _getGridHighlightPositions };
PATCHES.BASIC.MIXES = { _getGridHighlightPositions, highlightGrid, _refreshTemplate };

// ----- Autotarget Wraps ----- //

Expand Down Expand Up @@ -395,6 +447,7 @@ PATCHES.BASIC.GETTERS = { attachedToken, wallsBlock };
*/
function refreshMeasuredTemplateHook(template, flags) {
if ( flags.retarget && template.autotargetTokens ) template.autotargetTokens();
if ( flags.refreshTemplate ) template._refreshTemplate();
}

PATCHES.AUTOTARGET.HOOKS = { refreshMeasuredTemplate: refreshMeasuredTemplateHook };
Expand Down
10 changes: 10 additions & 0 deletions scripts/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ Hooks.once("ready", () => {
templates have an elevation configuration now—--I am considering options to provide some handling of 3d templates.`
})

.addEntry({
version: "0.6.6",
title: "Template hiding",
body: `\
The GM can now hide template highlighting or template borders in the game settings.
Hovering over the template control icon will still show the highlighting and border. Animations
continue to display regardless of this setting. This is mostly intended to facilitate better-looking
animations used with templates. Thanks to @TMinz for the idea!`
})

.build()
?.render(true);
});
Expand Down
4 changes: 4 additions & 0 deletions scripts/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const FLAGS = {
DELTAS: "attachedTokenDelta",
SPELL_TEMPLATE: "attachToken"
},
HIDE: {
BORDER: "hideBorder",
HIGHLIGHTING: "hideHighlighting"
},
HEIGHT_ALGORITHM: "heightAlgorithm",
HEIGHT_CUSTOM_VALUE: "heightCustomValue",
HEIGHT_TOKEN_OVERRIDES: "attachedTokenOverridesHeight"
Expand Down
6 changes: 5 additions & 1 deletion scripts/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Hooks.once("init", function() {
CONFIG.MeasuredTemplate.objectClass.RENDER_FLAGS.refresh.propagate = ["refreshState", "refreshPosition"];
CONFIG.MeasuredTemplate.objectClass.RENDER_FLAGS.refreshShape.propagate = ["refreshGrid", "refreshText"];
CONFIG.MeasuredTemplate.objectClass.RENDER_FLAGS.refreshPosition.propagate = ["retarget", "refreshShape"];
CONFIG.MeasuredTemplate.objectClass.RENDER_FLAGS.refreshTemplate = {};

// Tell modules that the module is set up
Hooks.callAll(`${MODULE_ID}Ready`);
Expand Down Expand Up @@ -148,7 +149,10 @@ Hooks.once("ready", async function() {
promises.push(t.document.setFlag(MODULE_ID, FLAGS.WALLS_BLOCK, enabled
? SETTINGS.DEFAULT_WALLS_BLOCK.CHOICES.WALLED : SETTINGS.DEFAULT_WALLS_BLOCK.CHOICES.UNWALLED));
} else {
promises.push(t.document.setFlag(MODULE_ID, FLAGS.WALLS_BLOCK, getSetting(SETTINGS.DEFAULT_WALLS_BLOCK[shape])));
promises.push(t.document.setFlag(
MODULE_ID,
FLAGS.WALLS_BLOCK,
getSetting(SETTINGS.DEFAULT_WALLS_BLOCK[shape])));
}
}

Expand Down
27 changes: 27 additions & 0 deletions scripts/settings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* globals
canvas,
game
*/
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
Expand All @@ -14,6 +15,10 @@ export const SETTINGS = {
DEFAULT_WALL_RESTRICTION: {},
DIAGONAL_SCALING: {},
AUTOTARGET: {},
HIDE: {
BORDER: "hideBorder",
HIGHLIGHTING: "hideHighlighting"
},
CHANGELOG: "changelog"
};

Expand Down Expand Up @@ -138,6 +143,26 @@ export function registerSettings() {
config: true
});

game.settings.register(MODULE_ID, SETTINGS.HIDE.BORDER, {
name: game.i18n.localize(`${MODULE_ID}.settings.${SETTINGS.HIDE.BORDER}.Name`),
hint: game.i18n.localize(`${MODULE_ID}.settings.${SETTINGS.HIDE.BORDER}.Hint`),
type: Boolean,
default: false,
scope: "world",
config: true,
onChange: _value => canvas.templates.placeables.forEach(t => t.renderFlags.set({ refreshTemplate: true }))
});

game.settings.register(MODULE_ID, SETTINGS.HIDE.HIGHLIGHTING, {
name: game.i18n.localize(`${MODULE_ID}.settings.${SETTINGS.HIDE.HIGHLIGHTING}.Name`),
hint: game.i18n.localize(`${MODULE_ID}.settings.${SETTINGS.HIDE.HIGHLIGHTING}.Hint`),
type: Boolean,
default: false,
scope: "world",
config: true,
onChange: _value => canvas.templates.placeables.forEach(t => t.renderFlags.set({ refreshGrid: true }))
});

for ( const shape of SHAPE_KEYS ) {
game.settings.register(MODULE_ID, SETTINGS.DEFAULT_WALLS_BLOCK[shape], {
name: game.i18n.localize(`${MODULE_ID}.settings.${SETTINGS.DEFAULT_WALLS_BLOCK[shape]}.Name`),
Expand Down Expand Up @@ -177,6 +202,8 @@ export function registerSettings() {
scope: "world",
config: false
});


}

log("Done registering settings.");
Expand Down
13 changes: 13 additions & 0 deletions scripts/template_shapes/WalledTemplateCircle.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@ export class WalledTemplateCircle extends WalledTemplateShape {

return [new this.constructor(this.template, opts)];
}

/**
* Compute the shape to be used for this template.
* Output depends on the specific template settings.
* @returns {PIXI.Polygon|PIXI.Circle}
*/
computeShape() {
const shape = super.computeShape();

// Set values that Sequencer or other modules may use.
shape.radius ??= this.distance;
return shape;
}
}

// NOTE: Set the recursion types to spread or reflect, accordingly.
Expand Down
17 changes: 17 additions & 0 deletions scripts/template_shapes/WalledTemplateRectangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,23 @@ export class WalledTemplateRectangle extends WalledTemplateCircle {
return rect.toPolygon().translate(delta.x, delta.y);
}

/**
* Compute the shape to be used for this template.
* Output depends on the specific template settings.
* @returns {PIXI.Polygon|PIXI.Circle}
*/
computeShape() {
const shape = super.computeShape();

// Set values that Sequencer or other modules may use from the rectangle.
if ( !shape.width || !shape.height ) {
const origShape = this.originalShape;
shape.width ??= origShape.width;
shape.height ??= origShape.height;
}
return shape;
}

/**
* Generate a new RectangleTemplate based on spreading from a designated corner.
* @param {PIXI.Point} corner
Expand Down
7 changes: 3 additions & 4 deletions scripts/template_shapes/WalledTemplateShape.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,9 @@ export class WalledTemplateShape {
return this.originalShape;
}

// Set values that may be used by other modules
poly.x ??= this.originalShape.x;
poly.y ??= this.originalShape.y;
poly.radius ??= this.originalShape.radius;
// Set origin, which may be used by other modules
poly.x ??= this.origin.x;
poly.y ??= this.origin.y;
return poly;
}

Expand Down

0 comments on commit 8c386c7

Please sign in to comment.