226 lines
5.4 KiB
JavaScript
226 lines
5.4 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);
|
|
|
|
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.7em;
|
|
line-height: 1.25em;
|
|
}
|
|
.content-page {
|
|
height: 100vh;
|
|
box-sizing: border-box;
|
|
padding: 1.5cm;
|
|
page-break-after: always;
|
|
overflow: hidden;
|
|
break-inside: avoid;
|
|
}
|
|
h1 {
|
|
font-family: ${headingFont};
|
|
text-align: center;
|
|
font-size: 2em;
|
|
margin: 0.2em 0 0.3em;
|
|
color: #1a1a1a;
|
|
border-bottom: 2px solid #1a1a1a;
|
|
padding-bottom: 0.2em;
|
|
letter-spacing: 0.1em;
|
|
}
|
|
.flavor {
|
|
text-align: center;
|
|
font-style: italic;
|
|
font-family: ${quoteFont};
|
|
margin: 0.4em 0 0.8em;
|
|
font-size: 0.9em;
|
|
}
|
|
.columns {
|
|
display: grid;
|
|
grid-template-columns: 1fr 1fr 1fr;
|
|
gap: 0.5cm;
|
|
align-items: start;
|
|
}
|
|
.col {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0.15em;
|
|
}
|
|
h2 {
|
|
font-family: ${headingFont};
|
|
font-size: 1.0em;
|
|
margin: 0.3em 0 0.1em;
|
|
color: #1a1a1a;
|
|
border-bottom: 1px solid #1a1a1a;
|
|
padding-bottom: 0.1em;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.05em;
|
|
}
|
|
.room h3 {
|
|
margin: 0.2em 0 0.05em;
|
|
font-size: 0.95em;
|
|
font-weight: bold;
|
|
}
|
|
.room p {
|
|
text-align: justify;
|
|
word-wrap: break-word;
|
|
margin: 0.1em 0 0.3em;
|
|
}
|
|
ul {
|
|
padding-left: 1em;
|
|
margin: 0.1em 0 0.3em;
|
|
}
|
|
li {
|
|
margin-bottom: 0.2em;
|
|
}
|
|
table {
|
|
width: 100%;
|
|
border-collapse: collapse;
|
|
font-family: ${tableFont};
|
|
font-size: 0.8em;
|
|
}
|
|
th,
|
|
td {
|
|
border: 1px solid #1a1a1a;
|
|
padding: 0.2em;
|
|
text-align: left;
|
|
vertical-align: top;
|
|
}
|
|
th {
|
|
background: #e0e0e0;
|
|
}
|
|
table tr:hover {
|
|
background: rgba(0, 0, 0, 0.05);
|
|
}
|
|
.map-page {
|
|
height: 210mm;
|
|
width: 297mm;
|
|
box-sizing: border-box;
|
|
padding: 1.5cm;
|
|
position: relative;
|
|
display: block;
|
|
}
|
|
.map-image-container {
|
|
position: absolute;
|
|
top: 1.5cm;
|
|
left: 1.5cm;
|
|
right: 1.5cm;
|
|
bottom: 3cm;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
.map-page img {
|
|
max-width: 100%;
|
|
max-height: 100%;
|
|
object-fit: contain;
|
|
}
|
|
.map-page footer {
|
|
position: absolute;
|
|
bottom: 1.5cm;
|
|
left: 1.5cm;
|
|
right: 1.5cm;
|
|
text-align: center;
|
|
font-size: 0.65em;
|
|
color: #555;
|
|
font-style: italic;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="content-page">
|
|
<h1>${data.title}</h1>
|
|
<p class="flavor">${data.flavor}</p>
|
|
<div class="columns">
|
|
<div class="col">
|
|
<h2>Adventure Hooks & Rumors</h2>
|
|
<ul>${data.hooksRumors.map(item => `<li>${item}</li>`).join("")}</ul>
|
|
<h2>Locations</h2>
|
|
${data.rooms.map((room, i) => `<div class="room">
|
|
<h3>${i + 1}. ${room.name}</h3>
|
|
<p>${room.description}</p>
|
|
</div>`).join("")}
|
|
</div>
|
|
<div class="col">
|
|
<h2>Encounters</h2>
|
|
<table>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Details</th>
|
|
</tr>
|
|
${data.encounters.map(e => `<tr>
|
|
<td>${e.name}</td>
|
|
<td>${e.details}</td>
|
|
</tr>`).join("")}
|
|
</table>
|
|
<h2>Treasure</h2>
|
|
<ul>${data.treasure.map(t => `<li>${t}</li>`).join("")}</ul>
|
|
</div>
|
|
<div class="col">
|
|
<h2>NPCs</h2>
|
|
<ul>${data.npcs.map(n => `<li><b>${n.name}</b>: ${n.trait}</li>`).join("")}</ul>
|
|
<h2>Plot Resolutions</h2>
|
|
<ul>${data.plotResolutions.map(p => `<li>${p}</li>`).join("")}</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="map-page">
|
|
<div class="map-image-container">
|
|
<img src="${data.map}" alt="Dungeon Map">
|
|
</div>
|
|
<footer>Generated with Scrollsmith • © ${new Date().getFullYear()}</footer>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
`;
|
|
}
|