A small add-on module for Foundry VTT which converts wall segments to drawings for quick maps
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.

69 lines
1.6 KiB

  1. /** @constant {string} */
  2. WALLCOLOUR = "#111111";
  3. /** @constant {number} */
  4. WALLWIDTH = "4";
  5. /** @constant {string} */
  6. MODULENAME = "foundry-walls-to-drawing";
  7. /**
  8. * Set up configuration options
  9. * */
  10. Hooks.on("init", () => {
  11. game.settings.register(MODULENAME, "cvWallColour", {
  12. name: "Converted Wall Colour",
  13. default: WALLCOLOUR,
  14. type: String,
  15. scope: "client",
  16. config: true,
  17. hint: "Enter a hexadecimal colour, eg #FF0000 for red"
  18. });
  19. game.settings.register(MODULENAME, "cvWallWidth", {
  20. name: "Converted Wall Width",
  21. default: WALLWIDTH,
  22. type: Number,
  23. scope: "client",
  24. config: true,
  25. hint: "Enter a decimal width"
  26. });
  27. });
  28. /**
  29. * Add 'Convert to walls' button in Walls Layer Tools
  30. * */
  31. Hooks.on('getSceneControlButtons', controls => {
  32. cvWallColour = game.settings.get(MODULENAME, "cvWallColour");
  33. cvWallWidth = game.settings.get(MODULENAME, "cvWallWidth");
  34. let walls = controls.find(e => e.name === "walls");
  35. walls.tools.push( {
  36. "name": "convert-to-draw",
  37. "icon": "far fa-square",
  38. "title": "Convert selected to Drawing",
  39. "onClick": () => {
  40. cvWalls = []
  41. canvas.walls.controlled.forEach(function(wall) {
  42. cvWalls.push({
  43. type: CONST.DRAWING_TYPES.POLYGON,
  44. author: game.user._id,
  45. x: 0,
  46. y: 0,
  47. height: 100,
  48. strokeWidth: cvWallWidth,
  49. strokeColor: cvWallColour,
  50. points: [
  51. [wall.coords[0], wall.coords[1]],
  52. [wall.coords[2], wall.coords[3]]
  53. ]
  54. });
  55. });
  56. Drawing.create(cvWalls);
  57. ui.controls.controls.find(e => e.name === "walls").activeTool = "select";
  58. ui.controls.render();
  59. }
  60. });
  61. });