feat: Add cursor outline and improve debug mode mouse tracking
This commit is contained in:
parent
ef2226b1d2
commit
7fe2e5e474
33
script.js
33
script.js
@ -466,16 +466,29 @@ function render() {
|
||||
}
|
||||
}
|
||||
|
||||
// Draw cursor position in debug mode
|
||||
if (debugMode) {
|
||||
const rect = canvas.getBoundingClientRect();
|
||||
const mouseX = lastMouseX || 0;
|
||||
const mouseY = lastMouseY || 0;
|
||||
const worldX = Math.floor(mouseX / PIXEL_SIZE) + worldOffsetX;
|
||||
const worldY = Math.floor(mouseY / PIXEL_SIZE) + worldOffsetY;
|
||||
// Draw cursor position and update debug info
|
||||
if (currentMouseX !== undefined && currentMouseY !== undefined) {
|
||||
const worldX = Math.floor(currentMouseX / PIXEL_SIZE) + worldOffsetX;
|
||||
const worldY = Math.floor(currentMouseY / PIXEL_SIZE) + 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)}`;
|
||||
// Update coordinates display in debug mode
|
||||
if (debugMode) {
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user