Skip to content

[#6763] Implement TemplatePlacement to replace AbilityTemplate#6778

Merged
arbron merged 9 commits into
6.0.xfrom
template-placement
Jun 19, 2026
Merged

[#6763] Implement TemplatePlacement to replace AbilityTemplate#6778
arbron merged 9 commits into
6.0.xfrom
template-placement

Conversation

@arbron

@arbron arbron commented Feb 26, 2026

Copy link
Copy Markdown
Collaborator

Adds a new dnd5e.canvas.TemplatePlacement API to handle placing shapes within a scene. This base API deals with basic shape data but the fromActivity factory method behaves similar to the old method on AbilityTemplate to create a full measured template region.

The created regions are set up to work as similar as possible to the old measured templates, using coverage highlight mode and the user's color. When the area of effect count is larger than one, all of the shapes are combined into a single measured template.

TokenPlacement has been refactored and much of its code has been shifted into a new BasePlacement class that is shared between the two canvas placement systems.

Closes #6763

@dev7355608 dev7355608 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason that we don't use the new RegionLayer#placeRegion API?

@arbron

arbron commented Mar 4, 2026

Copy link
Copy Markdown
Collaborator Author

What is the reason that we don't use the new RegionLayer#placeRegion API?

We need to support placing more than one shape at a time would be the big one. I also have plans for adding additional UI that is shared with our token placement system.

@dev7355608

Copy link
Copy Markdown
Contributor

Could you write up a feature request for the limitations you currently facing with RegionLayer#placeRegion. It would be undesirable for us if dnd5e and other systems couldn't use RegionLayer#placeRegion and needed to reimplement most of the placement workflow.

@arbron

arbron commented Mar 4, 2026

Copy link
Copy Markdown
Collaborator Author

Could you write up a feature request for the limitations you currently facing with RegionLayer#placeRegion. It would be undesirable for us if dnd5e and other systems couldn't use RegionLayer#placeRegion and needed to reimplement most of the placement workflow.

These cover much of it:

But I will say our implementation also shares a bunch of the internals with our TokenPlacement API which currently has no equivalent in core, so sharing those internals rather than having one base based on placeRegion probably makes more sense for us.

There are also other features for placement restriction/guidance that might not make sense in core:

  • Range limits/display from caster
  • Line of sight placement restriction
  • Limit placement to grid intersections
  • Locking template origins to the casting token (e.g. lines start at edge of caster's token and should only go out)
  • UI displaying number of templates or tokens placed and number still to go

@krbz999

krbz999 commented Mar 4, 2026

Copy link
Copy Markdown
Contributor

At least one of those are mentioned in foundryvtt/foundryvtt#9840

@dev7355608

Copy link
Copy Markdown
Contributor

There are also other features for placement restriction/guidance that might not make sense in core:

  • Range limits/display from caster
  • Line of sight placement restriction
  • Limit placement to grid intersections
  • Locking template origins to the casting token (e.g. lines start at edge of caster's token and should only go out)
  • UI displaying number of templates or tokens placed and number still to go

The options preConfirm, onMove, and onRotate of RegionLayer#placeRegion should make this possible to implement such behaviors.

@arbron arbron force-pushed the template-placement branch 3 times, most recently from 7335281 to 54aa781 Compare March 12, 2026 22:21
@arbron arbron force-pushed the template-placement branch from 494ddb3 to e0507eb Compare March 19, 2026 17:13
@arbron arbron changed the base branch from 5.3.x to 6.0.x June 2, 2026 17:42
@arbron arbron force-pushed the template-placement branch from e0507eb to 65395d1 Compare June 2, 2026 17:47

@Fyorl Fyorl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good simplification. Seem to have lost the handling for gridAlignedSquareTemplates.

Comment thread module/canvas/api/base-placement.mjs
Comment thread module/canvas/template-placement.mjs Outdated
* @param {TemplatePlacementConfiguration} placementConfig Configuration that drives template placement.
* @returns {boolean} Return `false` to prevent template placement.
*/
if ( Hooks.call("dnd5e.preCreateMeasuredTemplate", activity, config) === false ) return null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createActivityTemplate was the hook we were using before. Did we mean to change it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it because the config data here is very different than the templateData data we used in the original hook. Same with the post hooks which have region data as their second argument rather than measured templates.

Comment thread module/canvas/template-placement.mjs Outdated
arbron added 8 commits June 19, 2026 11:05
Adds a new `dnd5e.canvas.TemplatePlacement` API to handle placing
shapes within a scene. This base API deals with basic shape data
but the `fromActivity` factory method behaves similar to the old
method on `AbilityTemplate` to create a full measured template
region.

The created regions are set up to work as similar as possible to
the old measured templates, using `coverage` highlight mode and
the user's color. When the area of effect count is larger than one,
all of the shapes are combined into a single measured template.

`TokenPlacement` has been refactored and much of its code has been
shifted into a new `BasePlacement` class that is shared between the
two canvas placement systems.

Closes #6763
Rewrites both placement APIs to rely on core's `placeToken` and
`placeRegion` mathods rather than a new implementation. Removes
`BasePlacement` since there is no longer much shared code.
Finds all applications that are not minimized, have a frame, and
are not detached and minimizes them until placement is completed.
This behavior can be disabled using the `minimizeWindows` option
in the placement configuration.

Also adds a `restoreLayer` option to the configuration to control
whether the original canvas layer is made active after placement.
Both of these options are enabled by default.

Closes #6763
@arbron arbron force-pushed the template-placement branch from 65395d1 to e222c9e Compare June 19, 2026 18:06
@arbron arbron requested a review from Fyorl June 19, 2026 18:06
Comment thread module/canvas/token-placement.mjs Outdated
@arbron arbron merged commit 57d217b into 6.0.x Jun 19, 2026
@arbron arbron deleted the template-placement branch June 19, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api compatibility Relating to compatibility issues with new core versions priority: high system: canvas Vision modes and scene interaction

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Re-write AbilityTemplate as new TemplatePlacement mirroring TokenPlacement

4 participants