Mapwright v0.5.0 — procedural battle map generator for Foundry VTT
Buildings (modern/fantasy, multi-floor, footprint shapes), caves, outdoor biomes, and town/village + city-block settlements. Auto-places Foundry walls, doors, windows, lighting; furniture as locked tiles; live preview. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* Mapwright — entry point.
|
||||
*
|
||||
* Registers the toolbar button + a global API hook. The heavy lifting lives in
|
||||
* lib/* (pure, Node-testable) and app/* (the dialog).
|
||||
*/
|
||||
|
||||
import { MapwrightApp } from "./app/generator-app.mjs";
|
||||
|
||||
const MODULE_ID = "mapwright";
|
||||
|
||||
Hooks.once("init", () => {
|
||||
game.mapwright = { open: () => MapwrightApp.open() };
|
||||
});
|
||||
|
||||
// Toolbar button on the Walls control group (v13 array-or-object shape).
|
||||
Hooks.on("getSceneControlButtons", (controls) => {
|
||||
if (!game.user?.isGM) return;
|
||||
|
||||
const tool = {
|
||||
name: "mapwrightOpen",
|
||||
title: game.i18n.localize("MAPWRIGHT.ToolbarOpen"),
|
||||
icon: "fas fa-map",
|
||||
button: true,
|
||||
onClick: () => MapwrightApp.open()
|
||||
};
|
||||
|
||||
if (Array.isArray(controls)) {
|
||||
const walls = controls.find((c) => c.name === "walls");
|
||||
if (walls) {
|
||||
walls.tools ??= [];
|
||||
if (!walls.tools.some((t) => t.name === tool.name)) walls.tools.push(tool);
|
||||
} else {
|
||||
controls.push({ name: MODULE_ID, title: "Mapwright", icon: "fas fa-map", layer: "walls", tools: [tool] });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (controls && typeof controls === "object") {
|
||||
const walls = controls.walls;
|
||||
if (walls) {
|
||||
walls.tools ??= {};
|
||||
walls.tools[tool.name] ??= tool;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Scene directory header button as a second entry point.
|
||||
Hooks.on("renderSceneDirectory", (_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(".header-actions");
|
||||
if (!header || header.querySelector(".mapwright-open")) return;
|
||||
const btn = document.createElement("button");
|
||||
btn.type = "button";
|
||||
btn.className = "mapwright-open";
|
||||
btn.innerHTML = `<i class="fas fa-map"></i> ${game.i18n.localize("MAPWRIGHT.SceneButton")}`;
|
||||
btn.addEventListener("click", () => MapwrightApp.open());
|
||||
header.appendChild(btn);
|
||||
});
|
||||
Reference in New Issue
Block a user