Worldbuilding Generator
Craft the foundation of your new reality, from continents to cultures.
Your generated world profile will appear here once you complete the previous steps.
Central Conflict: ${worldData.conflict}
`; const contentDiv = document.getElementById('generated-world-content'); if (contentDiv) { contentDiv.innerHTML = worldHTML; lucide.createIcons(); } } tabs.forEach((tab, index) => { tab.addEventListener('click', () => updateTabUI(index)); }); nextBtn.addEventListener('click', () => { if (currentTab < totalTabs - 1) { if (currentTab === totalTabs - 2) generateWorld(); updateTabUI(currentTab + 1); } }); prevBtn.addEventListener('click', () => { if (currentTab > 0) updateTabUI(currentTab - 1); }); downloadPdfBtn.addEventListener('click', () => { const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' }); const getValue = id => document.getElementById(id)?.value.trim() || 'Not Provided'; const worldData = { name: getValue('world-name'), geography: getValue('world-geography'), landmarks: getValue('world-landmarks'), species: getValue('inhabitants-species'), society: getValue('inhabitants-society'), religion: getValue('inhabitants-religion'), powerType: getValue('power-type'), powerSource: getValue('power-source'), powerUsers: getValue('power-users'), historyEvent: getValue('history-event'), conflict: getValue('history-conflict') }; const pageW = doc.internal.pageSize.getWidth(); const pageH = doc.internal.pageSize.getHeight(); const margin = 18; const usableWidth = pageW - margin * 2; let y = 0; const tealColor = '#0D9488'; const darkGrayColor = '#374151'; const lightGrayColor = '#6B7280'; const addFooter = () => { const pageCount = doc.internal.getNumberOfPages(); for (let i = 1; i <= pageCount; i++) { doc.setPage(i); doc.setFontSize(9); doc.setTextColor(lightGrayColor); const footerText = `World Profile: ${worldData.name} | Page ${i} of ${pageCount}`; doc.text(footerText, pageW / 2, pageH - 10, { align: 'center' }); } }; const checkPageBreak = (heightNeeded) => { if (y + heightNeeded >= pageH - margin) { doc.addPage(); y = margin; } }; const addSectionHeader = (text) => { checkPageBreak(18); y += 10; doc.setFontSize(15); doc.setFont(undefined, 'bold'); doc.setTextColor(tealColor); doc.text(text, margin, y); y += 3; doc.setDrawColor(tealColor); doc.setLineWidth(0.5); doc.line(margin, y, pageW - margin, y); y += 8; }; const addContent = (label, value) => { const labelLines = doc.splitTextToSize(label, usableWidth); const valueLines = doc.splitTextToSize(value, usableWidth); const heightNeeded = (labelLines.length * 5) + (valueLines.length * 5) + 4; checkPageBreak(heightNeeded); y += 2; doc.setFontSize(11); doc.setFont(undefined, 'bold'); doc.setTextColor(darkGrayColor); doc.text(label, margin, y); y += labelLines.length * 5; doc.setFont(undefined, 'normal'); doc.setTextColor(lightGrayColor); doc.text(valueLines, margin + 2, y); y += valueLines.length * 5 + 4; // Add extra space after content }; // --- Build PDF --- // Title Page y = pageH / 3; doc.setFontSize(28); doc.setFont(undefined, 'bold'); doc.setTextColor(darkGrayColor); doc.text('World Profile', pageW / 2, y, { align: 'center' }); y += 20; doc.setFontSize(20); doc.setTextColor(tealColor); doc.text(worldData.name, pageW / 2, y, { align: 'center' }); doc.addPage(); y = margin; // Content Pages addSectionHeader('Physical World'); addContent('Core Geography & Climate:', worldData.geography); addContent('Key Landmarks:', worldData.landmarks.split('\n').join(', ')); addSectionHeader('Inhabitants & Culture'); addContent('Dominant Species:', worldData.species); addContent('Societal Structure:', worldData.society); addContent('Belief Systems:', worldData.religion); addSectionHeader('Power Systems'); addContent('Primary System:', worldData.powerType); addContent('Source of Power:', worldData.powerSource); addContent('Usage & Limitations:', worldData.powerUsers); addSectionHeader('History & Conflict'); addContent('Major Historical Event:', worldData.historyEvent); addContent('Central Conflict:', worldData.conflict); addFooter(); doc.save(`${worldData.name.replace(/\s+/g, '-')}-World-Profile.pdf`); }); updateTabUI(0); lucide.createIcons(); });