2023-05-07 15:09:47 -04:00
|
|
|
var modName = "mods/wifi.js";
|
|
|
|
|
var libraryMod = "mods/code_library.js";
|
|
|
|
|
|
2026-01-22 18:58:00 -05:00
|
|
|
dependOn("code_library.js", function(){
|
2023-05-07 15:09:47 -04:00
|
|
|
//https://stackoverflow.com/a/60922255
|
|
|
|
|
elements.wifi = {
|
|
|
|
|
color: "#bfff7f",
|
|
|
|
|
properties: {
|
|
|
|
|
_channel: 0,
|
|
|
|
|
_correspondingWifi: null,
|
|
|
|
|
},
|
2023-05-07 16:08:02 -04:00
|
|
|
hardness: 0.8,
|
|
|
|
|
breakInto: ["plastic","steel","copper"],
|
2023-05-07 15:09:47 -04:00
|
|
|
conduct: 1,
|
|
|
|
|
insulate: true,
|
|
|
|
|
tick: function(pixel) {
|
|
|
|
|
pixel._channel = Math.floor(pixel.temp / 100);
|
|
|
|
|
|
|
|
|
|
var colorBase = (pixel._channel + 3);
|
2023-05-07 16:03:29 -04:00
|
|
|
if(colorBase < 0 || colorBase > 124) {
|
2023-05-07 15:09:47 -04:00
|
|
|
pixel.color == "rgb(212,185,222)";
|
|
|
|
|
} else {
|
2023-05-07 16:03:29 -04:00
|
|
|
colorBase = colorBase.toString(5).padStart(3,"0").split("").map(x => parseInt(x) * 64);
|
2023-05-07 15:09:47 -04:00
|
|
|
pixel.color = `rgb(${colorBase.join(",")})`
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pixel._correspondingWifi = currentPixels.filter(function(pixelToCheck) {
|
|
|
|
|
return (
|
|
|
|
|
pixelToCheck !== pixel && //should work if this pixel is the same as the other one by reference
|
|
|
|
|
["wifi","receiver"].includes(pixelToCheck.element) &&
|
|
|
|
|
pixelToCheck._channel == pixelChannel
|
|
|
|
|
);
|
|
|
|
|
},pixelChannel=pixel._channel).map(pixel => [pixel.x,pixel.y]);
|
|
|
|
|
|
|
|
|
|
if(pixel.charge) {
|
|
|
|
|
for(var i in pixel._correspondingWifi) {
|
|
|
|
|
i = parseInt(i);
|
|
|
|
|
var wifiCoords = pixel._correspondingWifi[i];
|
|
|
|
|
var newPixel = pixelMap[wifiCoords[0]]?.[wifiCoords[1]];
|
|
|
|
|
if(newPixel) {
|
|
|
|
|
if(!newPixel.chargeCD) {
|
|
|
|
|
for(var j in adjacentCoords) {
|
|
|
|
|
j = parseInt(j);
|
|
|
|
|
var pixelAdjacentToWifi = pixelMap[newPixel.x+adjacentCoords[j][0]]?.[newPixel.y+adjacentCoords[j][1]];
|
|
|
|
|
if(pixelAdjacentToWifi) { pixelAdjacentToWifi.charge = 1 };
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
if(pixel._correspondingWifi.length > 0) {
|
|
|
|
|
delete pixel.charge;
|
|
|
|
|
pixel.chargeCD = 5
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(typeof(pixel.chargeCD) !== "undefined") {
|
|
|
|
|
pixel.chargeCD--;
|
|
|
|
|
if(pixel.chargeCD <= 0) { delete pixel.chargeCD };
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
category: "machines",
|
|
|
|
|
state: "solid",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
elements.transmitter = {
|
|
|
|
|
color: "#00ff7f",
|
|
|
|
|
properties: {
|
|
|
|
|
_channel: 0,
|
|
|
|
|
_correspondingWifi: null,
|
|
|
|
|
},
|
2023-05-07 16:08:02 -04:00
|
|
|
hardness: 0.8,
|
|
|
|
|
breakInto: ["plastic","steel","copper"],
|
2023-05-07 15:09:47 -04:00
|
|
|
conduct: 1,
|
|
|
|
|
insulate: true,
|
|
|
|
|
tick: function(pixel) {
|
|
|
|
|
pixel._channel = Math.floor(pixel.temp / 100);
|
|
|
|
|
|
|
|
|
|
var colorBase = (pixel._channel + 3);
|
2023-05-07 16:03:29 -04:00
|
|
|
if(colorBase < 0 || colorBase > 124) {
|
2023-05-07 15:09:47 -04:00
|
|
|
pixel.color == "rgb(212,185,222)";
|
|
|
|
|
} else {
|
2023-05-07 16:03:29 -04:00
|
|
|
colorBase = colorBase.toString(5).padStart(3,"0").split("").map(x => parseInt(x) * 64);
|
2023-05-07 15:09:47 -04:00
|
|
|
pixel.color = `rgb(${colorBase.join(",")})`
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pixel._correspondingWifi = currentPixels.filter(function(pixelToCheck) {
|
|
|
|
|
return (
|
|
|
|
|
pixelToCheck !== pixel && //should work if this pixel is the same as the other one by reference
|
|
|
|
|
["wifi","receiver"].includes(pixelToCheck.element) &&
|
|
|
|
|
pixelToCheck._channel == pixelChannel
|
|
|
|
|
);
|
|
|
|
|
},pixelChannel=pixel._channel).map(pixel => [pixel.x,pixel.y]);
|
|
|
|
|
|
|
|
|
|
if(pixel.charge) {
|
|
|
|
|
for(var i in pixel._correspondingWifi) {
|
|
|
|
|
i = parseInt(i);
|
|
|
|
|
var wifiCoords = pixel._correspondingWifi[i];
|
|
|
|
|
var newPixel = pixelMap[wifiCoords[0]]?.[wifiCoords[1]];
|
|
|
|
|
if(newPixel) {
|
|
|
|
|
if(!newPixel.chargeCD) {
|
|
|
|
|
for(var j in adjacentCoords) {
|
|
|
|
|
j = parseInt(j);
|
|
|
|
|
var pixelAdjacentToWifi = pixelMap[newPixel.x+adjacentCoords[j][0]]?.[newPixel.y+adjacentCoords[j][1]];
|
|
|
|
|
if(pixelAdjacentToWifi && elements[pixelAdjacentToWifi.element].conduct) { pixelAdjacentToWifi.charge = 1 };
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
if(pixel._correspondingWifi.length > 0) {
|
|
|
|
|
delete pixel.charge;
|
|
|
|
|
pixel.chargeCD = 5
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(typeof(pixel.chargeCD) !== "undefined") {
|
|
|
|
|
pixel.chargeCD--;
|
|
|
|
|
if(pixel.chargeCD <= 0) { delete pixel.chargeCD };
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
category: "machines",
|
|
|
|
|
state: "solid",
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
elements.receiver = {
|
|
|
|
|
color: "#bfff00",
|
|
|
|
|
properties: {
|
|
|
|
|
_channel: 0,
|
|
|
|
|
},
|
2023-05-07 16:08:02 -04:00
|
|
|
hardness: 0.8,
|
|
|
|
|
breakInto: ["plastic","steel","copper"],
|
2023-05-07 15:09:47 -04:00
|
|
|
conduct: 1,
|
|
|
|
|
insulate: true,
|
|
|
|
|
tick: function(pixel) {
|
|
|
|
|
pixel._channel = Math.floor(pixel.temp / 100);
|
|
|
|
|
|
|
|
|
|
var colorBase = (pixel._channel + 3);
|
2023-05-07 16:03:29 -04:00
|
|
|
if(colorBase < 0 || colorBase > 124) {
|
|
|
|
|
pixel.color = "rgb(212,185,222)";
|
2023-05-07 15:09:47 -04:00
|
|
|
} else {
|
2023-05-07 16:03:29 -04:00
|
|
|
colorBase = colorBase.toString(5).padStart(3,"0").split("").map(x => parseInt(x) * 64);
|
2023-05-07 15:09:47 -04:00
|
|
|
pixel.color = `rgb(${colorBase.join(",")})`
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(typeof(pixel.chargeCD) !== "undefined") {
|
|
|
|
|
pixel.chargeCD = Math.min(pixel.chargeCD,5);
|
|
|
|
|
pixel.chargeCD--;
|
|
|
|
|
if(pixel.chargeCD <= 0) { delete pixel.chargeCD };
|
|
|
|
|
};
|
|
|
|
|
if(pixel.charge) {
|
|
|
|
|
pixel.charge -= 0.25;
|
|
|
|
|
if(pixel.charge <= 0) { delete pixel.charge };
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
category: "machines",
|
|
|
|
|
state: "solid",
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-22 18:58:00 -05:00
|
|
|
}, true);
|