-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug.js
More file actions
87 lines (74 loc) · 2.3 KB
/
debug.js
File metadata and controls
87 lines (74 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/**
* Debug utilities for AI Alchemist's Lair
* Provides performance monitoring and debug visualization features
*/
// Debug configuration
const DEBUG_CONFIG = {
SHOW_FPS: false, // FPS counter disabled for deployment
FPS_TEXT_COLOR: '#00ffcc', // Neon cyan to match the medieval-cyberpunk theme
FPS_BACKGROUND: 'rgba(0, 0, 0, 0.5)',
FPS_FONT: '14px monospace',
FPS_PADDING: 5,
logSceneRendering: false, // Toggle scene rendering logs for debugging
};
// Set global debug mode flag (controls scene ID and render counter visibility)
window.DEBUG_MODE = false;
/**
* Toggles global debug mode
*/
function toggleDebugMode() {
window.DEBUG_MODE = !window.DEBUG_MODE;
console.log(`Debug Mode: ${window.DEBUG_MODE ? 'Enabled' : 'Disabled'}`);
}
/**
* Draws FPS counter on the canvas
* @param {CanvasRenderingContext2D} ctx - Canvas rendering context
* @param {number} fps - Current frames per second
*/
function drawFpsCounter(ctx, fps) {
if (!DEBUG_CONFIG.SHOW_FPS) return;
// Save current context state
ctx.save();
// Configure text style
ctx.font = DEBUG_CONFIG.FPS_FONT;
ctx.fillStyle = DEBUG_CONFIG.FPS_BACKGROUND;
// Measure text for background
const text = `FPS: ${fps}`;
const metrics = ctx.measureText(text);
const textHeight = parseInt(DEBUG_CONFIG.FPS_FONT) + 2;
// Draw background
ctx.fillRect(
DEBUG_CONFIG.FPS_PADDING,
DEBUG_CONFIG.FPS_PADDING,
metrics.width + DEBUG_CONFIG.FPS_PADDING * 2,
textHeight + DEBUG_CONFIG.FPS_PADDING
);
// Draw text
ctx.fillStyle = DEBUG_CONFIG.FPS_TEXT_COLOR;
ctx.fillText(
text,
DEBUG_CONFIG.FPS_PADDING * 2,
DEBUG_CONFIG.FPS_PADDING + textHeight - 2
);
// Restore context
ctx.restore();
}
/**
* Toggle FPS counter visibility
*/
function toggleFpsDisplay() {
DEBUG_CONFIG.SHOW_FPS = !DEBUG_CONFIG.SHOW_FPS;
console.log(`FPS Counter: ${DEBUG_CONFIG.SHOW_FPS ? 'Visible' : 'Hidden'}`);
}
// F key toggle for FPS counter disabled for deployment
// document.addEventListener('keydown', (event) => {
// if (event.key === 'f' || event.key === 'F') {
// toggleFpsDisplay();
// }
// });
export {
drawFpsCounter,
toggleFpsDisplay,
toggleDebugMode,
DEBUG_CONFIG
};