Alien Invasion Roleplay Scenario Generator

Generate a starting situation for your survival, resistance, or collaboration amidst extraterrestrial threats!

${generatedScenarioData.objective}

${generatedScenarioData.complication ? `

Complication:

${generatedScenarioData.complication}

` : ''} `; resultsDiv.style.display = 'block'; pdfBtn.disabled = false; } // --- PDF Download Function --- function downloadPDF() { if (!generatedScenarioData || !generatedScenarioData.setting) { alert("Please generate a scenario first."); return; } // Ensure jsPDF is loaded if (typeof jspdf === 'undefined' || typeof jspdf.jsPDF === 'undefined') { console.error("jsPDF library or jsPDF constructor is not loaded correctly."); alert("Error: PDF generation library failed to load. Please check internet connection or Elementor setup."); return; } const { jsPDF } = jspdf; const doc = new jsPDF(); // --- PDF Styling --- const primaryColor = '#c62828'; // Red const secondaryColor = '#455a64'; // Blue Grey const accentColor = '#ff8f00'; // Amber const textColor = '#263238'; // Dark Slate const pageMargin = 15; const lineSpacing = 7; let currentY = pageMargin; const pageHeight = doc.internal.pageSize.height; const pageWidth = doc.internal.pageSize.width; // Helper to add text with page breaks function addTextToPDF(text, size, color, style = 'normal') { doc.setFont("helvetica", style); // Use standard font doc.setFontSize(size); doc.setTextColor(color); const splitText = doc.splitTextToSize(text, pageWidth - pageMargin * 2); splitText.forEach(line => { if (currentY + lineSpacing > pageHeight - pageMargin) { doc.addPage(); currentY = pageMargin; // Reset font on new page doc.setFont("helvetica", style); doc.setFontSize(size); doc.setTextColor(color); } doc.text(line, pageMargin, currentY); currentY += lineSpacing; }); } function addHeadingPDF(text) { addTextToPDF(text, 14, primaryColor, 'bold'); // Red heading currentY += lineSpacing * 0.2; } function addSubHeadingPDF(text) { addTextToPDF(text, 11, secondaryColor, 'bold'); currentY -= lineSpacing * 0.4; // Reduce space after subheading } function addParagraphPDF(text) { addTextToPDF(text, 10, textColor); currentY += lineSpacing * 0.3; // Space after paragraph } // --- PDF Content --- addHeadingPDF("Alien Invasion Scenario"); addParagraphPDF(`Location: ${generatedScenarioData.location} (${generatedScenarioData.locationType}) | Stage: ${generatedScenarioData.stage}`); currentY += lineSpacing * 0.5; addSubHeadingPDF("Setting:"); addParagraphPDF(generatedScenarioData.setting); addSubHeadingPDF("Your Role:"); addParagraphPDF(generatedScenarioData.role); addSubHeadingPDF("Starting Situation:"); addParagraphPDF(generatedScenarioData.situation); addSubHeadingPDF("Objective:"); addParagraphPDF(generatedScenarioData.objective); if (generatedScenarioData.complication) { addSubHeadingPDF("Complication:"); // Use accent color for complication text in PDF addTextToPDF(generatedScenarioData.complication, 10, accentColor, 'italic'); } // --- Save PDF --- const safeFileName = `invasion_scenario_${generatedScenarioData.role.split(' ')[0]}_${generatedScenarioData.locationType.split(' ')[0]}`.replace(/[^a-z0-9_]/gi, '_').toLowerCase(); doc.save(`${safeFileName}.pdf`); } // --- Event Listeners --- if (generateBtn) { generateBtn.addEventListener('click', generateScenario); } else { console.error("Generate button not found!"); } if (pdfBtn) { pdfBtn.addEventListener('click', downloadPDF); } else { console.error("PDF button not found!"); } })(); // Immediately invoke the function
Scroll to Top