All user data for FoundryVTT. Includes worlds, systems, modules, and any asset in the "foundryuserdata" directory. Does NOT include the FoundryVTT installation itself.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
1.7 KiB

1 year ago
  1. export class LightHandler{
  2. static isLightVisibleWrapper(wrapped, ...args){
  3. const result = wrapped(...args);
  4. const isPreview = this.document?.id == null;
  5. if(isPreview) return result;
  6. if(!CONFIG.Levels.handlers.UIHandler.emitsLightUI(this)) return false;
  7. if (game.Levels3DPreview?._active) return result;
  8. const isToken = this instanceof Token;
  9. const rangeBottom = isToken ? this.document.elevation : this.document.flags.levels?.rangeBottom ?? -Infinity;
  10. const rangeTop = isToken ? this.losHeight : this.document.flags.levels?.rangeTop ?? Infinity;
  11. const currentElevation = CONFIG.Levels.currentToken?.losHeight
  12. if(currentElevation === undefined) return result;
  13. const underBackground = currentElevation >= canvas.primary.background.elevation && rangeTop < canvas.primary.background.elevation;
  14. if(underBackground) return false;
  15. let isLightVisible = false;
  16. if ((canvas.scene.flags.levels?.lightMasking ?? true)) {
  17. if (isToken) isLightVisible = true;//this.visible || rangeBottom <= currentElevation;
  18. else isLightVisible = rangeBottom <= currentElevation;
  19. } else {
  20. let inTokenElevationRange = false;
  21. if (isToken) {
  22. const currentTokenElevation = CONFIG.Levels.currentToken?.document?.elevation ?? currentElevation;
  23. inTokenElevationRange = rangeBottom <= currentTokenElevation && currentTokenElevation <= rangeTop;
  24. }
  25. isLightVisible = (rangeBottom <= currentElevation && currentElevation <= rangeTop) || inTokenElevationRange;
  26. }
  27. return result && isLightVisible;
  28. }
  29. }