From bca9b267e3d60b2509163c1492e71143eb09f69a Mon Sep 17 00:00:00 2001 From: GGod <46885632+GGodPL@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:37:53 +0100 Subject: [PATCH] add smooth mode to moreViews.js --- mods/moreViews.js | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/mods/moreViews.js b/mods/moreViews.js index 33ab23d0..dbd8d9ab 100644 --- a/mods/moreViews.js +++ b/mods/moreViews.js @@ -207,8 +207,8 @@ runAfterLoadList.push(() => drawPixels = (function() { const oldDrawPixels = drawPixels; return function(forceTick = false) { - if (view >= 5) { - if (maxDistance = -1) maxDistance = Math.sqrt((width / 2) ** 2 + (height / 2) ** 2) * 2; + if (view >= 4) { + if (maxDistance == -1) maxDistance = Math.sqrt((width / 2) ** 2 + (height / 2) ** 2) * 2; const canvas = document.getElementById("game"); const ctx = canvas.getContext("2d"); @@ -276,8 +276,30 @@ runAfterLoadList.push(() => drawPixels = (function() { if (pixelMap[pixel.x][pixel.y] == undefined) {continue} if (pixel.con) { pixel = pixel.con }; ctx.fillStyle = getModeColor(pixel.color, view == 18 ? Math.sqrt((width / 2 - pixel.x) ** 2 + (height / 2 - pixel.y) ** 2) : 0); + if (view == 4) { + let colorList = []; + for (var j = 0; j < biCoords.length; j++) { + const x = pixel.x + biCoords[j][0]; + const y = pixel.y + biCoords[j][1]; + if (isEmpty(x,y,true) || elements[pixelMap[x][y].element].state !== elements[pixel.element].state) {continue} + const color = pixelMap[x][y].color; + const [r, g, b] = color.replace(/[rgb()]/g, "").split(",").map(a => parseInt(a.trim())); + const [r1, g1, b1] = pixel.color.replace(/[rgb()]/g, "").split(",").map(a => parseInt(a.trim())); + if (Math.abs(r - r1) + Math.abs(g - g1) + Math.abs(b - b1) > 75 && pixelMap[x][y].element != pixel.element) continue; + if (color.indexOf("rgb") !== -1) { + colorList.push(color.match(/\d+/g)); + } + } + if (colorList.length === 0) { + ctx.fillStyle = pixel.color; + } + else { + ctx.fillStyle = averageRGB(colorList); + } + ctx.fillRect(pixel.x * pixelSize, pixel.y * pixelSize, pixelSize, pixelSize); + } // 3D VIEW - if (view == 5) { + else if (view == 5) { const neighborRight = !outOfBounds(pixel.x + 1, pixel.y) && !!pixelMap[pixel.x + 1][pixel.y]; const neighborUp = !outOfBounds(pixel.x, pixel.y - 1) && !!pixelMap[pixel.x][pixel.y - 1]; const neighborUpRight = !outOfBounds(pixel.x + 1, pixel.y - 1) && !!pixelMap[pixel.x + 1][pixel.y - 1];