Skip to content

Commit

Permalink
GM Macro socket
Browse files Browse the repository at this point in the history
  • Loading branch information
MrPrimate committed Apr 30, 2024
1 parent 806ee7e commit 220cafe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/effects/DDBMacros.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,22 @@ return game.modules.get("ddb-importer")?.api.macros.executeMacro("${type}", "${f
return macro.execute(...params);
}

static async executeDDBMacroAsGM(type, name, ...params) {
const gmUser = game.users.find((f) => f.isGM);
if (!gmUser) {
ui.notifications.error("No GM user found");
return undefined;
}
if (!game.modules.get("socketlib")?.active) {
ui.notifications.warn(`Socketlib needs to be installed and active for this macro functionality`);
return DDBMacros.executeDDBMacro(type, name, ...params);
} else if (game.user.isGM) {
return DDBMacros.executeDDBMacro(type, name, ...params);
} else {
return globalThis.socketlib.modules.get("ddb-importer").executeAsGM("ddbMacro", type, name, ...params);
}
}

static getMacroFunction(type, name) {
const macroFunction = async (...params) => {
const macro = await DDBMacros.getMacro(type, name);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/socket/socketlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function setupSocketlib() {
const socket = globalThis.socketlib.registerModule("ddb-importer");
socket.register("simpleButtonDialog", DDBImporter.lib.DialogHelper.buttonDialog);
socket.register("chooserDialog", DDBImporter.lib.DialogHelper.ChooserDialog.Ask);

socket.register("ddbMacro", DDBImporter.lib.DDBMacros.executeDDBMacro);
return socket;

}

0 comments on commit 220cafe

Please sign in to comment.