Science Fiction Story Idea Generator
Input cosmic variables to generate a unique story concept.
Cosmic Parameters
Awaiting Transmission...
Provide story parameters to unlock a new universe.
Calculating orbital mechanics...
Transmission Failed!
Could not generate story idea. Please check the console and try again.
${data.opening_scene || 'N/A'}
`; default: return 'No content available.
'; } } function showTab(index) { const tabs = tabsContainer.querySelectorAll('.tab'); const contents = tabContentsContainer.querySelectorAll('.tab-content'); tabs.forEach(tab => tab.classList.remove('active')); contents.forEach(content => content.classList.remove('active')); if(tabs[index]) tabs[index].classList.add('active'); if(contents[index]) contents[index].classList.add('active'); currentTabIndex = index; updateNavButtons(); } function navigateTabs(direction) { const newIndex = currentTabIndex + direction; if (newIndex >= 0 && newIndex < tabConfig.length) showTab(newIndex); } function updateNavButtons() { prevTabBtn.disabled = currentTabIndex === 0; nextTabBtn.disabled = currentTabIndex === tabConfig.length - 1; } function generatePdf() { if (!window.jspdf || !latestGeneratedData) { alert("Please generate a story idea before downloading."); return; } const { jsPDF } = window.jspdf; const doc = new jsPDF({ orientation: 'portrait', unit: 'pt', format: 'a4' }); const pageHeight = doc.internal.pageSize.getHeight(); const pageWidth = doc.internal.pageSize.getWidth(); const margin = 50; const contentWidth = pageWidth - margin * 2; let cursorY = 0; let pageCount = 1; const addFooter = () => { doc.setFontSize(8); doc.setFont("courier", "normal"); doc.setTextColor(148, 163, 184); // Slate-400 doc.text(`// DATAPACKET END // PAGE ${pageCount}`, pageWidth - margin, pageHeight - 20, { align: 'right' }); }; const checkPageBreak = (neededHeight) => { if (cursorY + neededHeight > pageHeight - margin) { addFooter(); doc.addPage(); pageCount++; cursorY = margin; addHeader(false); } }; const addHeader = (isFirstPage = true) => { doc.setFont("courier", "bold"); doc.setTextColor(100, 116, 139); // Slate-500 doc.setFontSize(9); doc.text("SYS_MSG: DECRYPTED TRANSMISSION", margin, margin - 20); doc.setDrawColor(226, 232, 240); // Slate-200 doc.rect(margin-10, margin - 10, contentWidth + 20, pageHeight - margin*2 + 20); // Border around content cursorY = margin + 10; if (isFirstPage) { doc.setFont("courier", "bold"); doc.setFontSize(22); doc.setTextColor(30, 41, 59); // Slate-800 const titleLines = doc.splitTextToSize(latestGeneratedData.title.toUpperCase() || "UNTITLED PROJECT", contentWidth); doc.text(titleLines, margin, cursorY + 10); cursorY += (titleLines.length * 22); doc.setFont("courier", "normal"); doc.setFontSize(10); doc.setTextColor(71, 85, 105); // Slate-600 doc.text(`> SUBGENRE: ${sciFiSubgenreEl.value}`, margin, cursorY + 15); doc.text(`> CONCEPT: ${coreConceptEl.value}`, margin, cursorY + 28); cursorY += 45; } }; const drawSectionTitle = (title) => { checkPageBreak(30); doc.setFont("courier", "bold"); doc.setFontSize(11); doc.setTextColor(14, 116, 144); // Cyan-700 doc.text(`// ${title.toUpperCase()}`, margin, cursorY); cursorY += 20; }; const drawParagraph = (text) => { doc.setFont("courier", "normal"); doc.setFontSize(10); doc.setTextColor(51, 65, 85); // Slate-700 const lines = doc.splitTextToSize(text || 'DATA NOT FOUND', contentWidth); checkPageBreak(lines.length * 11 + 10); doc.text(lines, margin, cursorY); cursorY += lines.length * 11 + 15; }; addHeader(true); drawSectionTitle("Logline"); drawParagraph(latestGeneratedData.logline); drawSectionTitle("Synopsis"); drawParagraph(latestGeneratedData.synopsis); drawSectionTitle("Key Characters"); latestGeneratedData.key_characters.forEach(char => { drawParagraph(`- ${char}`); }); drawSectionTitle("Worldbuilding Notes"); drawParagraph(latestGeneratedData.worldbuilding_notes); drawSectionTitle("Opening Scene"); drawParagraph(latestGeneratedData.opening_scene); addFooter(); const safeFileName = (latestGeneratedData.title || 'story_idea').replace(/[^a-z0-9]/gi, '_').toLowerCase(); doc.save(`${safeFileName}_datapacket.pdf`); } setUIState('placeholder'); });