Improve surface minimap rendering and add path overlay

This commit is contained in:
Tanner committed 2026-11-09 03:29:23 +00:00
1 parent 7e43001d9d
commit 67381655a2
7 files changed
+67 -32

No files matched your search

+1 -1
View File
@@ -138,7 +138,7 @@ h2 { margin: 3px 0 0; font-size: 20px; letter-spacing: -.01em; font-weight: 600;
.side-panel { padding: 14px; }
.minimap-panel { min-width: 0; }
.minimap-panel.is-large { grid-column: 1 / -1; width: 100%; }
.minimap-canvas { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; margin: 2px auto 0; border: 1px solid #4b5549; border-radius: 2px; background: #111411; image-rendering: pixelated; }
.minimap-canvas { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; margin: 2px auto 0; border: 1px solid #4b5549; border-radius: 2px; background: #111411; }
.minimap-panel.is-large .minimap-canvas { aspect-ratio: 2 / 1; }
.minimap-caption { min-height: 14px; margin-top: 6px; color: var(--muted); text-align: center; font: 10px var(--mono); }
.minimap-controls { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin-top: 8px; }
+43 -24
View File
@@ -93,13 +93,6 @@
return '#7a806f';
}
function shadeMinimapColor(color, amount) {
const value = Number.parseInt(color.slice(1), 16);
const channels = [value >> 16, (value >> 8) & 0xff, value & 0xff]
.map((channel) => Math.max(0, Math.min(255, Math.round(channel * amount))));
return `rgb(${channels[0]} ${channels[1]} ${channels[2]})`;
}
function drawMinimap(data = lastMinimapData) {
const canvas = $('minimap-canvas');
if (!canvas) return;
@@ -124,6 +117,27 @@
const columns = radiusX * 2 + 1;
const cellWidth = width / columns;
const cellHeight = height / rows;
// Rasterize one color per sample before scaling to avoid subpixel cell seams.
const raster = document.createElement('canvas');
raster.width = columns;
raster.height = rows;
const rasterContext = raster.getContext('2d');
const rasterPixels = rasterContext.createImageData(columns, rows);
for (let rowIndex = 0; rowIndex < rows; rowIndex++) {
const row = data.cells[rowIndex] || [];
for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
const surface = row[columnIndex];
const color = surface ? minimapBlockColor(surface.block) : '#171b17';
const value = Number.parseInt(color.slice(1), 16);
const pixel = (rowIndex * columns + columnIndex) * 4;
rasterPixels.data[pixel] = value >> 16;
rasterPixels.data[pixel + 1] = (value >> 8) & 0xff;
rasterPixels.data[pixel + 2] = value & 0xff;
rasterPixels.data[pixel + 3] = 255;
}
}
rasterContext.putImageData(rasterPixels, 0, 0);
const yaw = Number(data.yaw || 0);
const mapRotation = minimapNorthLocked ? 0 : (180 - yaw) * Math.PI / 180;
context.save();
@@ -132,23 +146,28 @@
context.clip();
context.translate(centerX, centerY);
context.rotate(mapRotation);
for (let rowIndex = 0; rowIndex < rows; rowIndex++) {
const row = data.cells[rowIndex] || [];
for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
const surface = row[columnIndex];
const x = -centerX + columnIndex * cellWidth;
const y = -centerY + rowIndex * cellHeight;
if (!surface) {
context.fillStyle = '#171b17';
} else {
const heightDelta = Number(surface.y) - Number(data.center?.y || 0);
const shade = Math.max(0.72, Math.min(1.28, 1 + heightDelta * 0.018));
context.fillStyle = shadeMinimapColor(
minimapBlockColor(surface.block), shade);
}
context.fillRect(x, y, Math.ceil(cellWidth) + 0.2,
Math.ceil(cellHeight) + 0.2);
}
context.imageSmoothingEnabled = false;
context.drawImage(raster, -centerX, -centerY, width, height);
const route = Array.isArray(data.path) ? data.path : [];
if (route.length) {
context.beginPath();
route.forEach((point, index) => {
const x = (Number(point.x) - data.center.x + radiusX + 0.5) *
cellWidth - centerX;
const y = (Number(point.z) - data.center.z + radiusZ + 0.5) *
cellHeight - centerY;
if (index === 0) context.moveTo(x, y);
else context.lineTo(x, y);
});
context.lineCap = 'round';
context.lineJoin = 'round';
context.strokeStyle = '#17251d';
context.lineWidth = 4;
context.stroke();
context.strokeStyle = '#b7f27d';
context.lineWidth = 2;
context.stroke();
}
context.restore();
+2 -2
View File
@@ -6,8 +6,8 @@
<meta name="theme-color" content="#10130f" />
<meta name="description" content="Live Minecraft bot dashboard" />
<title>Mosfet · Minecraft Bot</title>
<link rel="stylesheet" href="/static/css/dashboard.css?v=19" />
<script defer src="/static/js/dashboard.js?v=19"></script>
<link rel="stylesheet" href="/static/css/dashboard.css?v=20" />
<script defer src="/static/js/dashboard.js?v=23"></script>
</head>
<body>
<div class="shell">