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.

87 lines
2.9 KiB

1 year ago
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. document = document.document ?? document;
  48. if(document instanceof WallDocument){
  49. return {
  50. rangeBottom: document.flags?.["wall-height"]?.bottom ?? -Infinity,
  51. rangeTop: document.flags?.["wall-height"]?.top ?? Infinity
  52. }
  53. }else if(document instanceof TokenDocument){
  54. return {
  55. rangeBottom: document.elevation,
  56. rangeTop: document.elevation
  57. }
  58. }
  59. const rangeBottom = document.flags?.levels?.rangeBottom ?? -Infinity;
  60. const rangeTop = document.flags?.levels?.rangeTop ?? Infinity;
  61. return { rangeBottom, rangeTop };
  62. }
  63. export function cloneTileMesh(tile){
  64. if(!tile.mesh) {
  65. const sprite = new PIXI.Sprite();
  66. sprite.tile = tile;
  67. return sprite;
  68. };
  69. const sprite = PIXI.Sprite.from(tile.mesh.texture);
  70. sprite.alpha = 1;
  71. sprite.tint = 0x000000;
  72. sprite.width = tile.mesh.width;
  73. sprite.height = tile.mesh.height;
  74. sprite.position.set(tile.center.x, tile.center.y);
  75. sprite.anchor.set(0.5, 0.5);
  76. sprite.angle = tile.mesh.angle;
  77. sprite.scale.x = (tile.mesh.width / tile.mesh.texture.width) * tile.document.texture.scaleX;
  78. sprite.scale.y = (tile.mesh.height / tile.mesh.texture.height) * tile.document.texture.scaleY;
  79. sprite.tile = tile;
  80. return sprite;
  81. }