Files
tevansandClaude Opus 4.8 309a115d8b v0.5.1 — fix scene-control button on Foundry v14 (tokens group + onChange)
Button registered on notes/onClick did not appear on v14. Now matches the Zero
Engine system pattern: token group, visible+button, onChange. Open via the skull
icon in the token toolbar or game.slaBlueprintNewsZero.open().

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17 19:32:43 +01:00

70 lines
2.4 KiB
JavaScript

/**
* SLA Blueprint News — entry point.
*
* Thin Foundry wrapper around the engine-agnostic component vendored under
* module/vendor/. Registers a global API and a Journal-directory button that
* opens the generator; the generator writes briefings into journal entries.
*/
import { BlueprintNewsApp } from "./app/generator-app.mjs";
const MODULE_ID = "sla-blueprint-news-zero";
Hooks.once("init", () => {
game.slaBlueprintNewsZero = { open: () => BlueprintNewsApp.open() };
});
/* Journal directory header button (GM only) — the natural home, since this
tool produces journal entries. */
Hooks.on("renderJournalDirectory", (_app, html) => {
if (!game.user?.isGM) return;
const root = html instanceof HTMLElement ? html : html?.[0];
if (!root) return;
const header =
root.querySelector(".directory-header .action-buttons") ??
root.querySelector(".directory-header .header-actions") ??
root.querySelector(".directory-header");
if (!header || header.querySelector(".sla-bpn-zero-open")) return;
const btn = document.createElement("button");
btn.type = "button";
btn.className = "sla-bpn-open sla-bpn-zero-open";
btn.innerHTML = `<i class="fas fa-skull"></i> Blueprint News 0E`;
btn.addEventListener("click", () => BlueprintNewsApp.open());
header.appendChild(btn);
});
/* Token-group toolbar button (GM only). Mirrors the Zero Engine system's own
scene-control registration, which is the pattern verified on Foundry v14.361:
v14 controls is a keyed object and tools fire via onChange; v13 is an array. */
Hooks.on("getSceneControlButtons", (controls) => {
if (!game.user?.isGM) return;
const open = () => BlueprintNewsApp.open();
const tool = {
name: "slaBpnZeroOpen",
title: "Blueprint News 0 Engine",
icon: "fas fa-skull",
visible: true,
button: true,
toggle: false,
onChange: open,
onClick: open
};
// Foundry v14: controls is a plain object keyed by group name.
if (controls && !Array.isArray(controls)) {
const grp = controls.tokens ?? controls.token ?? null;
if (grp) {
grp.tools ??= {};
grp.tools[tool.name] = tool;
}
return;
}
// Foundry v13 fallback: controls is an array.
const grp = controls.find((c) => c.name === "token" || c.name === "tokens");
if (grp) {
if (Array.isArray(grp.tools)) grp.tools.push(tool);
else { grp.tools ??= {}; grp.tools[tool.name] = tool; }
}
});