337 lines
8.6 KiB
JavaScript
337 lines
8.6 KiB
JavaScript
function pickRandom(arr) {
|
|
return arr[Math.floor(Math.random() * arr.length)];
|
|
}
|
|
|
|
export function dungeonTemplate(data) {
|
|
const bodyFonts = [
|
|
"'Lora', serif",
|
|
"'Merriweather', serif",
|
|
"'Libre Baskerville', serif",
|
|
"'Source Serif 4', serif"
|
|
];
|
|
|
|
const headingFonts = [
|
|
"'New Rocker', system-ui",
|
|
"'UnifrakturCook', cursive",
|
|
"'IM Fell DW Pica', serif",
|
|
"'Cinzel', serif",
|
|
"'Cormorant Garamond', serif",
|
|
"'Playfair Display', serif"
|
|
];
|
|
|
|
const tableFonts = [
|
|
"'Alegreya Sans', sans-serif",
|
|
"'Cabin', sans-serif",
|
|
"'IBM Plex Sans', sans-serif",
|
|
"'Cormorant Garamond', serif"
|
|
];
|
|
|
|
const quoteFonts = [
|
|
"'Playfair Display', serif",
|
|
"'Libre Baskerville', serif",
|
|
"'Merriweather', serif"
|
|
];
|
|
|
|
const bodyFont = pickRandom(bodyFonts);
|
|
const headingFont = pickRandom(headingFonts);
|
|
const tableFont = pickRandom(tableFonts);
|
|
const quoteFont = pickRandom(quoteFonts);
|
|
|
|
// Check if we have a map image to include
|
|
const hasMap = data.map && typeof data.map === 'string' && data.map.startsWith('data:image/');
|
|
|
|
return `
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>${data.title}</title>
|
|
<link
|
|
href="https://fonts.googleapis.com/css2?family=Cinzel+Decorative&family=UnifrakturCook&family=New+Rocker&family=Metamorphous&family=Playfair+Display&family=Alegreya+Sans&family=Cabin&family=IBM+Plex+Sans&family=Cormorant+Garamond&family=Lora&family=Merriweather&family=Libre+Baskerville&family=Source+Serif+4&family=Walter+Turncoat&family=Uncial+Antiqua&family=Beth+Ellen&family=Pinyon+Script&display=swap"
|
|
rel="stylesheet">
|
|
<style>
|
|
@page {
|
|
size: A4 landscape;
|
|
margin: 0;
|
|
}
|
|
body {
|
|
margin: 0;
|
|
padding: 0;
|
|
font-family: ${bodyFont};
|
|
color: #1a1a1a;
|
|
font-size: 0.65em;
|
|
line-height: 1.2em;
|
|
}
|
|
.content-page {
|
|
height: 100vh;
|
|
box-sizing: border-box;
|
|
padding: 1.2cm;
|
|
page-break-after: always;
|
|
overflow: hidden;
|
|
break-inside: avoid;
|
|
}
|
|
h1 {
|
|
font-family: ${headingFont};
|
|
text-align: center;
|
|
text-transform: uppercase;
|
|
font-size: 1.8em;
|
|
margin: 0.15em 0 0.2em;
|
|
color: #1a1a1a;
|
|
border-bottom: 2px solid #1a1a1a;
|
|
padding-bottom: 0.15em;
|
|
letter-spacing: 0.1em;
|
|
}
|
|
.flavor {
|
|
text-align: center;
|
|
font-style: italic;
|
|
font-family: ${quoteFont};
|
|
margin: 0.3em 0 0.6em;
|
|
font-size: 0.85em;
|
|
line-height: 1.2em;
|
|
}
|
|
.columns {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr 1fr;
|
|
gap: 0.4cm;
|
|
align-items: start;
|
|
}
|
|
.col {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.15em;
|
|
overflow-wrap: break-word;
|
|
word-break: break-word;
|
|
}
|
|
.section-block {
|
|
break-inside: avoid;
|
|
page-break-inside: avoid;
|
|
margin-bottom: 0.25em;
|
|
}
|
|
h2 {
|
|
font-family: ${headingFont};
|
|
font-size: 0.95em;
|
|
margin: 0.2em 0 0.2em;
|
|
color: #1a1a1a;
|
|
border-bottom: 1px solid #1a1a1a;
|
|
padding-bottom: 0.08em;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
break-inside: avoid;
|
|
page-break-inside: avoid;
|
|
}
|
|
.room {
|
|
break-inside: avoid;
|
|
page-break-inside: avoid;
|
|
}
|
|
.room h3 {
|
|
margin: 0.15em 0 0.08em;
|
|
font-size: 0.85em;
|
|
font-weight: bold;
|
|
color: #1a1a1a;
|
|
}
|
|
.room p {
|
|
margin: 0 0 0.35em;
|
|
font-size: 0.8em;
|
|
font-weight: normal;
|
|
line-height: 1.25em;
|
|
}
|
|
.encounter, .npc, .treasure, .plot-resolution {
|
|
margin: 0 0 0.3em;
|
|
break-inside: avoid;
|
|
page-break-inside: avoid;
|
|
font-size: 0.8em;
|
|
line-height: 1.25em;
|
|
}
|
|
.random-events {
|
|
margin: 0.2em 0;
|
|
break-inside: avoid;
|
|
page-break-inside: avoid;
|
|
font-size: 0.8em;
|
|
}
|
|
.random-events table {
|
|
margin-top: 0.15em;
|
|
}
|
|
.encounter strong, .npc strong, .treasure strong {
|
|
font-weight: bold;
|
|
}
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
margin: 0.2em 0;
|
|
font-size: 0.8em;
|
|
break-inside: avoid;
|
|
page-break-inside: avoid;
|
|
border: 1px solid #1a1a1a;
|
|
}
|
|
table th {
|
|
font-family: ${headingFont};
|
|
text-align: left;
|
|
border-bottom: 1px solid #1a1a1a;
|
|
padding: 0.15em 0.3em;
|
|
font-size: 0.85em;
|
|
text-transform: uppercase;
|
|
font-weight: bold;
|
|
}
|
|
table td {
|
|
padding: 0.2em 0.3em;
|
|
vertical-align: top;
|
|
line-height: 1.3em;
|
|
border-bottom: 1px solid #1a1a1a;
|
|
}
|
|
table tr:last-child td {
|
|
border-bottom: 1px solid #1a1a1a;
|
|
}
|
|
table td:first-child {
|
|
font-weight: bold;
|
|
width: 2em;
|
|
text-align: center;
|
|
border-right: 1px solid #1a1a1a;
|
|
}
|
|
.encounters-table td:nth-child(2) {
|
|
font-weight: bold;
|
|
width: 30%;
|
|
padding-right: 0.5em;
|
|
border-right: 1px solid #1a1a1a;
|
|
}
|
|
.encounters-table td:nth-child(3) {
|
|
width: auto;
|
|
}
|
|
.map-page {
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
page-break-before: always;
|
|
}
|
|
.map-container {
|
|
text-align: center;
|
|
margin: 1em 0;
|
|
}
|
|
.map-container img {
|
|
max-width: 100%;
|
|
max-height: calc(100vh - 3cm);
|
|
border: 1px solid #1a1a1a;
|
|
}
|
|
ul {
|
|
margin: 0.2em 0;
|
|
padding-left: 1.2em;
|
|
}
|
|
li {
|
|
margin: 0.08em 0;
|
|
font-size: 0.8em;
|
|
line-height: 1.25em;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="content-page">
|
|
<h1>${data.title}</h1>
|
|
${data.flavor ? `<p class="flavor">${data.flavor}</p>` : ''}
|
|
|
|
<div class="columns">
|
|
<div class="col">
|
|
${data.hooksRumors && data.hooksRumors.length > 0 ? `
|
|
<div class="section-block">
|
|
<h2>Hooks & Rumors</h2>
|
|
<ul>
|
|
${data.hooksRumors.map(hook => `<li>${hook}</li>`).join('')}
|
|
</ul>
|
|
</div>
|
|
` : ''}
|
|
|
|
${data.randomEvents && data.randomEvents.length > 0 ? `
|
|
<div class="section-block random-events">
|
|
<h2>Random Events (d6)</h2>
|
|
<table>
|
|
<tbody>
|
|
${data.randomEvents.map((event, index) => `
|
|
<tr>
|
|
<td>${index + 1}</td>
|
|
<td>${event}</td>
|
|
</tr>
|
|
`).join('')}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
` : ''}
|
|
|
|
${data.rooms && data.rooms.length > 0 ? `
|
|
<div class="section-block">
|
|
<h2>Locations</h2>
|
|
${data.rooms.map(room => `
|
|
<div class="room">
|
|
<h3>${room.name}</h3>
|
|
<p>${room.description}</p>
|
|
</div>
|
|
`).join('')}
|
|
</div>
|
|
` : ''}
|
|
</div>
|
|
|
|
<div class="col">
|
|
${data.encounters && data.encounters.length > 0 ? `
|
|
<div class="section-block">
|
|
<h2>Encounters (d6)</h2>
|
|
<table class="encounters-table">
|
|
<tbody>
|
|
${data.encounters.map((encounter, index) => `
|
|
<tr>
|
|
<td>${index + 1}</td>
|
|
<td><strong>${encounter.name}</strong></td>
|
|
<td>${encounter.details}</td>
|
|
</tr>
|
|
`).join('')}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
` : ''}
|
|
</div>
|
|
|
|
<div class="col">
|
|
${data.treasure && data.treasure.length > 0 ? `
|
|
<div class="section-block">
|
|
<h2>Treasure</h2>
|
|
${data.treasure.map(item => `
|
|
<div class="treasure">
|
|
${typeof item === 'object' && item.name ? `<strong>${item.name}</strong> — ${item.description}` : item}
|
|
</div>
|
|
`).join('')}
|
|
</div>
|
|
` : ''}
|
|
|
|
${data.npcs && data.npcs.length > 0 ? `
|
|
<div class="section-block">
|
|
<h2>NPCs</h2>
|
|
${data.npcs.map(npc => `
|
|
<div class="npc">
|
|
<strong>${npc.name}</strong>: ${npc.trait}
|
|
</div>
|
|
`).join('')}
|
|
</div>
|
|
` : ''}
|
|
|
|
${data.plotResolutions && data.plotResolutions.length > 0 ? `
|
|
<div class="section-block">
|
|
<h2>Plot Resolutions</h2>
|
|
${data.plotResolutions.map(resolution => `
|
|
<div class="plot-resolution">
|
|
${resolution}
|
|
</div>
|
|
`).join('')}
|
|
</div>
|
|
` : ''}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
${hasMap ? `
|
|
<div class="content-page map-page">
|
|
<div class="map-container">
|
|
<img src="${data.map}" alt="Dungeon Map" />
|
|
</div>
|
|
</div>
|
|
` : ''}
|
|
</body>
|
|
</html>
|
|
`;
|
|
}
|