forked from public/bol
81 lines
3.4 KiB
JavaScript
81 lines
3.4 KiB
JavaScript
import {BoLUtility} from "./bol-utility.js";
|
|
|
|
export default function registerHooks() {
|
|
|
|
/**
|
|
* Ready hook loads tables, and override's foundry's entity link functions to provide extension to pseudo entities
|
|
*/
|
|
|
|
Hooks.once("ready", async () => {
|
|
console.info("BOL | System Initialized.");
|
|
});
|
|
|
|
Hooks.on("renderPause", ((_app, html) => {
|
|
html.find("img").attr("src", "systems/bol/ui/pause2.webp")
|
|
}))
|
|
|
|
Hooks.on('renderChatLog', (log, html, data) => BoLUtility.chatListeners(html))
|
|
Hooks.on('renderChatMessage', (message, html, data) => BoLUtility.chatMessageHandler(message, html, data))
|
|
|
|
/**
|
|
* Create a macro when dropping an entity on the hotbar
|
|
* Item - open roll dialog for item
|
|
* Actor - open actor sheet
|
|
* Journal - open journal sheet
|
|
*/
|
|
Hooks.on("hotbarDrop", async (bar, data, slot) => {
|
|
console.log(data.type);
|
|
// Create item macro if rollable item - weapon, spell, prayer, trait, or skill
|
|
if (data.type == "Item") {
|
|
let item = data.data;
|
|
console.log(item);
|
|
}
|
|
// Create a macro to open the actor sheet of the actor dropped on the hotbar
|
|
else if (data.type == "Actor") {
|
|
let actor = game.actors.get(data.id);
|
|
let command = `/*\nPersonnalisez la macro selon vos besoins en suivant les exemples suivants : \ngame.bol.macros.rollMacro('attribute', 'vigor|agility|mind|appeal', adv, mod);\ngame.bol.macros.rollMacro('aptitude', 'init|melee|ranged|def', adv, mod);\n*/\ngame.bol.macros.rollMacro('attribute', 'vigor', 0, 0);`;
|
|
let macro = game.macros.entities.find(m => (m.name === actor.name) && (m.command === command));
|
|
if (!macro) {
|
|
macro = await Macro.create({
|
|
name: actor.name,
|
|
type: "script",
|
|
img: "icons/svg/dice-target.svg",
|
|
command: command
|
|
}, {displaySheet: false})
|
|
game.user.assignHotbarMacro(macro, slot);
|
|
}
|
|
}
|
|
// Create a macro to open the journal sheet of the journal dropped on the hotbar
|
|
else if (data.type == "JournalEntry") {
|
|
let journal = game.journal.get(data.id);
|
|
console.log(journal);
|
|
let command = `game.journal.get("${data.id}").sheet.render(true)`
|
|
let macro = game.macros.entities.find(m => (m.name === journal.name) && (m.command === command));
|
|
if (!macro) {
|
|
macro = await Macro.create({
|
|
name: journal.name,
|
|
type: "script",
|
|
img: (journal.img) ? journal.img : "icons/svg/book.svg",
|
|
command: command
|
|
}, {displaySheet: false})
|
|
game.user.assignHotbarMacro(macro, slot);
|
|
}
|
|
}
|
|
return false;
|
|
});
|
|
|
|
/********************************************************************************** */
|
|
Hooks.on("renderActorDirectory", (app, html, data) => {
|
|
if (game.user.isGM) {
|
|
const button = document.createElement('button');
|
|
button.style.width = '95%';
|
|
button.innerHTML = game.i18n.localize("BOL.ui.pclistbutton")
|
|
button.addEventListener('click', () => {
|
|
game.bol.charSummary.render(true)
|
|
})
|
|
html.find('.header-actions').after(button)
|
|
}
|
|
})
|
|
|
|
}
|