AI Robot Battle Simulator
Robot 1 Configuration
Robot 2 Configuration
Battle Log ID
Combatant Profiles
Arena
Arena description...
Combat Log
Initializing simulation...
Outcome
Calculating results...
/g, '').replace(/<\/p>/g, '\n') .trim(); const logLines = doc.splitTextToSize(logTextForPDF, textWidth); logLines.forEach(line => { const requiredHeight = (normalFontSize * 0.4); // Approx height per line if (yPos + requiredHeight > doc.internal.pageSize.getHeight() - 15) { doc.addPage(); yPos = 15; doc.setFont(logFont, 'normal'); doc.setFontSize(normalFontSize - 1); doc.setTextColor(textColorPDF); } // Basic indent for log lines after timestamp/turn marker if (line.match(/^--- Turn \d+ ---/) || line.match(/^M-DAY \d+\.\d+:/) || line.match(/^-{20,}/)) { doc.text(line, leftMargin, yPos); } else { doc.text(line, leftMargin + 3, yPos); // Indent subsequent lines } yPos += lineSpacing; // Move to the next line position }); yPos += sectionSpacing; // Outcome if (yPos + 15 > doc.internal.pageSize.getHeight() - 15) { doc.addPage(); yPos = 15; } doc.setFontSize(subHeadingFontSize); doc.setFont(titleFont, 'bold'); doc.setTextColor(secondaryColorPDF); // Orange outcome title doc.text("Final Outcome:", leftMargin, yPos); yPos += lineSpacing * 1.5; doc.setFontSize(normalFontSize + 1); doc.setFont(titleFont, 'bold'); doc.setTextColor(textColorPDF); const outcomeLines = doc.splitTextToSize(currentBattleLog.outcome, textWidth); doc.text(outcomeLines, leftMargin, yPos); // Save PDF const safeID = currentBattleLog.battleID.replace(/[^a-z0-9]/gi, '_').toLowerCase(); doc.save(`ai_battle_log_${safeID}.pdf`); } catch(error) { console.error("Error generating PDF:", error); alert("System malfunction! Failed to download battle log PDF. Check console (F12)."); } finally { downloadBtn.disabled = false; // Re-enable button downloadBtn.textContent = "Download Battle Log (PDF)"; } }, 50); // 50ms delay for UI update }); }); // End DOMContentLoaded
