Skip to content

Commit

Permalink
Added and updated macros
Browse files Browse the repository at this point in the history
  • Loading branch information
AnthonyVadala committed Feb 14, 2023
1 parent ca454fa commit ceaece1
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions packs/macros-module-specific.db
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"Token Favorite Action","type":"script","scope":"global","author":"9xl2JLocACiT1lMg","img":"icons/svg/dice-target.svg","command":"/*\n* FAVORITE ACTION PICKER\n* Requires: DND5e with Tidy5eSheet extension\n* --------------------------------------------------------------------------------\n* Provides handy and minimalistic, icon based menu for accessing actions that checked\n* in as favorite for a selected token or main character.\n* --------------------------------------------------------------------------------\n* Author: Broadway-afk\n* This script forked from show_token_actions.js macro made by shawndibble and stick#0520\n*/\n\nclass ActionDialog extends Application {\n getData(){\n // Get user's character or the first token from the controlled list.\n function getTargetActor() {\n const character = game.user.character;\n if (character)\n return character;\n\n const controlled = canvas.tokens.controlled;\n\n if (controlled.length > 0 && controlled[0] !== null)\n return controlled[0].actor;\n }\n\n function buildActionsList(targetActor) {\n let actionsList = [];\n Object.entries(targetActor.itemTypes).forEach(([type, items]) => {\n items.forEach(item => {\n if (item.flags[\"tidy5e-sheet\"]?.favorite) {\n actionsList.push(item);\n }\n });\n })\n return actionsList;\n }\n\n function getContentTemplate(actions) {\n let actionButtonsTemplate = actions.map((action) => {\n let displayName = action.name.split(\" /\")[0];\n let initials = displayName.split(\" \").map((item) => item[0]).join(\"\").toUpperCase();\n return `<button title=\"${displayName}\" onclick=\"${getRollItemMacro(action.name)}\"> \n <figure>\n <img alt=\"${action.name}\" src=\"${action.img}\" /> \n <figcaption>${initials}</figcaption> \n </figure> \n </button>`\n }).join(\" \");\n\n return `\n ${getCssStyle()}\n <div class=\"favorite-actions\">\n ${actionButtonsTemplate}\n </div>\n `;\n }\n\n function getCssStyle() {\n return `<style>\n .favorite-actions {\n display: flex;\n flex-wrap: wrap;\n gap: 10px;\n }\n .favorite-actions button {\n width: 40px;\n padding: 0;\n }\n .favorite-actions figure {\n margin: 0;\n position: relative;\n } \n .favorite-actions figcaption {\n padding: 0;\n line-height: 1;\n margin-top: 0;\n position: absolute;\n left: 0;\n top: 0;\n width: 40px;\n height: 40px;\n display: flex;\n align-items: center;\n justify-content: center;\n font-size: 25px;\n color: white;\n opacity: 0.5;\n text-shadow: 0 0 6px #000000;\n } \n </style>`\n }\n\n function getRollItemMacro(itemName) {\n return `game.dnd5e.rollItemMacro(&quot;${itemName}&quot;)`;\n }\n\n let targetActor = getTargetActor();\n let innerContent = \"\";\n\n if (targetActor) {\n this.options.title = `${targetActor.name} favorite actions`;\n let actionLists = buildActionsList(targetActor);\n innerContent = getContentTemplate(actionLists);\n } else {\n ui.notifications.error(\"No token selected or user character found.\");\n throw new Error(\"No token selected or character found\");\n }\n\n let content = `<div id=\"actionDialog\">${innerContent}</div>`;\n let contentsObject = {content:`${content}`}\n return contentsObject;\n }\n}\n\nlet opt=Dialog.defaultOptions;\nopt.resizable=true;\nopt.minimizable=true;\nopt.width=600;\nlet viewer;\nviewer = new ActionDialog(opt);\nviewer.render(true);","ownership":{"default":0,"9xl2JLocACiT1lMg":3},"flags":{"core":{"sourceId":"Macro.eKi2YKRqMXaVYgWC"}},"_stats":{"systemId":"dnd5e","systemVersion":"2.1.4","coreVersion":"10.291","createdTime":1676359091029,"modifiedTime":1676359141430,"lastModifiedBy":"9xl2JLocACiT1lMg"},"folder":null,"sort":0,"_id":"mGIy84rESg0w7xxK"}

0 comments on commit ceaece1

Please sign in to comment.