// Global Error Handler // Ujame kritične napake in prikaže prijazen "Crash Screen" namesto belega zaslona. export class ErrorHandler { static init() { window.onerror = (message, source, lineno, colno, error) => { ErrorHandler.showError(message, source, lineno, colno, error); // return true; // Če vrnemo true, zavremo izpis v konzolo (ne želimo tega) return false; }; window.addEventListener('unhandledrejection', (event) => { ErrorHandler.showError('Unhandled Promise Rejection', '', 0, 0, event.reason); }); console.log('🛡️ Global Error Handler Initialized'); } static showError(message, source, lineno, colno, error) { console.error('🔥 CRITICAL ERROR HAUGHT:', message); // Prepreči podvajanje overlayev if (document.getElementById('error-overlay')) return; // Ustvari overlay element const overlay = document.createElement('div'); overlay.id = 'error-overlay'; overlay.style.cssText = ` position: fixed; top: 0; left: 0; width: 100%; height: 100%; background-color: rgba(20, 0, 0, 0.95); color: #ffaaaa; z-index: 999999; display: flex; flex-direction: column; align-items: center; justify-content: center; font-family: 'Consolas', 'Courier New', monospace; text-align: center; padding: 20px; box-sizing: border-box; `; const title = document.createElement('h1'); title.innerText = '💀 OOPS! GAME CRASHED 💀'; title.style.color = '#ff4444'; title.style.marginBottom = '20px'; const msgBox = document.createElement('div'); msgBox.innerText = `${message}\n\nFile: ${source}\nLine: ${lineno}:${colno}\n\n${error ? error.stack : ''}`; msgBox.style.cssText = ` background: rgba(0,0,0,0.5); padding: 15px; border: 1px solid #ff4444; max-width: 800px; max-height: 300px; overflow: auto; white-space: pre-wrap; text-align: left; font-size: 12px; margin-bottom: 30px; color: #fff; `; const btnContainer = document.createElement('div'); const btnReload = document.createElement('button'); btnReload.innerText = '🔄 RELOAD GAME'; btnReload.style.cssText = ` padding: 15px 30px; font-size: 18px; font-weight: bold; background: #44aa44; color: white; border: none; cursor: pointer; border-radius: 5px; margin-right: 15px; `; btnReload.onclick = () => window.location.reload(); const btnIgnore = document.createElement('button'); btnIgnore.innerText = 'IGNORE & TRY TO CONTINUE'; btnIgnore.style.cssText = ` padding: 15px 30px; font-size: 14px; background: #666; color: white; border: none; cursor: pointer; border-radius: 5px; `; btnIgnore.onclick = () => { overlay.remove(); console.log('⚠️ User ignored critical error.'); }; btnContainer.appendChild(btnReload); btnContainer.appendChild(btnIgnore); overlay.appendChild(title); overlay.appendChild(msgBox); overlay.appendChild(btnContainer); document.body.appendChild(overlay); } }