Add an extra paragraph to the Macro deletion dialog in order to tell people how many items use that macro (closes #81)
This commit is contained in:
parent
74d881c3df
commit
c6d3c094b8
3 changed files with 42 additions and 0 deletions
39
module/documents/Macro.mjs
Normal file
39
module/documents/Macro.mjs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
export class TAFMacro extends foundry.documents.Macro {
|
||||
async deleteDialog(options, operation) {
|
||||
const itemsUsingMacro = new Set();
|
||||
|
||||
// Check Items on Actors
|
||||
game.actors.forEach(actor => {
|
||||
actor.items.forEach(item => {
|
||||
console.log(item.uuid, `owned by`, actor.uuid);
|
||||
if (item.system.trigger === this.uuid) {
|
||||
itemsUsingMacro.add(item.uuid);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
// Check World Items
|
||||
game.items.forEach(item => {
|
||||
if (item.system.trigger === this.uuid) {
|
||||
itemsUsingMacro.add(item.uuid);
|
||||
};
|
||||
});
|
||||
|
||||
// Modify the dialog arguments
|
||||
const type = _loc(this.constructor.metadata.label);
|
||||
const question = _loc(`COMMON.AreYouSure`);
|
||||
const warning = _loc(`SIDEBAR.DeleteWarning`, { type });
|
||||
let content = `<p style="margin: 0;"><strong>${question}</strong> ${warning}</p>`;
|
||||
|
||||
if (itemsUsingMacro.size) {
|
||||
const extraInfo = _loc(
|
||||
`taf.misc.macro-is-in-use`,
|
||||
{ count: itemsUsingMacro.size },
|
||||
);
|
||||
content += `<p style="margin: 0;">${extraInfo}</p>`;
|
||||
};
|
||||
|
||||
options.content = content;
|
||||
return super.deleteDialog(options, operation);
|
||||
};
|
||||
};
|
||||
|
|
@ -14,6 +14,7 @@ import { PlayerData } from "../data/Actor/player.mjs";
|
|||
import { TAFActor } from "../documents/Actor.mjs";
|
||||
import { TAFCombatant } from "../documents/Combatant.mjs";
|
||||
import { TAFItem } from "../documents/Item.mjs";
|
||||
import { TAFMacro } from "../documents/Macro.mjs";
|
||||
import { TAFTokenDocument } from "../documents/Token.mjs";
|
||||
|
||||
// Settings
|
||||
|
|
@ -33,6 +34,7 @@ Hooks.on(`init`, () => {
|
|||
CONFIG.Actor.documentClass = TAFActor;
|
||||
CONFIG.Combatant.documentClass = TAFCombatant;
|
||||
CONFIG.Item.documentClass = TAFItem;
|
||||
CONFIG.Macro.documentClass = TAFMacro;
|
||||
CONFIG.Token.documentClass = TAFTokenDocument;
|
||||
// #endregion Documents
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue