From 3098dcba7dc7184ce72408e8e38865feac4c11d1 Mon Sep 17 00:00:00 2001 From: JustAGenericUsername Date: Wed, 24 Jan 2024 14:22:47 -0500 Subject: [PATCH] the logical wifi --- mods/logicgates.js | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/mods/logicgates.js b/mods/logicgates.js index 0eca9be3..1f2f83d9 100644 --- a/mods/logicgates.js +++ b/mods/logicgates.js @@ -330,4 +330,63 @@ elements.L2E_constant = { } } } +} +var transmitterVar = 0; +elements.logic_transmitter = { + onSelect: function() { + var answertransmitter = prompt("Please input the desired element of this filter. It will not work if you do multiple filter types while paused.",(transmitterVar||undefined)); + if (!answertransmitter) { return } + transmitterVar = answertransmitter; + }, + color: "#c26994", + state: "solid", + behavior: behaviors.WALL, + category: "logic", + tick: function(pixel){ + var neighborResult = countNeighbors(); + if (pixel.start === pixelTicks){ + pixel.channel = transmitterVar; + } + var receivers = currentPixels.filter(function(pixelToCheck) { + return ( + pixelToCheck !== pixel && //should work if this pixel is the same as the other one by reference + pixelToCheck.element == "logic_receiver" && + pixelToCheck.channel == pixel.channel + ); + }).map(pixel => [pixel.x,pixel.y]); + for(var i in receivers) { + i = parseInt(i); + var wifiCoords = receivers[i]; + var newPixel = pixelMap[wifiCoords[0]]?.[wifiCoords[1]]; + if(newPixel) { + if (neighborResult.charged){ + for(var j in adjacentCoords) { + j = parseInt(j); + var pixelAdjacentToWifi = pixelMap[newPixel.x+adjacentCoords[j][0]]?.[newPixel.y+adjacentCoords[j][1]]; + if(pixelAdjacentToWifi && pixelAdjacentToWifi.element == "logic_wire") { pixelAdjacentToWifi.lstate = 2 }; + }; + } else { + for(var j in adjacentCoords) { + j = parseInt(j); + var pixelAdjacentToWifi = pixelMap[newPixel.x+adjacentCoords[j][0]]?.[newPixel.y+adjacentCoords[j][1]]; + if(pixelAdjacentToWifi && pixelAdjacentToWifi.element == "logic_wire") { pixelAdjacentToWifi.lstate = -2 }; + }; + } + } + }; + } +} +elements.logic_receiver = { + onSelect: function() { + var answertransmitter = prompt("Please input the desired element of this filter. It will not work if you do multiple filter types while paused.",(transmitterVar||undefined)); + if (!answertransmitter) { return } + transmitterVar = answertransmitter; + }, + color: "#69c2ba", + behavior: behaviors.WALL, + state: "solid", + category: "logic", + tick: function(pixel){ + if (pixel.start === pixelTicks){pixel.channel = transmitterVar} + } } \ No newline at end of file