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

+12
View File
@@ -226,6 +226,17 @@ def api_minimap():
lock.release() lock.release()
ready = any(cell is not None for row in cells for cell in row) ready = any(cell is not None for row in cells for cell in row)
path_nodes = []
for node in (g.get('path') or ())[:512]:
try:
if all(hasattr(node, key) for key in ('x', 'z')):
path_x, path_z = float(node.x), float(node.z)
else:
path_x, path_z = float(node[0]), float(node[2])
except (IndexError, TypeError, ValueError, AttributeError):
continue
path_nodes.append({'x': path_x, 'z': path_z})
return jsonify( return jsonify(
ready=ready, ready=ready,
center={'x': center_x, 'y': center_y, 'z': center_z}, center={'x': center_x, 'y': center_y, 'z': center_z},
@@ -234,6 +245,7 @@ def api_minimap():
radius_x=radius_x, radius_x=radius_x,
radius_z=radius_z, radius_z=radius_z,
cells=cells if ready else [], cells=cells if ready else [],
path=path_nodes,
) )
+5 -1
View File
@@ -35,7 +35,7 @@ class TestWebInventoryAPI(unittest.TestCase):
self.original = { self.original = {
key: self.g.get(key) for key in key: self.g.get(key) for key in
('connected', 'game', 'inv', 'chest_viewers', 'time', 'time_base', ('connected', 'game', 'inv', 'chest_viewers', 'time', 'time_base',
'chunks', 'pos', 'yaw') 'chunks', 'pos', 'yaw', 'path')
} }
self.game = FakeGame() self.game = FakeGame()
self.g.connected = True self.g.connected = True
@@ -78,6 +78,7 @@ class TestWebInventoryAPI(unittest.TestCase):
self.g.chunks = FakeChunks() self.g.chunks = FakeChunks()
self.g.pos = Munch(x=1.5, y=6.0, z=1.5) self.g.pos = Munch(x=1.5, y=6.0, z=1.5)
self.g.yaw = 90 self.g.yaw = 90
self.g.path = [(-1, 5, 1), Munch(x=1, y=5, z=1)]
response = self.client.get( response = self.client.get(
'/api/minimap?radius=4&radius_x=6&radius_z=4') '/api/minimap?radius=4&radius_x=6&radius_z=4')
@@ -87,6 +88,9 @@ class TestWebInventoryAPI(unittest.TestCase):
self.assertTrue(data['ready']) self.assertTrue(data['ready'])
self.assertEqual(data['center'], {'x': 1, 'y': 6, 'z': 1}) self.assertEqual(data['center'], {'x': 1, 'y': 6, 'z': 1})
self.assertEqual(data['yaw'], 90) self.assertEqual(data['yaw'], 90)
self.assertEqual(data['path'], [
{'x': -1.0, 'z': 1.0}, {'x': 1.0, 'z': 1.0},
])
self.assertEqual(data['radius_x'], 6) self.assertEqual(data['radius_x'], 6)
self.assertEqual(data['radius_z'], 4) self.assertEqual(data['radius_z'], 4)
self.assertEqual(len(data['cells']), 9) self.assertEqual(len(data['cells']), 9)
+2 -2
View File
@@ -6,8 +6,8 @@
<meta name="theme-color" content="#10130f" /> <meta name="theme-color" content="#10130f" />
<meta name="description" content="Live Minecraft bot dashboard" /> <meta name="description" content="Live Minecraft bot dashboard" />
<title>Mosfet · Minecraft Bot</title> <title>Mosfet · Minecraft Bot</title>
<link rel="stylesheet" href="/static/css/dashboard.css?v=19" /> <link rel="stylesheet" href="/static/css/dashboard.css?v=20" />
<script defer src="/static/js/dashboard.js?v=19"></script> <script defer src="/static/js/dashboard.js?v=23"></script>
</head> </head>
<body> <body>
<div class="shell"> <div class="shell">
+2 -2
View File
@@ -6,8 +6,8 @@
<meta name="theme-color" content="#10130f" /> <meta name="theme-color" content="#10130f" />
<meta name="description" content="Live Minecraft bot dashboard" /> <meta name="description" content="Live Minecraft bot dashboard" />
<title>Mosfet · Minecraft Bot</title> <title>Mosfet · Minecraft Bot</title>
<link rel="stylesheet" href="/static/css/dashboard.css?v=19" /> <link rel="stylesheet" href="/static/css/dashboard.css?v=20" />
<script defer src="/static/js/dashboard.js?v=19"></script> <script defer src="/static/js/dashboard.js?v=23"></script>
</head> </head>
<body> <body>
<div class="shell"> <div class="shell">
+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; } .side-panel { padding: 14px; }
.minimap-panel { min-width: 0; } .minimap-panel { min-width: 0; }
.minimap-panel.is-large { grid-column: 1 / -1; width: 100%; } .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-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-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; } .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'; 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) { function drawMinimap(data = lastMinimapData) {
const canvas = $('minimap-canvas'); const canvas = $('minimap-canvas');
if (!canvas) return; if (!canvas) return;
@@ -124,6 +117,27 @@
const columns = radiusX * 2 + 1; const columns = radiusX * 2 + 1;
const cellWidth = width / columns; const cellWidth = width / columns;
const cellHeight = height / rows; 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 yaw = Number(data.yaw || 0);
const mapRotation = minimapNorthLocked ? 0 : (180 - yaw) * Math.PI / 180; const mapRotation = minimapNorthLocked ? 0 : (180 - yaw) * Math.PI / 180;
context.save(); context.save();
@@ -132,23 +146,28 @@
context.clip(); context.clip();
context.translate(centerX, centerY); context.translate(centerX, centerY);
context.rotate(mapRotation); context.rotate(mapRotation);
for (let rowIndex = 0; rowIndex < rows; rowIndex++) { context.imageSmoothingEnabled = false;
const row = data.cells[rowIndex] || []; context.drawImage(raster, -centerX, -centerY, width, height);
for (let columnIndex = 0; columnIndex < columns; columnIndex++) {
const surface = row[columnIndex]; const route = Array.isArray(data.path) ? data.path : [];
const x = -centerX + columnIndex * cellWidth; if (route.length) {
const y = -centerY + rowIndex * cellHeight; context.beginPath();
if (!surface) { route.forEach((point, index) => {
context.fillStyle = '#171b17'; const x = (Number(point.x) - data.center.x + radiusX + 0.5) *
} else { cellWidth - centerX;
const heightDelta = Number(surface.y) - Number(data.center?.y || 0); const y = (Number(point.z) - data.center.z + radiusZ + 0.5) *
const shade = Math.max(0.72, Math.min(1.28, 1 + heightDelta * 0.018)); cellHeight - centerY;
context.fillStyle = shadeMinimapColor( if (index === 0) context.moveTo(x, y);
minimapBlockColor(surface.block), shade); else context.lineTo(x, y);
} });
context.fillRect(x, y, Math.ceil(cellWidth) + 0.2, context.lineCap = 'round';
Math.ceil(cellHeight) + 0.2); context.lineJoin = 'round';
} context.strokeStyle = '#17251d';
context.lineWidth = 4;
context.stroke();
context.strokeStyle = '#b7f27d';
context.lineWidth = 2;
context.stroke();
} }
context.restore(); context.restore();
+2 -2
View File
@@ -6,8 +6,8 @@
<meta name="theme-color" content="#10130f" /> <meta name="theme-color" content="#10130f" />
<meta name="description" content="Live Minecraft bot dashboard" /> <meta name="description" content="Live Minecraft bot dashboard" />
<title>Mosfet · Minecraft Bot</title> <title>Mosfet · Minecraft Bot</title>
<link rel="stylesheet" href="/static/css/dashboard.css?v=19" /> <link rel="stylesheet" href="/static/css/dashboard.css?v=20" />
<script defer src="/static/js/dashboard.js?v=19"></script> <script defer src="/static/js/dashboard.js?v=23"></script>
</head> </head>
<body> <body>
<div class="shell"> <div class="shell">