Feu-Secret / Tokenmagic

A Foundry VTT module that allows you to add animations and graphic effects to tokens, tiles, templates and drawings.
GNU General Public License v3.0
51 stars 36 forks source link

Feature: Better compatibility with Walled Templates module #265

Open caewok opened 4 months ago

caewok commented 4 months ago

Hi! I am the dev for the Walled Templates module. There are some incompatibilities between our two modules when it comes to displaying/hiding templates.

Walled Templates allows the GM to hide or display the template highlight grid and the template border separately. Each shape has a default "hide" setting, but that can be overridden on a per-template basis. In dnd5e, spells can pass these settings through to template creation because I added some drop-down selections to the spell configuration.

I am seeing at least two incompatibilities with Token Magic that I cannot fix on my end. (1) There is flickering related to the template alpha setting. While WT will respect the TM alpha setting, it seems that TM does not set the template alpha soon enough on a template refresh, causing a flicker as the template is briefly drawn with full alpha. (2) WT cannot hide the template border if Token Magic is active. I think this is irregardless of the TM setting for template hiding.

Walled Templates sets template hiding in the MeasuredTemplate refresh hook. Most of the tests are in the helper function, canHideTemplateComponent.

The basic approach is:

  1. Border and template visibility: To hide the border, set template.ruler.visible to false and change template.template.alpha to 0. I don't set visibliity of the template because that would cause automated animations to not display.
  2. Highlight visibility: To hide the highlight grid, set the canvas.grid.getHighlightLayer(template.highlightId).alpha to 0.

Because I am completely hiding the template (given the right settings) I allow the control icon to be visible to non-owners in certain situations.

Walled Templates uses flags on the template to indicate when it should be hidden, although there is some logic to it as well based on the user privileges and where the cursor is located. (For example, there is a setting to unhide the template when hovering over a token within the template.)

I am open to suggestions for how to improve compatibility here. I noticed that you use several libWrapper methods, which I don't think is strictly necessary for template hiding (although it surely is necessary for other things that Token Magic is doing).

caewok commented 4 months ago

FYI, if you don't want to support template hiding anymore, you could take that code out of Token Magic and just direct users to my Walled Templates module for that feature. In its default settings, Walled Templates should act like normal Foundry templates, and so it should be possible for a user to only use the template hiding features. Near as I can tell, Walled Templates is otherwise compatible with Token Magic.