mirror of
https://github.com/RoY7x/worldbuilding.git
synced 2025-04-30 02:31:41 -04:00
22 lines
790 B
JavaScript
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 === item.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;
|
|
}
|