-
Notifications
You must be signed in to change notification settings - Fork 231
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
[#893] Add system for selecting summoning placement #3235
Conversation
fe71c7f
to
7242a0a
Compare
7242a0a
to
89a54f2
Compare
The `TokenPlacement` class right now is small and only delegates to the `TokenPlacementTemplate` which is responsible for rendering and returning placement information. With the V12 improvements to placeables hopefully we'll be able to shift more logic out of the `MeasuredTemplate` subclass and into the `TokenPlacement` class. The `TokenPlacementConfiguration` data structure currently just includes the prototype token information, but will eventually have quantity, origin, and range values to handle multiple summons and restricting range from the summoner. Works with tokens of any size or scale on the square grid. On hex grids, it handles 1x1 tokens pretty good with only a bit of offset on the final token placement. Stranger token sizes lead to some issues with positioning, but I'm not sure how important those are to fix before the other grid improvements in V12.
0e1fa23
to
5b0c07f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please see my comments, but this looks great.
#getSnapAdjustment(token) { | ||
const size = canvas.dimensions.size; | ||
switch ( canvas.grid.type ) { | ||
case CONST.GRID_TYPES.SQUARE: | ||
return { | ||
x: token.width % 2 === 0 ? Math.round(size * 0.5) : 0, | ||
y: token.height % 2 === 0 ? Math.round(size * 0.5) : 0 | ||
}; | ||
default: | ||
return { x: 0, y: 0 }; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should be able to use canvas.grid.getSnappedPosition
(getSnappedPoint
in v12) for this. I don't think we need to handle this ourselves.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find that using getSnappedPosition
works fine for 1x1 tokens, but results in larger or stranger shaped tokens being offset in rather than centered under the token. I tried this:
const center = canvas.grid.getSnappedPosition(
point.x - Math.round(canvas.dimensions.size * 0.5),
point.y - Math.round(canvas.dimensions.size * 0.5),
1,
{ token: this.config.tokens[0].object }
);
For 2x2 tokens for example, this would result in the token being places with the top-left quarter centered over the square that I am hovering which makes it non-intuitive where to move the mouse to place the token.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's fair enough. I think this has all been improved in v12 so I will experiment with checking game.release
here and calling getSnappedPoint
instead, but this seems good enough for now.
5b0c07f
to
ad057a7
Compare
The
TokenPlacement
class right now is small and only delegates to theTokenPlacementTemplate
which is responsible for rendering and returning placement information. With the V12 improvements to placeables hopefully we'll be able to shift more logic out of theMeasuredTemplate
subclass and into theTokenPlacement
class.The
TokenPlacementConfiguration
data structure currently just includes the prototype token information, but will eventually have quantity, origin, and range values to handle multiple summons and restricting range from the summoner.Works with tokens of any size or scale on the square grid. On hex grids, it handles 1x1 tokens pretty good with only a bit of offset on the final token placement. Stranger token sizes lead to some issues with positioning, but I'm not sure how important those are to fix before the other grid improvements in V12.
Closes #893