Conflict Resolution Role-Play

Conflict Resolution Role-Play

${scene.perspectives[character]}

`; crrp_perspectives.appendChild(card); } // Render Choices crrp_choices.innerHTML = ""; // Clear choices if (scene.choices && scene.choices.length > 0) { scene.choices.forEach(choice => { const btn = document.createElement("button"); btn.type = "button"; btn.className = "crrp-choice-btn"; btn.textContent = choice.text; btn.dataset.nextSceneId = choice.nextSceneId; btn.addEventListener("click", crrp_handlePlayerChoice); crrp_choices.appendChild(btn); }); } else { const endText = document.createElement("p"); endText.id = "crrp-end-text"; endText.textContent = "End of Scene."; crrp_choices.appendChild(endText); } crrp_addRestartButton(crrp_choices); } function crrp_handlePlayerChoice(e) { const nextSceneId = e.currentTarget.dataset.nextSceneId; crrp_renderScene(nextSceneId); } function crrp_addRestartButton(container) { const restartBtn = document.createElement("button"); restartBtn.type = "button"; restartBtn.id = "crrp-restart-btn"; restartBtn.className = "crrp-choice-btn crrp-btn-secondary"; // Re-use style, change color restartBtn.textContent = "Restart Scenario"; restartBtn.addEventListener("click", () => crrp_renderScene(1)); // Always restart at scene 1 container.appendChild(restartBtn); } // --- TAB NAVIGATION --- window.crrp_showTab = function (tabIndex, element) { if (!crrp_tabPanels || !crrp_tabLinks) return; crrp_currentTab = tabIndex; crrp_tabPanels.forEach((panel) => panel.classList.remove("crrp-active")); crrp_tabLinks.forEach((link) => link.classList.remove("crrp-active")); if (crrp_tabPanels[tabIndex]) { crrp_tabPanels[tabIndex].classList.add("crrp-active"); } if (element) { element.classList.add("crrp-active"); } crrp_updateNavButtons(); }; function crrp_goToNextTab() { if (crrp_currentTab < crrp_tabPanels.length - 1) { crrp_currentTab++; crrp_showTab(crrp_currentTab, crrp_tabLinks[crrp_currentTab]); } } function crrp_goToPrevTab() { if (crrp_currentTab > 0) { crrp_currentTab--; crrp_showTab(crrp_currentTab, crrp_tabLinks[crrp_currentTab]); } } function crrp_updateNavButtons() { if (!crrp_prevBtn || !crrp_nextBtn) return; crrp_prevBtn.disabled = crrp_currentTab === 0; crrp_nextBtn.disabled = crrp_currentTab === crrp_tabPanels.length - 1; } // --- PDF EXPORT --- function crrp_downloadPDF() { if (typeof jspdf === "undefined") { console.error("jsPDF library not loaded."); alert("Error: PDF generation library failed to load."); return; } const scenario = crrp_scenariosData[crrp_currentScenarioId]; const scene = scenario.scenes[crrp_currentSceneId]; if (!scene) return; const { jsPDF } = jspdf; const doc = new jsPDF({ orientation: "p", unit: "pt", format: "a4", }); const margin = 40; const pageWidth = doc.internal.pageSize.getWidth(); const contentWidth = pageWidth - margin * 2; let yPos = margin; doc.setFont('helvetica', 'normal'); doc.setFontSize(18); doc.setFont('helvetica', 'bold'); doc.text(`Conflict Scenario: ${scenario.name}`, pageWidth / 2, yPos, { align: 'center' }); yPos += 30; doc.setFontSize(14); doc.text(`Scene: ${scene.title}`, margin, yPos); yPos += 25; doc.setFontSize(11); doc.setFont('helvetica', 'normal'); const sceneLines = doc.splitTextToSize(scene.text, contentWidth); doc.text(sceneLines, margin, yPos); yPos += (sceneLines.length * 11 * 1.5) + 20; // Approx line height doc.setFontSize(12); doc.setFont('helvetica', 'bold'); doc.text("Perspectives:", margin, yPos); yPos += 20; doc.setFontSize(10); doc.setFont('helvetica', 'normal'); for (const character in scene.perspectives) { if (yPos > doc.internal.pageSize.getHeight() - 60) { doc.addPage(); yPos = margin; } doc.setFont('helvetica', 'bold'); doc.text(character + ":", margin + 15, yPos); doc.setFont('helvetica', 'normal'); const perspectiveLines = doc.splitTextToSize(scene.perspectives[character], contentWidth - 30); doc.text(perspectiveLines, margin + 15, yPos + 12); yPos += (perspectiveLines.length * 10 * 1.5) + 15; } // Note: Choices are not included in the PDF as it represents a single moment. doc.save(`Conflict-RolePlay-${scenario.name.replace(/\s/g,'_')}-Scene.pdf`); } })();