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.

86 lines
2.9 KiB

1 year ago
  1. export function adjustPolygonPoints(drawing){
  2. let globalCoords = [];
  3. if (drawing.document.shape.points.length != 0) {
  4. for (let i = 0; i < drawing.document.shape.points.length; i += 2) {
  5. globalCoords.push(
  6. drawing.document.shape.points[i] + (drawing.x),
  7. drawing.document.shape.points[i + 1] + (drawing.y)
  8. );
  9. }
  10. } else {
  11. globalCoords = [
  12. drawing.x,
  13. drawing.y,
  14. drawing.x + drawing.document.shape.width,
  15. drawing.y,
  16. drawing.x + drawing.document.shape.width,
  17. drawing.y + drawing.document.shape.height,
  18. drawing.x,
  19. drawing.y + drawing.document.shape.height,
  20. ];
  21. }
  22. return globalCoords;
  23. }
  24. export function inRange(document, elevation){
  25. const rangeBottom = document.flags?.levels?.rangeBottom ?? -Infinity;
  26. const rangeTop = document.flags?.levels?.rangeTop ?? Infinity;
  27. return elevation >= rangeBottom && elevation <= rangeTop;
  28. }
  29. export function inDistance(placeable1, placeable2, distance) {
  30. const placeable1Vector = {
  31. x: placeable1.center.x,
  32. y: placeable1.center.y,
  33. z: (placeable1.losHeight ?? placeable1.document.elevation) * canvas.scene.dimensions.size / canvas.scene.dimensions.distance,
  34. }
  35. const placeable2Vector = {
  36. x: placeable2.center.x,
  37. y: placeable2.center.y,
  38. z: (placeable2.losHeight ?? placeable2.document.elevation) * canvas.scene.dimensions.size / canvas.scene.dimensions.distance,
  39. }
  40. return Math.hypot(
  41. placeable1Vector.x - placeable2Vector.x,
  42. placeable1Vector.y - placeable2Vector.y,
  43. placeable1Vector.z - placeable2Vector.z
  44. ) <= distance;
  45. }
  46. export function getRangeForDocument(document){
  47. if(document instanceof WallDocument){
  48. return {
  49. rangeBottom: document.flags?.["wall-height"]?.bottom ?? -Infinity,
  50. rangeTop: document.flags?.["wall-height"]?.top ?? Infinity
  51. }
  52. }else if(document instanceof TokenDocument){
  53. return {
  54. rangeBottom: document.elevation,
  55. rangeTop: document.elevation
  56. }
  57. }
  58. const rangeBottom = document.flags?.levels?.rangeBottom ?? -Infinity;
  59. const rangeTop = document.flags?.levels?.rangeTop ?? Infinity;
  60. return { rangeBottom, rangeTop };
  61. }
  62. export function cloneTileMesh(tile){
  63. if(!tile.mesh) {
  64. const sprite = new PIXI.Sprite();
  65. sprite.tile = tile;
  66. return sprite;
  67. };
  68. const sprite = PIXI.Sprite.from(tile.mesh.texture);
  69. sprite.alpha = 1;
  70. sprite.tint = 0x000000;
  71. sprite.width = tile.mesh.width;
  72. sprite.height = tile.mesh.height;
  73. sprite.position.set(tile.center.x, tile.center.y);
  74. sprite.anchor.set(0.5, 0.5);
  75. sprite.angle = tile.mesh.angle;
  76. sprite.scale.x = (tile.mesh.width / tile.mesh.texture.width) * tile.document.texture.scaleX;
  77. sprite.scale.y = (tile.mesh.height / tile.mesh.texture.height) * tile.document.texture.scaleY;
  78. sprite.tile = tile;
  79. return sprite;
  80. }