mclemente / about-face

FoundryVTT Module to rotate tokens on move
Other
7 stars 8 forks source link

Allow indicator to snap to hex facings #20

Closed crnormand closed 2 years ago

crnormand commented 2 years ago

This solves https://github.com/mclemente/about-face/issues/19

It adds a system setting: image

And when tokens are moved (only on hex maps), it will determine the closest facing image image

And sorry about the spacing issue... I guess my IDE isn't using the same spaces/tab as yours.

mclemente commented 2 years ago

Hey, thanks for the contribution, but I wasn't able to reproduce the image on #19 (the token in the middle) with this on any of the hex grid types.

Also, no problem on the spacing, I haven't uploaded a .prettierrc with the project, so it's not your fault. Also, it's just a save away from fixing, so it's not a big deal either.

crnormand commented 2 years ago

Oh sorry, after I made the issue request, I thought to myself, why don't I just do it and send it to you as a pull request.

I was just indicating with the blue arrow that the token on the right was the one that had the correct indicator.

mclemente commented 2 years ago

But they already snap to the grid, try it without any other modules.

Are you using any modules that also hook on preUpdateToken? That might be causing a race condition, messing with the x,y coordinates during the update and making the indicators like that.

crnormand commented 2 years ago

Yes, I am sorry, I wasn't talking about the grid. I was just talking about the direction indicator. In GURPS combat, the way you're facing makes a big difference. Which is why A lot of us were really excited that you took up the project and made it work in version 9. All I added was a small amount of code to make the facing indicator lock onto one of the faces of the hex grid after a move. What the player does with it after the move is up to them.

mclemente commented 2 years ago

Can't you do that by toggling the Lock Indicator Arrow setting on already, though?

crnormand commented 2 years ago

No. The "Lock Indicator Arrow" setting means that the indicator will not change if the token is moved: image image The indicator stayed pointing up and to the left. When the "Lock Indicator Arrow" feature is turned on, the "Lock Indicator to Hex face" setting is ignored.

We like the feature that the indicator moves to point in the direction that the token moved, it is just that in GURPS (and some other hex based games), the final facing is important. The current implementation calculates the exact angle of the movement, and sets the indicator to point in that direction, with no regard to the map grid.

The "Lock Indicator to Hex face" just makes it so the indicator, after a token is moved, is pointing directly through the most appropriate hex face. Here is what it looks like when this is OFF (which is the current behavior): image image

You can see the indicator is slightly off of the vertex (not the face) of the hex near the token's leg.

But, with this feature turned on, the indicator will choose one of the two faces, and directly point through that face: image image The indicator is pointing straight down through the bottom hex face, since it determined that the angle of movement was more closely in line with the bottom face (and not the bottom left face) of the hex.

I am sorry for all of the confusion. Hopefully this explains the new feature. I guess the only thing I would add (if I knew how to do it) would be to disable the "Lock Indicator to Hex face" setting if the "Lock Indicator Arrow" setting was true. But I don't know how (or if you can), dynamically enable and disable settings. I guess I could at least update the help text to say that this setting is ignored if "Lock Indicator Arrow" is on.

crnormand commented 2 years ago

I just added

This setting is ignored if 'Lock Indicator Rotation' is on.

to the hint text

mclemente commented 2 years ago

I understand now, I was testing with short movements where the arrows were already snapping, so I wasn't understanding the use of this.

This could actually be useful for Square grid too.

crnormand commented 2 years ago

Sure. Give me 30 minutes and I will update the PR

mclemente commented 2 years ago

Oh, you don't need to, I was already working on it. I should've accepted the PR already, sorry about that!

crnormand commented 2 years ago

You sure? I am almost done.

crnormand commented 2 years ago

Actually, I am done.

mclemente commented 2 years ago

In case you were already at it, Square's angles are [45, 90, 135, 180, 225, 270, 315, 360] and the only major difference from hexes is that dir = secondAngle - 60 needs to be dir = secondAngle - 45 instead, I'll commit over the PR.