From 7fe2e5e474f110f93b620df9c0ba176f838aff33 Mon Sep 17 00:00:00 2001 From: "Kacper Kostka (aider)" Date: Fri, 4 Apr 2025 11:13:19 +0200 Subject: [PATCH] feat: Add cursor outline and improve debug mode mouse tracking --- script.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/script.js b/script.js index 8331adc..0b4a091 100644 --- a/script.js +++ b/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 + ); + } } }