From c0d0f4117763c149eea06430e9c4674d24555f11 Mon Sep 17 00:00:00 2001 From: JustAGenericUsername <92590792+JustAGenericUsername@users.noreply.github.com> Date: Tue, 21 May 2024 06:11:13 -0400 Subject: [PATCH] logic fix --- mods/logicgates.js | 50 +++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/mods/logicgates.js b/mods/logicgates.js index 5b989a41..87b85c5e 100644 --- a/mods/logicgates.js +++ b/mods/logicgates.js @@ -93,7 +93,7 @@ elements.logic_wire = { } } } -function countNeighbors(){ +function countNeighbors(pixel){ var results = { "charged": 0, "uncharged": 0, @@ -115,7 +115,7 @@ function countNeighbors(){ } return results; } -function chargeOutputs(){ +function chargeOutputs(pixel){ for (var i = 0; i < squareCoords.length; i++) { var coord = squareCoords[i]; var x = pixel.x+coord[0]; @@ -128,7 +128,7 @@ function chargeOutputs(){ } } } -function unchargeOutputs(){ +function unchargeOutputs(pixel){ for (var i = 0; i < squareCoords.length; i++) { var coord = squareCoords[i]; var x = pixel.x+coord[0]; @@ -147,11 +147,11 @@ elements.not_gate = { state: "solid", behavior: behaviors.WALL, tick: function(pixel){ - var countNeighborsResult = countNeighbors() + var countNeighborsResult = countNeighbors(pixel) if (countNeighborsResult.charged == 0){ - chargeOutputs(); + chargeOutputs(pixel); } else { - unchargeOutputs(); + unchargeOutputs(pixel); } } } @@ -161,11 +161,11 @@ elements.and_gate = { state: "solid", behavior: behaviors.WALL, tick: function(pixel){ - var countNeighborsResult = countNeighbors() + var countNeighborsResult = countNeighbors(pixel) if (countNeighborsResult.uncharged == 0){ - chargeOutputs(); + chargeOutputs(pixel); } else { - unchargeOutputs(); + unchargeOutputs(pixel); } } } @@ -175,11 +175,11 @@ elements.xor_gate = { state: "solid", behavior: behaviors.WALL, tick: function(pixel){ - var countNeighborsResult = countNeighbors() + var countNeighborsResult = countNeighbors(pixel) if (countNeighborsResult.charged == 1){ - chargeOutputs(); + chargeOutputs(pixel); } else { - unchargeOutputs(); + unchargeOutputs(pixel); } } } @@ -189,11 +189,11 @@ elements.or_gate = { state: "solid", behavior: behaviors.WALL, tick: function(pixel){ - var countNeighborsResult = countNeighbors() + var countNeighborsResult = countNeighbors(pixel) if (countNeighborsResult.charged >= 1){ - chargeOutputs(); + chargeOutputs(pixel); } else { - unchargeOutputs(); + unchargeOutputs(pixel); } } } @@ -203,11 +203,11 @@ elements.nand_gate = { state: "solid", behavior: behaviors.WALL, tick: function(pixel){ - var countNeighborsResult = countNeighbors() + var countNeighborsResult = countNeighbors(pixel) if (countNeighborsResult.uncharged){ - chargeOutputs(); + chargeOutputs(pixel); } else { - unchargeOutputs(); + unchargeOutputs(pixel); } } } @@ -217,11 +217,11 @@ elements.nor_gate = { state: "solid", behavior: behaviors.WALL, tick: function(pixel){ - var countNeighborsResult = countNeighbors() + var countNeighborsResult = countNeighbors(pixel) if (!countNeighborsResult.charged){ - chargeOutputs(); + chargeOutputs(pixel); } else { - unchargeOutputs(); + unchargeOutputs(pixel); } } } @@ -231,11 +231,11 @@ elements.nxor_gate = { state: "solid", behavior: behaviors.WALL, tick: function(pixel){ - var countNeighborsResult = countNeighbors() + var countNeighborsResult = countNeighbors(pixel) if (!(countNeighborsResult.charged == 1)){ - chargeOutputs(); + chargeOutputs(pixel); } else { - unchargeOutputs(); + unchargeOutputs(pixel); } } } @@ -385,7 +385,7 @@ elements.logic_transmitter = { behavior: behaviors.WALL, category: "logic", tick: function(pixel){ - var neighborResult = countNeighbors(); + var neighborResult = countNeighbors(pixel); if (pixel.start === pixelTicks){ pixel.channel = transmitterVar; }