mirror of
https://github.com/RoY7x/worldbuilding.git
synced 2025-04-29 18:21:40 -04:00
23 lines
839 B
JavaScript
23 lines
839 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) {
|
|
if ( !data.roll || !data.label ) return false;
|
|
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;
|
|
}
|