Cosmic Quest

Cosmic Quest

CURRENT SYSTEM:

Sol System (Earth)

Mission Control is tracking an anomaly. Scans suggest it originated from the Alpha Centauri system.

CAPTAIN'S LOG:

Log entry 1: Our quest begins. We must find Planet X!

Your browser does not support the canvas element.

${entry}

` ).join(''); if (modalPdfContent) modalPdfContent.innerHTML = logHtml; if (pdfLogContent) pdfLogContent.innerHTML = pdfLogHtml; if (winModal) winModal.classList.remove('hidden'); if (winModal) winModal.classList.add('flex'); } /** * Generates and downloads a PDF of the quest report. */ async function downloadPDF() { if (!jspdfLoaded || !html2canvasLoaded) { alert('PDF generation libraries are not loaded. Please try again.'); return; } if (!pdfContentDiv) { alert('Error: Could not find PDF content to download.'); return; } const { jsPDF } = window.jspdf; if (downloadPdfBtn) { downloadPdfBtn.textContent = 'Generating...'; downloadPdfBtn.disabled = true; } // Show the hidden content pdfContentDiv.classList.remove('hidden'); try { const canvas = await window.html2canvas(pdfContentDiv, { scale: 2, // Increase resolution backgroundColor: '#ffffff' }); // Hide the content again pdfContentDiv.classList.add('hidden'); const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'portrait', unit: 'mm', format: 'a4' }); const imgProps = pdf.getImageProperties(imgData); const pdfWidth = pdf.internal.pageSize.getWidth() - 20; // A4 width with 10mm margins const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 10, 10, pdfWidth, pdfHeight); pdf.save('Cosmic_Quest_Report.pdf'); } catch (error) { console.error('Error generating PDF:', error); alert('An error occurred while generating the PDF.'); } finally { if (downloadPdfBtn) { downloadPdfBtn.textContent = 'Download Quest Report'; downloadPdfBtn.disabled = false; } } } // --- Event Listeners --- if (resetBtn) resetBtn.addEventListener('click', initGame); if (playAgainBtn) playAgainBtn.addEventListener('click', initGame); if (downloadPdfBtn) downloadPdfBtn.addEventListener('click', downloadPDF); // Resize canvas on window resize for responsiveness window.addEventListener('resize', drawStarMap); // --- Start Game --- initGame(); });