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

Not working for hex grids #335

Open
BoltsJ opened this issue Jul 28, 2024 · 0 comments
Open

Not working for hex grids #335

BoltsJ opened this issue Jul 28, 2024 · 0 comments

Comments

@BoltsJ
Copy link
Contributor

BoltsJ commented Jul 28, 2024

Foundry V12 greatly improves support for hex grids, including adding support arbitrarily large hex tokens and non-symmetrical hex token shapes. Various changes relevant to this module are:

  1. The "center" of the token now falls on a hex vertex or edge midpoint for some shapes if it doesn't align to the center of a hex.
  2. There is native support for alternate orientations and more shape types. The old foundry behavior is now "Ellipse (Variant 1)" for most tokens and "Ellipse (Ellipse 2)" for the old 2×2 behavior, with variant 1 generally being the standard orientation and variant 2 being alt orientation is hex-size-support terms.
  3. Snapping for all sizes in now handled directly by the grid correctly for all hex orientations and sizes. Snapping can be accessed for a canvas object such as a token via its getSnappedPosition method, which take a point corresponding to the token's topleft and returns that point snapped to the grid correctly for the parameters of the token.
  4. There are two additional shape types, Trapezoid and Rectangle, each having 2 orientation variants.
    image
  5. The aforementioned support for arbitrarily sized hex tokens. The token class now has an (internal IIRC) method to get the border polygon for a token based on size parameters.
  6. Internally, the hex grid is now properly tessellated hexagons instead of alternately offset rectangle "bricks". This means that the topleft point of a cell can't be directly translated back to a center point as it lies inside a different hex now.

Generally, these changes allow for modules to have a much lighter touch on hex grids. Hex Token Size Support (soon to become Token Border Supplements) in fact no longer makes any changes to tokens on hex grids outside of its border style changes and the optional hotkey to swap orientation variants.

Currently the module has severe issues with snapping on hex grids. Nearly every hex shape other than odd × odd elliptical tokens snaps incorrectly, size 2 being the worst offender. Additionally, moving a token on a hex scene can cause hundreds of deprecation warnings to fill the console.
image

For references, this is the HSS v12 isAltOrientation function: https://github.com/BoltsJ/hex-size-support/blob/4.x/v12-fixes/src/modules/grid.js
It's not used anywhere internally by HSS, and I'll probably end up removing it.
And here is code I wrote for Lancer to get an arbitrary sized n × n hex: https://github.com/Eranziel/foundryvtt-lancer/blob/27cca45fd5c4230cc6dcd376045aa68495523edc/src/module/token.ts#L13-L56
It doesn't cover the unusual shapes but it gets a majority of what people are using. In the past, this function tested points against the token shape to find the the spaces, however when computing many tokens simultaneously, there was a performance impact from calling pixi functions. A similar approach may be feasible in v12 with less of a performance hit now that token geometry is exposed publicly on Token#shape.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant