worldbuilding/module/macro.js
Matt Smith f69e3841ff 10: Add attribute groups base implementation
- Added support for attribute groups
- Added rollable buttons to formula attributes
- Added additional i18n translation strings
2020-09-28 15:54:14 +00:00

47 lines
No EOL
1.4 KiB
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 item = data;
// Create the macro command
const command = `game.worldbuilding.rollAttrMacro("${item.label}", "${item.roll}");`;
let macro = game.macros.entities.find(m => (m.name === item.label) && (m.command === command));
if (!macro) {
macro = await Macro.create({
name: item.label,
type: "script",
command: command,
flags: { "worldbuilding.attrMacro": true }
});
}
game.user.assignHotbarMacro(macro, slot);
return false;
}
/**
* Create a Macro from an Item drop.
* Get an existing item macro if one exists, otherwise create a new one.
* @param {string} itemName
* @return {Promise}
*/
export function rollAttrMacro(attrName, attrFormula) {
let actor;
// Get the speaker and actor if not provided.
const speaker = ChatMessage.getSpeaker({ actor: this.actor });
if (speaker.token) actor = game.actors.tokens[speaker.token];
if (!actor) actor = game.actors.get(speaker.actor);
// Create the roll.
let r = new Roll(attrFormula, actor.getRollData());
r.roll().toMessage({
user: game.user._id,
speaker: speaker,
flavor: attrName
});
}