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.

102 lines
3.9 KiB

1 year ago
  1. export class TemplateHandler{
  2. static isVisible(wrapped, ...args){
  3. const result = wrapped(...args);
  4. return result;
  5. const currentElevation = CONFIG.Levels.currentToken?.losHeight
  6. const templateElevation = this.document.flags.levels?.elevation;
  7. if(currentElevation === undefined || templateElevation === undefined || !CONFIG.Levels.currentToken) return result;
  8. const origin = {
  9. x: CONFIG.Levels.currentToken.x,
  10. y: CONFIG.Levels.currentToken.y,
  11. z: currentElevation
  12. }
  13. const target = {
  14. x: this.center.x,
  15. y: this.center.y,
  16. z: templateElevation
  17. }
  18. const isVisible = !CONFIG.Levels.handlers.SightHandler.testCollision(origin,target);
  19. return result && isVisible;
  20. }
  21. static async drawTooltip(wrapped, ...args){
  22. await wrapped(...args);
  23. if(this.document.getFlag(CONFIG.Levels.MODULE_ID, "elevation")===0) return this;
  24. this.tooltip = this.addChild(_templateDrawTooltip(this));
  25. function _templateDrawTooltip(template) {
  26. // Create the tooltip Text
  27. const tipFlag = template.document.getFlag(CONFIG.Levels.MODULE_ID, "elevation");
  28. let tipN;
  29. if (tipFlag === undefined) {
  30. if (CONFIG.Levels.UI.nextTemplateHeight !== undefined) {
  31. tipN = CONFIG.Levels.UI.nextTemplateHeight;
  32. } else {
  33. const cToken =
  34. canvas.tokens.controlled[0] || _token;
  35. tipN = cToken?.document?.elevation ?? 0;
  36. }
  37. } else {
  38. tipN = tipFlag;
  39. }
  40. let units = canvas.scene.grid.units;
  41. const tip = tipN > 0 ? `+${tipN} ${units}` : `${tipN} ${units}`;
  42. const style = CONFIG.canvasTextStyle.clone();
  43. style.fontSize = Math.max(
  44. Math.round(canvas.dimensions.size * 0.36 * 12) / 12,
  45. 36
  46. );
  47. const text = new PreciseText(tip, style);
  48. text.anchor.set(0.5, 2);
  49. return text;
  50. }
  51. return this;
  52. }
  53. static _refreshRulerText() {
  54. let special = this.document.flags.levels?.special// || _levels?.nextTemplateSpecial
  55. let text;
  56. let u = canvas.scene.grid.units;
  57. if ( this.document.t === "rect" ) {
  58. let d = canvas.dimensions;
  59. let dx = Math.round(this.ray.dx) * (d.distance / d.size);
  60. let dy = Math.round(this.ray.dy) * (d.distance / d.size);
  61. let w = Math.round(dx * 10) / 10;
  62. let h = Math.round(dy * 10) / 10;
  63. text = special ? `${w}${u} x ${h}${u} x ${special}${u}` : `${w}${u} x ${h}${u}`;
  64. } else {
  65. let d = Math.round(this.document.distance * 10) / 10;
  66. text = special ? `${d}${u} x ${special}${u}` : `${d}${u}`;
  67. }
  68. this.ruler.text = text;
  69. this.ruler.position.set(this.ray.dx + 10, this.ray.dy + 5);
  70. }
  71. static getTemplateData(){
  72. const cToken = canvas.tokens.controlled[0] || _token;
  73. const handMode =
  74. typeof LevelsVolumetricTemplates !== "undefined" &&
  75. LevelsVolumetricTemplates.tools.handMode &&
  76. cToken
  77. ? Math.round(
  78. (cToken.losHeight - cToken?.document?.elevation) * 0.8
  79. )
  80. : 0;
  81. let elevation;
  82. let special;
  83. if (CONFIG.Levels.UI.nextTemplateHeight !== undefined) {
  84. elevation = CONFIG.Levels.UI.nextTemplateHeight;
  85. special = CONFIG.Levels.UI.nextTemplateSpecial;
  86. CONFIG.Levels.UI.nextTemplateHeight = undefined;
  87. CONFIG.Levels.UI.nextTemplateSpecial = undefined;
  88. CONFIG.Levels.UI.templateElevation = false;
  89. CONFIG.Levels.UI._levelsTemplateTool.active = false;
  90. $("body")
  91. .find(`li[data-tool="setTemplateElevation"]`)
  92. .removeClass("active");
  93. } else {
  94. elevation = cToken?.document?.elevation + handMode || 0;
  95. }
  96. return { elevation, special };
  97. }
  98. }