Files
vtt_work/wg-greyknights/scripts/auto-loadout.js
T

48 lines
2.1 KiB
JavaScript

// gk-greyknight — auto hooks + small tools menu
Hooks.once("ready", () => {
// Hook: when our Archetype is added, open Loadout Manager
if (!window._gkAutoLoadoutHook) {
window._gkAutoLoadoutHook = Hooks.on("createItem", async (item, opts, userId) => {
try {
if (item?.type !== "archetype") return;
if (item?.name !== "Grey Knight (Archetype)") return;
const actor = item.parent;
if (!actor || game.userId !== userId) return;
const code = await (await fetch("/modules/gk-greyknight/scripts/macros/gk-loadout-manager.js")).text();
(0, eval)(code);
} catch (e) { console.error("gk-greyknight auto-loadout error", e); }
});
}
game.settings.registerMenu("gk-greyknight", "tools", {
name: "Grey Knight Tools",
label: "Open Tools",
icon: "fas fa-shield-alt",
type: class extends FormApplication {
async _updateObject(event, formData) {}
static get defaultOptions(){ return foundry.utils.mergeObject(super.defaultOptions, { id:"gk-tools", title:"Grey Knight Tools", template: null}); }
async render(...args){
new Dialog({
title: "Grey Knight Tools",
content: `<p>Quick actions for GK content.</p>`,
buttons: {
import: {label:"Import Items from Module", icon:"<i class='fas fa-file-import'></i>", callback: async ()=>{
const code = await (await fetch("/modules/gk-greyknight/scripts/macros/gk-import-from-module.js")).text();
(0, eval)(code);
}},
loadout: {label:"Open Loadout Manager", icon:"<i class='fas fa-robot'></i>", callback: async ()=>{
const code = await (await fetch("/modules/gk-greyknight/scripts/macros/gk-loadout-manager.js")).text();
(0, eval)(code);
}},
glow: {label:"Toggle Aegis Glow", icon:"<i class='fas fa-lightbulb'></i>", callback: async ()=>{
const code = await (await fetch("/modules/gk-greyknight/scripts/macros/gk-glow-toggle.js")).text();
(0, eval)(code);
}}
},
default: "import"
}).render(true);
}
},
restricted: true
});
});