From 0066cea82345a5bc3a990df858239104e8ca9d44 Mon Sep 17 00:00:00 2001 From: O-01-67 <68935009+O-01-67@users.noreply.github.com> Date: Sat, 21 May 2022 20:43:14 -0400 Subject: [PATCH] tool to replace all (read desc) use like replacer bacteria * target below, replacement above * then shock and it will replace all target pixels with replacement pixels --- mods/replace_all.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 mods/replace_all.js diff --git a/mods/replace_all.js b/mods/replace_all.js new file mode 100644 index 00000000..e04bda90 --- /dev/null +++ b/mods/replace_all.js @@ -0,0 +1,45 @@ +elements.replace_all = { + color: "#ef7f3f", + behavior: behaviors.WALL, + tick: function(pixel) { + if(pixel.charge) { //when shocked + //console.log("ouch") + if(!outOfBounds(pixel.x,pixel.y+1) && !isEmpty(pixel.x,pixel.y+1) && !outOfBounds(pixel.x,pixel.y-1) && !isEmpty(pixel.x,pixel.y-1)) { //check if pixels exists above and below to store the elements of + //console.log("elems stored") + if(pixelMap[pixel.x][pixel.y-1].element != pixel.element) { //exclude self and only fire once + //console.log("self excluded from replacement") + pixel.target = pixelMap[pixel.x][pixel.y+1].element + //console.log("target set to " + pixel.target) + pixel.replacement = pixelMap[pixel.x][pixel.y-1].element + //console.log("replacement set to " + pixel.replacement) + pixel.active = true + //console.log("replacer activated") + } + } + } + if(pixel.active) { + //console.log("is this on now?") + if(pixel.target && pixel.replacement) { //safety + //console.log("target and replacement exist, iterating...") + for (var i = 0; i < width; i++) { + for (var j = 0; j < height; j++) { + if(isEmpty(i,j,true) == false) { + //console.log("pixel at (" + i + "," + j + ") exists") + if(pixelMap[i][j].element == pixel.target) { + //console.log(pixel.target + " detected, replacing") + if(isEmpty(i,j,true) == false) { changePixel(pixelMap[i][j],pixel.replacement) } + } + } + } + } + } + pixel.active = false //de-activate + if(pixel.charge) { delete pixel.charge} + if(pixel.chargeCD) { delete pixel.chargeCD} + } + }, + category: "special", + state: "solid", + density: 1, + conduct: elements.water.conduct + 0.1, +} \ No newline at end of file