Skip to content

Draft: feat: add TokenPF.getLightLevel() for determining light level a token is at

Adds getLightLevel() function to the token placeable.

It has following parameters:

  • points – Number of light tests needed to qualify for a light level. Default: 2 (9 are tested)
  • maxRange – Maximum range to search lights from. Default: Infinity
  • tolerance – Extra range given to lights to give room for small error of margin. Default: 0.05 (scene scale multiplier)
  • visualize – Draws temporary pixi graphics for debugging.

Return value is 0 to 2, with 0 for darkness and 2 for bright light.

Not sure if the visualization should be left in, but it's easy way to verify the code functions correctly without having to try to look at coordinates.

Requiring only 2 tests out of 9 for light level was chosen as reasonable "lit enough" to see a person. This should also roughly match Foundry's token visibility testing logic.

Marked as draft since there's still some logging left in and the question of visualization. One could also argue that non-GMs should not be allowed to use this, but that would limit the usability of this in modules and macros severely. It could also be argued that this should be on the token document instead.

TODO:

  • Tokens with lights

There could be proxies on actor and the other token class for accessing the same functionality with ease, though purpose of such is a bit debatable.

Screencaps

Debug visualization in effect:

get-light-level

Performance

Decent?

benchmark

Edited by M.A.

Merge request reports