feat: Add cursor outline and improve debug mode mouse tracking

This commit is contained in:
Kacper Kostka (aider) 2025-04-04 11:13:19 +02:00
parent ef2226b1d2
commit 7fe2e5e474

View File

@ -466,16 +466,29 @@ function render() {
} }
} }
// Draw cursor position in debug mode // Draw cursor position and update debug info
if (debugMode) { if (currentMouseX !== undefined && currentMouseY !== undefined) {
const rect = canvas.getBoundingClientRect(); const worldX = Math.floor(currentMouseX / PIXEL_SIZE) + worldOffsetX;
const mouseX = lastMouseX || 0; const worldY = Math.floor(currentMouseY / PIXEL_SIZE) + worldOffsetY;
const mouseY = lastMouseY || 0;
const worldX = Math.floor(mouseX / PIXEL_SIZE) + worldOffsetX;
const worldY = Math.floor(mouseY / PIXEL_SIZE) + worldOffsetY;
document.getElementById('coords').textContent = // Update coordinates display in debug mode
`Chunk: ${Math.floor(worldOffsetX / CHUNK_SIZE)},${Math.floor(worldOffsetY / CHUNK_SIZE)} | ` + if (debugMode) {
`Mouse: ${worldX},${worldY} | Offset: ${Math.floor(worldOffsetX)},${Math.floor(worldOffsetY)}`; document.getElementById('coords').textContent =
`Chunk: ${Math.floor(worldOffsetX / CHUNK_SIZE)},${Math.floor(worldOffsetY / CHUNK_SIZE)} | ` +
`Mouse: ${worldX},${worldY} | Offset: ${Math.floor(worldOffsetX)},${Math.floor(worldOffsetY)}`;
// Draw cursor outline
const cursorScreenX = (worldX - worldOffsetX) * PIXEL_SIZE;
const cursorScreenY = (worldY - worldOffsetY) * PIXEL_SIZE;
ctx.strokeStyle = '#00ff00';
ctx.lineWidth = 2;
ctx.strokeRect(
cursorScreenX - PIXEL_SIZE,
cursorScreenY - PIXEL_SIZE,
PIXEL_SIZE * 3,
PIXEL_SIZE * 3
);
}
} }
} }