p4535992 / foundryvtt-arms-reach

FoundryVTT Door little Utilities, Arms Reach for door
MIT License
3 stars 4 forks source link

[BUG] Token centers and placeable centers not consistent in Foundry - needs to be adjusted in module #35

Closed KenGitsIt closed 2 years ago

KenGitsIt commented 2 years ago

Module Version: v2.1.7

Describe the bug It seems that Foundry measures placeables from the center and tokens from the corner (or vice-versa, I'm not really sure). So if you inspect the X coordinates of a token and a map note that are aligned vertically, you'll see that the coordinates are off by half a grid square. The result is that the measurements this module use are off by half a grid square, because it fails to adjust.

To Reproduce Steps to reproduce the behavior:

  1. Set the distance to interact at 5 feet
  2. Place a map note in the middle of a grid square.
  3. Place a player token one square to the west. It won't be able to interact. Place it one square to the east, and it will.

Expected behavior The token should be able to interact from one square in any direction.

Screenshots If applicable, add screenshots to help explain your problem.

I've verified this behavior with map notes, staircases, and doors. Changing appropriate functions like the following seems to fix the behavior: getNotesCenter: function (note) { const noteCenter = { x: note.x - canvas.dimensions.size/2, y: note.y - canvas.dimensions.size/2 }; return noteCenter; },

In the case of door controls, the measurement seems to be the corner of the door icon, so I used this: getDoorCenter: function (token) { const tokenCenter = { x: token.x + token.icon.width/2 - canvas.dimensions.size/2, y: token.y + token.icon.height/2 - canvas.dimensions.size/2 }; return tokenCenter; },

I also had to put back in the calls to getDoorCenter(), since that wasn't being used.

KenGitsIt commented 2 years ago

Screenshot: Notice how the token and the map note are vertically aligned, but the X position of the token is 50 less than the X position of the map note. The grid size in this example is 100.

image

p4535992 commented 2 years ago

ty for the contribution, i will check your solution tonight

p4535992 commented 2 years ago

Try to fix this on 2.1.9 try out and let me know