popravek zombijo
This commit is contained in:
107
src/utils/ErrorHandler.js
Normal file
107
src/utils/ErrorHandler.js
Normal file
@@ -0,0 +1,107 @@
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
@@ -571,6 +571,49 @@ class TextureGenerator {
|
||||
ctx.lineTo(32, 40);
|
||||
ctx.fill();
|
||||
|
||||
} else if (type === 'market') {
|
||||
// Market Stall
|
||||
// Wooden base
|
||||
ctx.fillStyle = '#8B4513';
|
||||
ctx.fillRect(4, 30, 56, 34); // Big base
|
||||
|
||||
// Counter
|
||||
ctx.fillStyle = '#DEB887'; // Burlywood
|
||||
ctx.fillRect(0, 40, 64, 10);
|
||||
|
||||
// Posts
|
||||
ctx.fillStyle = '#5C4033';
|
||||
ctx.fillRect(4, 10, 4, 30);
|
||||
ctx.fillRect(56, 10, 4, 30);
|
||||
|
||||
// Striped Roof
|
||||
ctx.fillStyle = '#FF0000'; // Red
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(32, 0);
|
||||
ctx.lineTo(64, 15);
|
||||
ctx.lineTo(0, 15);
|
||||
ctx.fill();
|
||||
|
||||
// White stripes
|
||||
ctx.fillStyle = '#FFFFFF';
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(32, 0);
|
||||
ctx.lineTo(40, 15);
|
||||
ctx.lineTo(32, 15);
|
||||
ctx.fill();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(32, 0);
|
||||
ctx.lineTo(24, 15);
|
||||
ctx.lineTo(16, 15);
|
||||
ctx.fill();
|
||||
|
||||
// Goods (Apples/Items)
|
||||
ctx.fillStyle = '#00FF00';
|
||||
ctx.beginPath(); ctx.arc(10, 38, 4, 0, Math.PI * 2); ctx.fill();
|
||||
ctx.fillStyle = '#FF0000';
|
||||
ctx.beginPath(); ctx.arc(20, 38, 4, 0, Math.PI * 2); ctx.fill();
|
||||
|
||||
} else if (type === 'ruin') {
|
||||
// Isometric Ruin
|
||||
|
||||
@@ -922,5 +965,29 @@ class TextureGenerator {
|
||||
|
||||
canvas.refresh();
|
||||
}
|
||||
|
||||
// 7. BONE
|
||||
if (!scene.textures.exists('item_bone')) {
|
||||
const size = 32;
|
||||
const canvas = scene.textures.createCanvas('item_bone', size, size);
|
||||
const ctx = canvas.getContext();
|
||||
ctx.clearRect(0, 0, size, size);
|
||||
|
||||
// Bone shape
|
||||
ctx.strokeStyle = '#E8E8E8'; // Off-white
|
||||
ctx.lineWidth = 6;
|
||||
ctx.lineCap = 'round';
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(10, 10);
|
||||
ctx.lineTo(22, 22);
|
||||
ctx.stroke();
|
||||
|
||||
// Knobs
|
||||
ctx.fillStyle = '#E8E8E8';
|
||||
ctx.beginPath(); ctx.arc(10, 10, 4, 0, Math.PI * 2); ctx.fill();
|
||||
ctx.beginPath(); ctx.arc(22, 22, 4, 0, Math.PI * 2); ctx.fill();
|
||||
|
||||
canvas.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user