Skip to content

[#6763] Implement TemplatePlacement to replace AbilityTemplate#6778

Open
arbron wants to merge 6 commits into5.3.xfrom
template-placement
Open

[#6763] Implement TemplatePlacement to replace AbilityTemplate#6778
arbron wants to merge 6 commits into5.3.xfrom
template-placement

Conversation

@arbron
Copy link
Collaborator

@arbron arbron commented Feb 26, 2026

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

Copy link
Contributor

@dev7355608 dev7355608 left a comment

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
Copy link
Collaborator Author

arbron commented Mar 4, 2026

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
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
Copy link
Collaborator Author

arbron commented Mar 4, 2026

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
Copy link
Contributor

krbz999 commented Mar 4, 2026

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

@dev7355608
Copy link
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 added 6 commits March 19, 2026 10:08
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 494ddb3 to e0507eb Compare March 19, 2026 17: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

3 participants