worldbuilding/module/macro.js
2021-12-21 14:19:14 +00:00

22 lines
790 B
JavaScript

/**
* Create a Macro from an attribute drop.
* Get an existing worldbuilding macro if one exists, otherwise create a new one.
* @param {Object} data The dropped data
* @param {number} slot The hotbar slot to use
* @returns {Promise}
*/
export async function createWorldbuildingMacro(data, slot) {
const command = `const roll = new Roll("${data.roll}", actor ? actor.getRollData() : {});
roll.toMessage({speaker, flavor: "${data.label}"});`;
let macro = game.macros.find(m => (m.name === data.label) && (m.command === command));
if (!macro) {
macro = await Macro.create({
name: data.label,
type: "script",
command: command,
flags: { "worldbuilding.attrMacro": true }
});
}
game.user.assignHotbarMacro(macro, slot);
return false;
}