Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass zones to templates so they don't have to look them up #4753

Conversation

kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented Apr 12, 2024

Identify the Bug or Feature request

Fixes #4524
Fixes #4527

Description of the Change

The main idea with this change is to fix #4527 by passing a Zone to templates rather than requiring them to look the zone up themselves. This is done by adding a Zone parameter to these Drawable methods, and other related methods:

  • draw()
  • getBounds()
  • getArea()

Regular drawings ignore the new parameter, but templates require it in order to scale properly without relying on global state.

There were some remaining zone lookups in RadiusCellTemplate, BlastTemplate, and BurstTemplate. These all delegated to a ShapeDrawable as a renderer, and keeping that renderer in sync with the template state required knowledge of the zone when modifying the template. But these renderer did not add any value to these templates -- RadiusCellTemplate didn't use its renderer, while BlastTemplate and BurstTemplate were just as well to draw their own shape. Removing these and the need for maintaining extra state is the resolution to #4524.

With those changes done, templates no longer require their zone ID in any way. So that is now removed from AbstractTemplate and the associated DTOs. This simplifies other parts of the code (e.g., Zone deserialization) as we don't have to worry about updating template zone IDs.

Possible Drawbacks

Should be none.

Documentation Notes

N/A

Release Notes

  • Fixed a bug where burst and blast templates would not scale when changing the the map grid size.
  • Fixed a bug where templates would disappear if duplicated to another map and then the duplicate was deleted.

This change is Reviewable

@kwvanderlinde kwvanderlinde force-pushed the bugfix/4524-4527-disappearing-and-non-scaling-templates branch from d03f5b5 to 34525c5 Compare April 15, 2024 22:23
@cwisniew cwisniew added this pull request to the merge queue Apr 16, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Apr 16, 2024
Corresponding changes to made to `AbstractDrawing.draw()`, `AbstractDrawing.drawBackground()`, and
`AbstractTemplate.paint()`.
Most uses of this method would fail if they encountered a null value, and very few implementations were able to return
null. The few null cases were easily replaced with empty areas instead.
Implementations have access to the zone through `renderer` or `getZone()`, and the passed ID always comes from there as
well.

In a related change, FOW expose tool implementations no longer look up the global current zone renderer. Instead they
just use the renderer that the tool is attached to.
These weren't actually used for anything, but were still being kept up-to-date on vertex and radius changes. With them
gone, we no longer need `adjustShape()` or the overrides for `setRadius()` and `setVertex()`.
This renderer was still in use, but it adds some unnecessary constraints to BlastTemplate. Mainly the issue is that it
had to modify the renderer's shape, and had to override `draw()`/`drawBackground()` instead of the `paint()` method
whichi is more idiomatic for templates.

Now we don't even bother keeping a shape up-to-date as we just create a new rectangle whenever it is needed. This is not
expensive at all, especially compared to what some other templates have to do.
Similar to BlastTemplate, now we make our own shape on demand.
Now that zones are passed via methods, the templates don't use the zone ID for any real functionality anymore. Removing
it cleans up a bunch of code, and avoids the need to make sure that templates have their zone IDs updated in various
case.
@kwvanderlinde kwvanderlinde force-pushed the bugfix/4524-4527-disappearing-and-non-scaling-templates branch from 34525c5 to 1ca8cc9 Compare April 16, 2024 13:17
@kwvanderlinde
Copy link
Collaborator Author

Fixed the merge conflicts.

@cwisniew cwisniew added this pull request to the merge queue Apr 17, 2024
Merged via the queue into RPTools:develop with commit 41479b0 Apr 17, 2024
4 checks passed
@kwvanderlinde kwvanderlinde deleted the bugfix/4524-4527-disappearing-and-non-scaling-templates branch April 17, 2024 03:15
@kwvanderlinde kwvanderlinde self-assigned this Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment