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.

50 lines
2.3 KiB

1 year ago
  1. export class LevelsAPI{
  2. /**
  3. * Test if a specified elevation is withing the range of a specified document, bounds are included.
  4. * @param {Document} document - the document to be tested
  5. * @param {Float} elevation - the elevation to test against
  6. * @returns {Boolean} returns wether the elevation is in the range or not
  7. **/
  8. static inRange(document, elevation){
  9. return CONFIG.Levels.helpers.inRange(document, elevation);
  10. }
  11. /**
  12. * Test if a token's losHeight is contained within the range of the placeable or document.
  13. * @param {Token} token - the token to test
  14. * @param {PlaceableObject|Document} placeableOrDocument - "sight" or "collision" (defaults to "sight")
  15. * @param {boolean} useElevation - if true, use the token's elevation, otherwise use the token's losHeight (the 'eye' elevation)
  16. * @returns {Boolean} returns wether the token is in the range or not
  17. **/
  18. static isTokenInRange(token, placeableOrDocument, useElevation = true){
  19. placeableOrDocument = placeableOrDocument?.document ?? placeableOrDocument;
  20. const elevation = useElevation ? token.document.elevation : token.losHeight;
  21. return CONFIG.Levels.helpers.inRange(placeableOrDocument, elevation);
  22. }
  23. /**
  24. * Perform a collision test between 2 TOKENS in 3D space
  25. * @param {Token} token1 - a token, the source of the check
  26. * @param {Token} token2 - a token, the target of the check
  27. * @param {String} type - "sight" or "collision" (defaults to "sight")
  28. * @returns {Object|Boolean} returns the collision point if a collision is detected, flase if it's not
  29. **/
  30. static checkCollision(token1, token2, type = "sight"){
  31. return CONFIG.Levels.handlers.SightHandler.checkCollision(token1, token2, type);
  32. }
  33. /**
  34. * Perform a collision test between 2 point in 3D space
  35. * @param {Object} p0 - a point in 3d space {x:x,y:y,z:z} where z is the elevation
  36. * @param {Object} p1 - a point in 3d space {x:x,y:y,z:z} where z is the elevation
  37. * @param {String} type - "sight" or "collision" (defaults to "sight")
  38. * @returns {Object|Boolean} returns the collision point if a collision is detected, flase if it's not
  39. **/
  40. static testCollision(p0, p1, type = "sight"){
  41. return CONFIG.Levels.handlers.SightHandler.testCollision(p0, p1, type);
  42. }
  43. }