Skip to content

Commit 0066cea

Browse files
authored
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
1 parent ba173f7 commit 0066cea

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

mods/replace_all.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
elements.replace_all = {
2+
color: "#ef7f3f",
3+
behavior: behaviors.WALL,
4+
tick: function(pixel) {
5+
if(pixel.charge) { //when shocked
6+
//console.log("ouch")
7+
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
8+
//console.log("elems stored")
9+
if(pixelMap[pixel.x][pixel.y-1].element != pixel.element) { //exclude self and only fire once
10+
//console.log("self excluded from replacement")
11+
pixel.target = pixelMap[pixel.x][pixel.y+1].element
12+
//console.log("target set to " + pixel.target)
13+
pixel.replacement = pixelMap[pixel.x][pixel.y-1].element
14+
//console.log("replacement set to " + pixel.replacement)
15+
pixel.active = true
16+
//console.log("replacer activated")
17+
}
18+
}
19+
}
20+
if(pixel.active) {
21+
//console.log("is this on now?")
22+
if(pixel.target && pixel.replacement) { //safety
23+
//console.log("target and replacement exist, iterating...")
24+
for (var i = 0; i < width; i++) {
25+
for (var j = 0; j < height; j++) {
26+
if(isEmpty(i,j,true) == false) {
27+
//console.log("pixel at (" + i + "," + j + ") exists")
28+
if(pixelMap[i][j].element == pixel.target) {
29+
//console.log(pixel.target + " detected, replacing")
30+
if(isEmpty(i,j,true) == false) { changePixel(pixelMap[i][j],pixel.replacement) }
31+
}
32+
}
33+
}
34+
}
35+
}
36+
pixel.active = false //de-activate
37+
if(pixel.charge) { delete pixel.charge}
38+
if(pixel.chargeCD) { delete pixel.chargeCD}
39+
}
40+
},
41+
category: "special",
42+
state: "solid",
43+
density: 1,
44+
conduct: elements.water.conduct + 0.1,
45+
}

0 commit comments

Comments
 (0)