fix historical pixel selection

This commit is contained in:
HF 2024-02-23 22:21:20 +01:00
parent edfc921d48
commit 51ef4a52cd
2 changed files with 5 additions and 4 deletions

View File

@ -86,10 +86,11 @@ class Chunk2D extends Chunk {
getColorIndex(cell, nearest = true) { getColorIndex(cell, nearest = true) {
const [x, y] = cell; const [x, y] = cell;
const ctx = this.image.getContext('2d'); 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) const ind = (nearest)
? this.palette.getClosestIndexOfColor(rgb[0], rgb[1], rgb[2]) ? this.palette.getClosestIndexOfColor(rgba[0], rgba[1], rgba[2])
: this.palette.getIndexOfColor(rgb[0], rgb[1], rgb[2]); : this.palette.getIndexOfColor(rgba[0], rgba[1], rgba[2]);
return ind; return ind;
} }

View File

@ -89,7 +89,7 @@ class ChunkLoader2D extends ChunkLoader {
const px = getCellInsideChunk(historicalCanvasSize, [x, y]); const px = getCellInsideChunk(historicalCanvasSize, [x, y]);
const curTime = Date.now(); const curTime = Date.now();
if (historicalTime && historicalTime !== '0000') { if (historicalTime && historicalTime && historicalTime !== '0000') {
// eslint-disable-next-line max-len // eslint-disable-next-line max-len
const incrementalChunkKey = `${historicalDate}${historicalTime}:${cx}:${cy}`; const incrementalChunkKey = `${historicalDate}${historicalTime}:${cx}:${cy}`;
const incrementalChunk = this.cget(incrementalChunkKey); const incrementalChunk = this.cget(incrementalChunkKey);