Files
mapwright/module/lib/population.mjs
T
slaguru666andClaude Opus 4.8 100e514c4d 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>
2026-06-17 15:05:25 +01:00

76 lines
2.2 KiB
JavaScript

/**
* System-agnostic map population.
*
* Works in ANY Foundry world: never assumes a game system, actors, or
* compendia. Labelled rooms/features become GM map Notes; optional ambient
* lights add atmosphere. Lightweight by design.
*/
const MODULE_ID = "mapwright";
const BOOK_ICON = "icons/svg/book.svg";
function note(x, y, text, gs, kind) {
return {
x: Math.round(x * gs),
y: Math.round(y * gs),
text,
texture: { src: BOOK_ICON },
iconSize: Math.max(32, Math.round(gs * 0.5)),
fontSize: Math.max(16, Math.round(gs * 0.24)),
global: false,
flags: { [MODULE_ID]: { generated: true, kind } }
};
}
/** Notes for each labelled building room. */
export function buildRoomNotes(layout, gs) {
const out = [];
for (const room of layout.rooms) {
if (!room.label) continue;
out.push(note(room.cx, room.cy, room.locked ? `${room.label} (locked)` : room.label, gs, "room-note"));
}
return out;
}
/** Notes for cave/outdoor feature points ({x,y,label}). */
export function buildFeatureNotes(features, gs) {
return (features ?? []).map((f) => note(f.x, f.y, f.label, gs, "feature-note"));
}
/** Soft ambient light per building room. */
export function buildRoomLights(layout, gs, subtype) {
return layout.rooms.map((room) => ({
x: Math.round(room.cx * gs),
y: Math.round(room.cy * gs),
walls: true,
vision: false,
config: {
dim: Math.round(Math.max(room.w, room.h) * gs * 0.9),
bright: Math.round(Math.max(room.w, room.h) * gs * 0.35),
color: subtype === "fantasy" ? "#ffb46b" : "#fdf6e3",
luminosity: 0.35,
alpha: 0.35
},
flags: { [MODULE_ID]: { generated: true } }
}));
}
/** A warm torch light at each cave feature point. */
export function buildFeatureLights(features, gs, animate = true) {
return (features ?? []).map((f) => ({
x: Math.round(f.x * gs),
y: Math.round(f.y * gs),
walls: true,
vision: false,
config: {
dim: Math.round(gs * 4),
bright: Math.round(gs * 1.6),
color: "#ff9d4a",
luminosity: 0.4,
alpha: 0.3,
animation: animate ? { type: "torch", speed: 3, intensity: 4 } : {}
},
flags: { [MODULE_ID]: { generated: true } }
}));
}