Conflict Resolution Simulator
Loading Scenario...
Please wait.
${node.feedback}
`; feedbackAreaEl.style.display = 'block'; // Log feedback userPath.push({ type: 'feedback', text: node.feedback }); // Add a restart button const restartBtn = document.createElement('button'); restartBtn.type = 'button'; // IV.D.1 restartBtn.className = 'simulator-choice-btn'; restartBtn.textContent = 'Run Simulation Again'; restartBtn.onclick = startSimulation; choicesAreaEl.appendChild(restartBtn); // Enable PDF download downloadPdfBtn.disabled = false; } else { // This is a choice node feedbackAreaEl.style.display = 'none'; node.choices.forEach(choice => { const choiceBtn = document.createElement('button'); choiceBtn.type = 'button'; // IV.D.1 choiceBtn.className = 'simulator-choice-btn'; choiceBtn.textContent = choice.text; choiceBtn.onclick = () => { // Log the choice made userPath.push({ type: 'choice', text: choice.text }); handleChoice(choice.nextNode); }; choicesAreaEl.appendChild(choiceBtn); }); } } function handleChoice(nextNodeId) { renderNode(nextNodeId); } function loadDefaultScenario() { jsonConfigTextarea.value = JSON.stringify(defaultScenario, null, 2); if (loadScenario(jsonConfigTextarea.value)) { startSimulation(); } } function downloadPdfReport() { if (userPath.length === 0) return; const { jsPDF } = window.jspdf; const doc = new jsPDF(); const pageHeight = doc.internal.pageSize.height; const margin = 20; const cellMargin = 10; let currentY = margin; doc.setFontSize(18); doc.setFont(undefined, 'bold'); doc.text("Conflict Simulation Report", margin, currentY); currentY += cellMargin; doc.setFontSize(14); doc.text(`Scenario: ${scenarioData.title}`, margin, currentY); currentY += cellMargin * 2; const checkPageBreak = (spaceNeeded) => { if (currentY + spaceNeeded > pageHeight - margin) { doc.addPage(); currentY = margin; } }; userPath.forEach(item => { let splitText; if (item.type === 'step') { checkPageBreak(30); // Check space doc.setFontSize(12); doc.setFont(undefined, 'bold'); doc.text("Situation:", margin, currentY); currentY += cellMargin * 0.7; doc.setFont(undefined, 'normal'); splitText = doc.splitTextToSize(item.text, doc.internal.pageSize.width - margin*2); doc.text(splitText, margin + 5, currentY); currentY += (splitText.length * 5) + cellMargin; } else if (item.type === 'choice') { checkPageBreak(30); doc.setFontSize(11); doc.setFont(undefined, 'italic'); doc.setTextColor(80, 80, 80); splitText = doc.splitTextToSize(`Your Choice: ${item.text}`, doc.internal.pageSize.width - margin*2); doc.text(splitText, margin, currentY); currentY += (splitText.length * 5) + cellMargin; doc.setTextColor(0, 0, 0); } else if (item.type === 'feedback') { checkPageBreak(40); doc.setFontSize(14); doc.setFont(undefined, 'bold'); doc.setFillColor(248, 249, 250); // --background-color doc.rect(margin, currentY, doc.internal.pageSize.width - margin*2, 10, 'F'); doc.text("Final Outcome:", margin, currentY + 7); currentY += cellMargin * 1.5; doc.setFont(undefined, 'normal'); doc.setFontSize(12); splitText = doc.splitTextToSize(item.text, doc.internal.pageSize.width - margin*2 - 10); doc.text(splitText, margin + 5, currentY); currentY += (splitText.length * 5) + cellMargin; } }); doc.save('conflict-simulation-report.pdf'); } // --- Tab Navigation --- function switchTab(tabIndex) { tabs.forEach((tab, index) => { tab.classList.toggle('active', index === tabIndex); contents[index].classList.toggle('active', index === tabIndex); }); currentTab = tabIndex; updateNavButtons(); } function updateNavButtons() { prevBtn.disabled = currentTab === 0; nextBtn.disabled = currentTab === tabs.length - 1; } tabs.forEach((tab, index) => { tab.addEventListener('click', () => switchTab(index)); }); nextBtn.addEventListener('click', () => { if (currentTab < tabs.length - 1) switchTab(currentTab + 1); }); prevBtn.addEventListener('click', () => { if (currentTab > 0) switchTab(currentTab - 1); }); // --- Event Listeners --- configForm.addEventListener('submit', (e) => { e.preventDefault(); if (loadScenario(jsonConfigTextarea.value)) { startSimulation(); switchTab(0); // Switch to simulator } }); resetBtn.addEventListener('click', () => { if (confirm("Are you sure you want to reset to the default scenario? Any unsaved changes will be lost.")) { loadDefaultScenario(); } }); downloadPdfBtn.addEventListener('click', downloadPdfReport); // --- Initial Setup --- updateNavButtons(); loadDefaultScenario(); });