Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 681: Fix double formatting of macroData. #682

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 30 additions & 15 deletions src/API/private-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -1689,23 +1689,16 @@ export default class PrivateAPI {
}

/**
* This executes any macro that is configured on the item pile, providing the macro with extra data relating to the
* action that prompted the execution (if the advanced-macros module is installed)
* This method will resolve any uuids and replace them with their corresponding documents.
* If the macroData has already been marked as reformatted, nothing will be done.
*
* @param {String} targetUuid
* @param {Object} macroData
* @return {Promise/Boolean}
* @return {Promise}
*/
static async _executeItemPileMacro(targetUuid, macroData) {

const target = Utilities.getToken(targetUuid);

if (!PileUtilities.isValidItemPile(target)) return;

const pileData = PileUtilities.getActorFlagData(target);

if (!pileData.macro) return;

static async _reformatMacroData(macroData) {
if (macroData.reformatted) {
return;
}
// Reformat macro data to contain useful information
if (macroData.source) {
macroData.source = fromUuidSync(macroData.source);
Expand Down Expand Up @@ -1737,9 +1730,31 @@ export default class PrivateAPI {
}

}
macroData.reformatted = true;
}

return Utilities.runMacro(pileData.macro, macroData)
/**
* This executes any macro that is configured on the item pile, providing the macro with extra data relating to the
* action that prompted the execution (if the advanced-macros module is installed)
*
* @param {String} targetUuid
* @param {Object} macroData
* @return {Promise/Boolean}
*/
static async _executeItemPileMacro(targetUuid, macroData) {

const target = Utilities.getToken(targetUuid);

if (!PileUtilities.isValidItemPile(target)) return;

const pileData = PileUtilities.getActorFlagData(target);

if (!pileData.macro) return;

// Reformat macro data to contain useful information
await this._reformatMacroData(macroData);

return Utilities.runMacro(pileData.macro, macroData)
}

/**
Expand Down