Advertisement
Guest User

Untitled

a guest
Aug 16th, 2024
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JavaScript 2.23 KB | Software | 0 0
  1. // Define the list of status macros we are interested in
  2. const statusMacros = [
  3.     "Fire",
  4.     "Poison",
  5.     "Bleed",
  6.     "Freeze",
  7.     "Staggered",
  8.     "Intoxication",
  9.     "Hallucination",
  10.     "Nausea",
  11.     "Regeneration",
  12.     "Remove Effects",
  13.     "Suffocation",
  14.     "Blinded"
  15. ];
  16.  
  17. // Function to display macros as a GUI
  18. async function showMacroSelector() {
  19.     // Filter macros to only include the ones listed in statusMacros
  20.     const allMacros = Array.from(game.macros.values());
  21.     const statusMacrosList = allMacros.filter(macro => statusMacros.includes(macro.name));
  22.  
  23.     // Sort the macros alphabetically by name
  24.     statusMacrosList.sort((a, b) => a.name.localeCompare(b.name));
  25.  
  26.     // Create an HTML container to display the macros
  27.     const content = `
  28.         <div style="display: grid; grid-template-columns: repeat(auto-fit, minmax(80px, 1fr)); gap: 10px; padding: 10px;">
  29.             ${statusMacrosList.map(macro => `
  30.                 <div style="text-align: center; display: flex; flex-direction: column; align-items: center;">
  31.                     <img src="${macro.img}" style="cursor: pointer; width: 64px; height: 64px;" title="${macro.name}" data-macro-id="${macro.id}" />
  32.                     <div>${macro.name}</div>
  33.                 </div>
  34.             `).join('')}
  35.         </div>
  36.     `;
  37.  
  38.     // Create a dialog to hold the GUI
  39.     const dialog = new Dialog({
  40.         title: "Select a Status Macro",
  41.         content: content,
  42.         buttons: {},
  43.         render: (html) => {
  44.             // Add click event listener to all images
  45.             html.find('img').on('click', async (event) => {
  46.                 const macroId = event.currentTarget.dataset.macroId;
  47.                 const macro = game.macros.get(macroId);
  48.                 if (macro) {
  49.                     // Execute the selected macro
  50.                     await macro.execute();
  51.                     // Close the dialog after executing the macro
  52.                     dialog.close();
  53.                 } else {
  54.                     console.error(`Macro with ID ${macroId} not found.`);
  55.                 }
  56.             });
  57.         }
  58.     });
  59.  
  60.     // Render the dialog
  61.     dialog.render(true);
  62. }
  63.  
  64. // Execute the macro selector function
  65. showMacroSelector();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement