mirror of
https://github.com/RoY7x/worldbuilding.git
synced 2025-04-30 02:31:41 -04:00
Simplify macro creation for formula attributes
This commit is contained in:
parent
6bf056b3d4
commit
5560fc24d4
2 changed files with 5 additions and 31 deletions
|
@ -6,42 +6,17 @@
|
|||
* @returns {Promise}
|
||||
*/
|
||||
export async function createWorldbuildingMacro(data, slot) {
|
||||
const item = data;
|
||||
|
||||
// Create the macro command
|
||||
const command = `game.worldbuilding.rollAttrMacro("${item.label}", "${item.roll}");`;
|
||||
const command = `const roll = new Roll("${data.roll}", actor ? actor.getRollData() : {});
|
||||
roll.toMessage({speaker, flavor: "${data.label}"});`;
|
||||
let macro = game.macros.entities.find(m => (m.name === item.label) && (m.command === command));
|
||||
if (!macro) {
|
||||
macro = await Macro.create({
|
||||
name: item.label,
|
||||
name: data.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
|
||||
});
|
||||
}
|
|
@ -9,7 +9,7 @@ import { SimpleActor } from "./actor.js";
|
|||
import { SimpleItemSheet } from "./item-sheet.js";
|
||||
import { SimpleActorSheet } from "./actor-sheet.js";
|
||||
import { preloadHandlebarsTemplates } from "./templates.js";
|
||||
import { createWorldbuildingMacro, rollAttrMacro } from "./macro.js";
|
||||
import { createWorldbuildingMacro } from "./macro.js";
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Foundry VTT Initialization */
|
||||
|
@ -32,8 +32,7 @@ Hooks.once("init", async function() {
|
|||
|
||||
game.worldbuilding = {
|
||||
SimpleActor,
|
||||
createWorldbuildingMacro,
|
||||
rollAttrMacro,
|
||||
createWorldbuildingMacro
|
||||
};
|
||||
|
||||
// Define custom Entity classes
|
||||
|
|
Loading…
Add table
Reference in a new issue