From 51ef4a52cd21a7ce188163579c9e31406f50ba11 Mon Sep 17 00:00:00 2001 From: HF Date: Fri, 23 Feb 2024 22:21:20 +0100 Subject: [PATCH] fix historical pixel selection --- src/ui/Chunk2D.js | 7 ++++--- src/ui/ChunkLoader2D.js | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ui/Chunk2D.js b/src/ui/Chunk2D.js index 0c545b57..232185cd 100644 --- a/src/ui/Chunk2D.js +++ b/src/ui/Chunk2D.js @@ -86,10 +86,11 @@ class Chunk2D extends Chunk { getColorIndex(cell, nearest = true) { const [x, y] = cell; const ctx = this.image.getContext('2d'); - const rgb = ctx.getImageData(x, y, 1, 1).data; + const rgba = ctx.getImageData(x, y, 1, 1).data; + if (!nearest && rgba[3] === 0) return null; const ind = (nearest) - ? this.palette.getClosestIndexOfColor(rgb[0], rgb[1], rgb[2]) - : this.palette.getIndexOfColor(rgb[0], rgb[1], rgb[2]); + ? this.palette.getClosestIndexOfColor(rgba[0], rgba[1], rgba[2]) + : this.palette.getIndexOfColor(rgba[0], rgba[1], rgba[2]); return ind; } diff --git a/src/ui/ChunkLoader2D.js b/src/ui/ChunkLoader2D.js index d36611fb..375e5928 100644 --- a/src/ui/ChunkLoader2D.js +++ b/src/ui/ChunkLoader2D.js @@ -89,7 +89,7 @@ class ChunkLoader2D extends ChunkLoader { const px = getCellInsideChunk(historicalCanvasSize, [x, y]); const curTime = Date.now(); - if (historicalTime && historicalTime !== '0000') { + if (historicalTime && historicalTime && historicalTime !== '0000') { // eslint-disable-next-line max-len const incrementalChunkKey = `${historicalDate}${historicalTime}:${cx}:${cy}`; const incrementalChunk = this.cget(incrementalChunkKey);